Tonight, I have spent some time looking into the sensor code for the G3H project. In the code I posted last week, sensors are read through a digital pin and exactly that value is displayed. A digital pin outputs a value between 0 and 1024 of type integer. An integer is a whole number, meaning no comma: 1, 2, 3, 4, 5 are integers, but 1.05 and 2.35 are not. Those numbers are usually called floats. More info on integer, float and other data types can be found on wikipedia.
If you measure the voltage on the pin, you will find that it is anywhere between 0V and 5V, where 0V corresponds to the digital value 0 and 5V corresponds to 1024. This is not entirely true as the minimum voltage is 0.005V, or 5 millivolts.
That means that each step up, measured digitally (the range between 0 and 1024) corresponds to 5V/1024 steps = 0.0048828125V.
This can be easily put into a short function you can use for all sensors using a digital pin:
/*
* getVoltage() – return the voltage on the analoge input defined by pin
*
*/
float getVoltage(int pin) {
return (analogRead(pin) * .004882813);
// reading a digital pin returns a value between 0 and 1024, which corresponds to a voltage range
// between 0V and 5V.
// So, one digital step means 5V/1024 = ~0.005V, or about 5 millivolt
}
With this value it is a lot easier to translate the value read from the sensor to meaningful data. In a future post I will show you how to use a thermistor to measure temperature and use this information to translate the voltage on the digital pin to degrees centrigrade or fahrenheit.


Hello!
I can’t contact you privately.
If you can please send me and email at info@bemushroomed.com
I’m developing an opersource community about spreading for free mushrooms (edibles) cultures, and one of my next step is to develop a tool that controls humidity, temperature, light and if possible also CO2 into a greenhouse. I’d like to use an Arduino too.
Once the tool will be developed I’d like to publish the plans freely and write a tutorial.
If you want I’d like you can help us!
Thanks!
Fabio