Analog Input
Many analog transducers convert the physical quantity they are measuring into resistance. For example, a Light Dependent Resistor (LDR), as the name implies, is a resistor whose resistance is a function of the amount of light falling on it. There are other transducers too, for example, a thermistor whose resistance is a function of temperature.
We usually use a voltage divider to convert the resistance into a voltage, which can then be read in by Arduino.
Voltage Divider
'out' should be connected to one of the Analog input pins (A0-A5). Here, we use A0. |
where Vcc = 5V for Arduino To Do : Derive the above. You can assume that the current Iout is negligible. |
---|
Connecting LDR
You have two options for choosing R2. This has an implication on the threshold you set in your program for Exercise 3 Solution.
Option 1 : Use a 10K resistor.
Option 2 : Cover the LDR completely. Measure the resistance (Rdark) using multimeter.
Expose the LDR to light. Measure the resistance (Rbright) using multimeter
Choose R2 = (Rdark + Rbright)/2
analogRead()
Arduino uses a 10-bit A/D converter. The input voltage has to be given to one of the pins A0-A5.
A 10-bit converter means that you get input values from 0 to 1023.
0 V → 0
5 V → 1023
Ex:
C++ | Blocks |
---|---|
int sensorValue = analogRead(A0); | In Tinkercad, we just need Start Simulation, click on the LDR and move the slider to change the amount of light falling on the LDR. |