0

I want to read voltage level by my Arduino board please help in this regard. I am using this syntax.

volts = analogRead(A3);    // read the input pin
Serial.println(volts)
4
  • 1
    Show where and how in your code you declare volts, and how are you wiring the voltage you want to read to the analog input. May 11 '17 at 8:40
  • 1
    Also, in what way is this not working?
    – Mark Smith
    May 11 '17 at 10:57
  • 1
    Other than missing the semicolon on the end of the second line, this chunk of code will work. Can you please show your whole program?
    – sa_leinad
    May 11 '17 at 12:53
  • 1
    Note that instead of printing out the number of volts on the input, it will output an ADC count that stands for some number of volts; by default, 1024/5 counts per volt. May 11 '17 at 13:53
0

//use this syntax and add ; sign at end of each line and try to read voltage level via voltage divider circuit.

volts = analogRead(A3);    // read the input pin
Serial.println(volts);             // debug value
1

First off you need to convert your signal's units from analog -> voltage. Do this by using the following equation. I've modified your code so you can copy and paste it into your IDE.

float volts = analogRead(A3) * ( 5.0 / 1024.0) ; 

Hope this helps! Good luck!

2
  • Your first solution will always be 0. 5 / 1024 does integer division which always results in 0. Any number multiplied with 0 is then 0.
    – gre_gor
    May 11 '17 at 19:17
  • @gre_gor I stand corrected! Good catch. I completely forgot about that. :)
    – L. Paw
    May 11 '17 at 21:19