Go Down

Topic: Reading a DC voltage (Read 474 times) previous topic - next topic

JuggTheGreat

I have a voltage divider circuit set up to read 1/10 of the actual voltage via 2 resistors when I try to read from the  analog input A0, my output looks like nonsense.

Output (via serial monitor):

0.00
5.00
3.34
1.05
5.00
0.50
3.58
4.75
0.00
5.00
3.38

The code is straight forward:

void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue1 = analogRead(A1);
float voltage1 = sensorValue1*(5.0/1023.0);
Serial.println(voltage1);
}

What is the best way to get a steady reading from a DC voltage?


DVDdoug

#1
Mar 20, 2017, 08:40 pm Last Edit: Mar 20, 2017, 08:43 pm by DVDdoug
Are you sure you have DC?  Are you sure you're connected to A1?

What is the source of this voltage?

Is the voltage-under-test's ground connected to the Arduino's ground?

Try connecting the Arduino's 5V to A1.  And/or, connect the Arduino's 5V to the voltage divider to confirm you are reading 0.5V.

jremington

#2
Mar 20, 2017, 08:43 pm Last Edit: Mar 20, 2017, 08:43 pm by jremington
What resistors are you using? The smallest should be less than 10K Ohms.

Do not forget to connect the grounds.

JuggTheGreat

It was the ground issue. I did not have the voltage source connected to the arduino ground. That solves that, thanks.


Go Up