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)

closed as unclear what you're asking by gre_gor, Enric Blanco, Code Gorilla, jfpoilpret, KIIV May 15 '17 at 20:35

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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. – Enric Blanco 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. – James Waldby - jwpat7 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!

  • 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