Hello, i am working on power monitoring project. I am using this voltage sensor with arrduino UNO https://www.electronicshub.org/wp-content/uploads/2018/07/Interfacing-Voltage-Sensor-with-Arduino-Voltage-Sensor-Pins.jpg
and my code is
int Button = 2;
int buttonstate;
int analogInput = A1;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; //
float R2 = 7500.0; //
int value = 0;
void setup(){
pinMode(analogInput, INPUT);
pinMode(Button, INPUT);
Serial.begin(9600);
Serial.print("DC VOLTMETER");
}
void loop(){
// read the value at analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
Serial.print("INPUT V= ");
Serial.println(vin,2);
delay(100);
buttonstate = digitalRead(Button);
Serial.println(buttonstate);
}
everything works fine, i am getting perfect value on serial monitor. After few hours, the serial monitor stopped printing the voltage sensor value but buttonstate value is contentiously printed on serial monitor.
Please tell me what i am doing wrong? or any suggestions? Thanks in advance