{{ message }}

Instantly share code, notes, and snippets.

Last active Mar 28, 2021
Arduino function to read a Vegetronix VH400 Soil Moisture Sensor. See http://www.vegetronix.com/Products/VH400/
 I got a question concerning the calculation of sensorVoltage: `// Read value and convert to voltage int sensor1DN = analogRead(analogPin); float sensorVoltage = sensor1DN*(3.0 / 1023.0); float VWC;` For the above calculation to work, you have to put a 3V source to your ref_pin on your Arduino. Usually the ArduinoADC compares the input voltage to 5V. Since the sensor can only put out 3V max that would correspond to 613 analogRead value. In that case your sensorVoltage would never go higher than 1.798V. I think you have to replace the 3.0 with a 5.0: `// Read value and convert to voltage int sensor1DN = analogRead(analogPin); float sensorVoltage = sensor1DN*(5.0 / 1023.0); float VWC;` Can someone confirm, that what I'am thinking is right, or am I wrong?
 I also was wondering 5.0 multiplier and the I had other thoughts why not to use internal 3.3V regulator for reference. By doing this you will lose only 10% resolution compared to 3.0V reference. Connect 3.3V output to AREF and then call analogReference(EXTERNAL) In this case you should get the sensor voltage with this: `float sensorVoltage = sensor1DN*(3.3 / 1023.0);` `3V3 pin: A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA. AREF pin: The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogReference() function.` To get even better resolution you can connect 3.3V output to AREF through 3.2kΩ resistor giving exact 3.0V reference. (Closest in E12 series is 3.3kΩ => 2,991501416V reference) `You can connect the external reference voltage to the AREF pin through a 3.2K resistor, allowing you to switch between external and internal reference voltages. Note that the resistor will alter the voltage that gets used as the reference because there is an internal 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 3.3V applied through the resistor will yield 3.3 * 32 / (32 + 3.2) = 3.0V at the AREF pin.` In this case you should get the sensor voltage with this: `float sensorVoltage = sensor1DN*(3.0 / 1023.0);`