Hi all. First of all if there could be a better title please let me know not sure how i could formulate my problem better.
I have borrowed some volt measurment code and adjusted it a bit so i would have a buzzer buzz when voltage would drop below a certain voltage.
In the first case, having the voltage drop below 12 volt with a delay of 1000ms at end of coude , would give me a solid beep until voltage would rise above 12v again.
For my second try i changed my code. beep when voltage drops below 12.05v and measuring every 500ms.
Here is where i had troubles, there was no beep. i had my serial monitor running and data being saved. there were two measurments below 12.05v.
below i add the code i borrowed and adjusted, any of you can figure out why the faster readings and different voltage would give me troubles?
/*
0 - ~17volt voltmeter
works with 3.3volt and 5volt Arduinos
uses the stable internal 1.1volt reference
10k resistor from A0 to ground, and 150k resistor from A0 to +batt
(1k8:27k or 2k2:33k are also valid 1:15 ratios)
100n capacitor from A0 to ground for stable readings
*/
int buzzer = 11;
unsigned int total; // holds readings
float voltage; // converted to volt
void setup() {
pinMode(11, OUTPUT);
analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
Serial.begin(9600); // ---set serial monitor to this value---
}
void loop() {
total = 0; // reset
analogRead(A0); // one unused reading to clear any ghost charge
for (int x = 0; x < 64; x++) { // 64 analogue readings for averaging
total = total + analogRead(A0); // add each value
}
voltage = total * 0.0002505; // convert readings to volt | ---calibrate by changing the last three digits---
Serial.print("The battery is ");
Serial.print(voltage, 2); // change to (voltage, 3) for three decimal places
Serial.println(" volt");
if(voltage<=12.05 )
{
digitalWrite (buzzer, HIGH);
}
else
{
digitalWrite (buzzer, LOW);
}
delay(500); // readout delay
}