Hi there,
i followed Mr.electronoob video on youtube and was able to measure constant battery voltage and that was exactly what i needed at an initial stage. Now, i have to add sensor to my code but after adding sensor to it the reading are not accurate. I am using solar panel for battery charging purpose during the daytime. The solar panel must be able to read voltage levels in order to detect day or night mode. for example: if (solar_voltage>=4){
Do something
}
ok, so heres's my code.
int led = 8;
void setup(){
Serial.begin(9600);
pinMode (led,OUTPUT);
}
void loop() {
//REFS1 AND REFS0 to 1 1 -> internal 1.1V refference
analogReference (INTERNAL);
//ADMUX = B11000000;
//We read A1 (MUX0)
int value = analogRead (A1);
//ADMUX = B00000001;
//int sensor = analogRead(A1);
// Start AD conversion
ADCSRA |= B11000000;
// Detect end-of-conversion
while (bit_is_set(ADCSRA,ADSC));
float val = ADCL | (ADCH <<
;
val = val * 5.7; //Multiply by the inverse of the divider
value=val;
Serial.println(val);
float voltage = val * analogRead(A0) / 1023;
voltage = ADCL | (ADCH <<
;
Serial.print ("voltage at A0:");
Serial.println(voltage);
Serial.print ("Solar panel voltage:");
Serial.println(voltage * 5.7);
delay(1000);
if (voltage>=174){ //1.1V
digitalWrite (led,HIGH);
}
else{
digitalWrite(led,LOW);
}
}
output was recorded from a Serial monitor. Schematic and output file has been attached below.
The issue is i need to connect my battery to solar panel and if i do so, the solar panel stops working. I believe that only you can better understand my situation as i have followed your tutorial.