Hello!
Im trying to make a simple program that reads voltage and prints it to the serial monitor. I have a circuit where the ground connects to a 1.5V battery and the battery connects to port A3. I am using this code for it:
#define reading A3
void setup() {
// put your setup code here, to run once:
analogRead(reading);
Serial.begin(9600);
pinMode(reading, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int pulse = analogRead(reading);
float Voltage = (pulse*(3.3/1023));
Serial.print(Voltage);
delay(1000);
Serial.print('\n');
}
It works and prints the proper voltage of the battery that I am hooking up to it, but as soon as the connection is broken it starts to print nonsense that ranges between 0 and 3.3. How can I fix this issue?