Interfacing Peripherals On The Arduino
Interfacing Peripherals On The Arduino
temperature.
across a p-n junction increases at a known rate. (in this case Vbe)
Datasheet of LM35
folder.
2.
3. 4. 5.
assign it to a global variable in setup() { }, initialize serial port to 9600 baud rate to send temp reading out to PC. In loop() { }, take the analogue reading from a pin and store it in a temp float variable. Multiply reading by 5.0 and then divide by 1024 to get voltage value read by the port. Store this is a float variable called volt. Print out this value to the serial port and check.
LM35 in Celsius.
0 Send it to the serial port and check your code. 0 To convert to fahrenheight, mult by 9 then divide by 5
Improvements?
0 Use 3.3V as reference to increase resolution since
0 Put in on PCB to avoid noise by breadboard internal 0 DO NOT LIGHT THE LM35 OR IMMERSE IT IN WATER. 0 Make a waterproof casing for the lm35 to test temp of
liquids.
LDR
0 An LDR is a Light Dependent Resistor. 0 As in the resistance offered by this device to an
anyway.
0 Circuit is GND-10kohn-LDR-VCC. 0 This circuit will only work if between 0-5V. If light is
too bright, it will saturate at 5V. 0 putting a variable resistor in place of 10k allows for controlling saturation with too bright/too dark light.
Ambient light like Dim hallway Moonlit night Room Dark overcast day / Bright room Overcast day
LDR + R () 610 K 80 K 20 K
100 lux
1.5 K
11.5 K
0.43 mA
4.3 V
1000 lux
300
10.03 K
0.5 mA
5V
Writing code!
0 decide analoge pin used as input to LDR.
Application 1
0 Make thresholds and determine the brightness
if (reading < 10) { Serial.println(" - Dark"); } else if (reading < 200) { Serial.println(" - Dim"); } else if (reading < 500) { Serial.println(" - Light"); } else if (reading < 800) { Serial.println(" - Bright"); } else { Serial.println(" - Very bright"); }
Application 2
0 Take the analogue reading and use it as the delay
void loop() { val = analogRead(LDR); digitalWrite(ledPin, HIGH); delay(val); digitalWrite(ledPin, LOW); delay(val); }
Another Application
0 Put three LEDs around the LDR. Red, Green and Blue.
Sensor Data on PC
0 Reading and plotting sensor data on PC is very simple
on the arduino.
serial port.
run.
matches arduino
The motor shield goes on top of the arduino neatly. There are loads of shields for the arduino that provide different functionality.
Be careful removing the shield, if you bend the pins, you cant put the shield in again.
IR TX RX Pair
0 An IR transmitter (TX) is a LED that emits
light in the infrared spectrum. 0 (most cameras see IR, light up the IR LED and point a camera at it to check)
base exposed. 0 The base voltage depends on the amount of IR received and it controls the amount of current passing through the C-E junction (leads).
IR schematic
0 The IR TX LED is connected through a current
limiting resisto 0 The IR RX is connected via a variable potentiometer to a voltage comparator to give a digital output.
0 The pot is used to adjust
Remember
0 The IR TX RX pairs should be spaced 1/4th of an inch apart
0 0 0
one way There are status LEDs just next to each IR socket, if the comparator goes HIGH, the LED lights. This is for calibration. Keep the IR sensor pointed at nothing (no obstruction). Use a screwdriver and GENTLY turn the appropriate POT until the respective IR sensors status LED turns dark. Check with your hand if LED lights, if not readjust as you like.
PINS
0 The table below shows the pin arrangement for the 4
time.
Try
0 Connect all four IR sensors and calibrate them.
the serial port doesnt repeat until the IR sensor has gone LOW again (obstruction removed). It shouldn't continuously output the message if the IR sensor is obstructed,
DC motors
0 Motors are devices that convert electrical energy to
0 Motors come in different varieties: AC, DC, Servo, Stepper 0 If motor draws less than 40mA of current, it can be directlu
torque. To avoid burning out the arduino, we use motor drivers to control DC motors.
voltages.
0 It as also called a H-bridge. 0 It uses the transistors as a switch concept to electrically
same supply.
Motor Driver
shield which also contains a wire block for easy connection of the wires.
marked on the board. Do not reverse these connections. The direction might have to be calibrated by testing if the terminals are reversed.
direction.
Wiring motors
0 Attach the arduino shield onto the arduino. 0 Take a 9V battery cap and screw it onto the motor
terminals.
TRY
0 Move both motors in same direction. 0 Reverse both motors. 0 Stop one and turn the other. 0 Stop the other and turn the one. 0 Make each motor turn in a different direction.
Exercise
0 Combine the functionality of 2 IR sensors and the
0 Algorith: 0 Move forward, left and right randomly. 0 If IR sensors detect an obstruction, move a little back in the opposite side of the obstruction 0 Continue.