Wednesday, March 1, 2017

How to calculate the values of the sensors


As I mentioned in a previous post, this is the output that is printing on the serial monitor of the Arduino IDE when I have four photoresistors set up in a voltage divider with four 10k ohm resistors. (The schematic diagram and an image of the actual circuit can be found on 2/7/17.)

The values that are printing for each of the four sensors are actually the voltages outputted from the voltage divider as a 10 bit number.
 
analogRead() returns a value, in bits, and automatically defaults to 10 bits (returns values between 0-1023) (https://www.arduino.cc/en/Reference/AnalogReadResolution). I am using 5v as power. This is the maximum voltage which maps over to the maximum value in bits, 1023. 

The values printed as the sensor values can be calculated using a proportion. The equation will be the output voltage from the voltage divider over the maximum voltage (5v) which is equal to the value printed on the serial monitor over the maximum voltage in bits (1023).

For example, if the photoresistor, at a particular moment, had a value that was equal to the other resistor in the voltage divider, which in this case is 10,000 ohms, then the voltage divider will output exactly half of the initial power, which is 5v. This means that the output will be 2.5v so the value that will print on the serial monitor will be that number in bits which is calculated below:

2.5v  =    x   
 5v        1023

So the value of x is about 512.

1 comment: