# Functionality

0 Input can be retrieved onto the Arduino in a number

of ways both digital and analogue.

0 Sensors convert changes in a physical quantity to

electrical signals that can be interpreted with the Arduino.

0 Temp sensors, Light Sensors, Force sensors are e.g..

Temperature sensors
0 Gives a Vout propotional to ambient room

temperature.

0 Concept : as temperature increases, voltage

across a p-n junction increases at a known rate. (in this case Vbe)

0 Voltage at Anlg.Pin in Volts = (reading

from ADC) * (5/1024) V 0 Centigrade temperature = [(analog voltage in V) – 0.5] * 100

Before: Writing the code
0 Review: 0 How does the lm35 work? 0 Read datasheet of lm35. 0 How to connect it to arduino? 0 What reference to use? 0 What sort of noises will be present? 0 What does the analogue input signify?

Datasheet of LM35

Circuit connection diagram

Temp sensor code
0 Connect lm35 as per circuit diagram in 7. Temp Sensor

folder.

0 We’re giving AREF as 3.3V to reduce noise from the

LM35 and give more accurate readings.

0 Upload code onto Arduino and Output is seen in the

Serial monitor of the Arduino.

Write the code
1. Decide which analogue pin you’re going to and

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.

Keep Writing the code
0 To get temp in centigrade, (volt – 0.5) * 100

0 This is the ambient temperature recognized by the

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

then add 32 to that result. Send it to serial port too.

Improvements?
0 Use 3.3V as reference to increase resolution since

datasheet says that resolution of lm35 ~ 10mV. resistance,

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.

0 Any other applications?

LDR
0 An LDR is a Light Dependent Resistor. 0 As in the resistance offered by this device to an

electrical circuit is dependent on the amount of light falling on the circuit.

0 Also called photocells because they convert light

energy to an electrical response.

0 Useful for on-when-light/off-when-dark.

How to connect the LDR
0 LDR is basically a resistor, so it can be connected

anyway.

0 You need a pull-down resistor to avoid sinking all the

current onto the arduino pin.

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

Ambient light (lux) 0.1 lux 1 lux 10 lux

Photocell resistance (Ω) 600KΩ 70 KΩ 10 KΩ

LDR + R (Ω) 610 KΩ 80 KΩ 20 KΩ

Current thru LDR +R 0.008 mA 0.07 mA 0.25 mA

Voltage across R 0.1 V 0.6 V 2.5 V

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.

0 In setup(){ }, initialize serial port with 9600.
0 In loop(){ }, first do an analogueread(pin) and store it in an

0 This value represents illumination received by LDR. 0 Send it to Serial Port.
0 Allow delay of some time to let the ADC settle.

Application 1
0 Make thresholds and determine the brightness

received and send it via serial port.

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

amount in an LED blinking scenario. Use ledpin = 13.

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.

0 Put an object of a particular color in front of the LDR.
0 Light up RED LED and measure LDR value 0 Light up GREEN LED and measure LDR value 0 Light up BLUE LED and measure LDR value 0 From these three analogue values you can determine the

color of object being sensed.

Sensor Data on PC
0 Reading and plotting sensor data on PC is very simple

on the arduino.

0 Send data continuously to the computer over the

serial port.

0 Data can be viewed by any program capable of

viewing this data

Send sensor data to serial port
0 Open the folder Sensor data graph

0 Upload the arduino code onto the arduino and close

arduino IDE after checking serial monitor.

0 In softwares folder extract the processing folder.

0 Open processing and copy the processing code onto it and

run.

0 Make sure serial port number in the processing sketch

matches arduino