I am using an Arduino Pro Mini with various sensors. I am powering it with 2 3.7v 3400mA batteries which I recharge with a solar panel. I take a reading from the batteries and if the reading is above a certain number I disconnect the solar panel from the batteries using a relay. Then when the battery reading gets below a certain number I switch back on the solar panel using the same relay. This all works fine. To conserve energy I want to delay the loop to the Arduino's activities for say two hours. Right now I call lowPower(); at the end of the loop{. void lowPower(){ is
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
Which I continually repeat for the two hours I want. The problem is during this two hours the high or low limit of the battery charge could be reached but I wouldn't know it.
What I would like to do is repeat
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
for 15 minutes and then check the batteries and turn on or off the solar charger as need. Then repeat the whole thing until two hrs is reached. At that point I would rerun the loop{ to check all sensors etc. I have tried the following
void loop(){
//code to run other sensors etc.
if (Delay ==4) {
delay(180000);
//check the battery to begin with
sensorBatValue = analogRead(batteryInPin);
delay(500);
if(chargeSwitch ==1){
if(sensorBatValue < batteryNoCharge) {
}
else if(sensorBatValue > batteryNoCharge) {
digitalWrite(10,HIGH);
delay(1000);
digitalWrite(10,LOW);
chargeSwitch = 2;
}
}
else if(chargeSwitch ==2){
if(sensorBatValue > batteryCharge) {
}
else if(sensorBatValue < batteryCharge) {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
chargeSwitch = 1;
}
}
//put to sleep
lowPower();
//check battery again
delay(180000);//real
sensorBatValue = analogRead(batteryInPin);
delay(500);
if(chargeSwitch ==1){
if(sensorBatValue < batteryNoCharge) {
}
else if(sensorBatValue > batteryNoCharge) {
digitalWrite(10,HIGH);
delay(1000);
digitalWrite(10,LOW);
chargeSwitch = 2;
}
}
else if(chargeSwitch ==2){
if(sensorBatValue > batteryCharge) {
}
else if(sensorBatValue < batteryCharge) {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
chargeSwitch = 1;
}
}
// put to sleep
lowPower();
//repeat for total of 2 hours.
}
void lowPower(){
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
//repeat until 15 minutes is reached
}
This doesn't seem to work. The Arduino waits the correct time but from what I can tell the battery is never checked.
Or should I try
void loop(){
everything
if (Delay ==4) {
delay(180000);//real
sensorBatValue = analogRead(batteryInPin);
delay(500);
if(chargeSwitch ==1){
if(sensorBatValue < batteryNoCharge) {
}
else if(sensorBatValue > batteryNoCharge) {
digitalWrite(10,HIGH);
delay(1000);
digitalWrite(10,LOW);
chargeSwitch = 2;
}
}
else if(chargeSwitch ==2){
if(sensorBatValue > batteryCharge) {
}
else if(sensorBatValue < batteryCharge) {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
chargeSwitch = 1;
}
}
//include the checking of the battery inside the lowPower
void lowPower(){
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
etc.
LowPower.powerDown(SLEEP_8S,ADC_OFF,BOD_OFF);
//check battery after 15 min.
delay(500);
sensorBatValue = analogRead(batteryInPin);
delay(500);
if(chargeSwitch ==1){
if(sensorBatValue < batteryNoCharge) {
}
else if(sensorBatValue > batteryNoCharge) {
digitalWrite(10,HIGH);
delay(1000);
digitalWrite(10,LOW);
chargeSwitch = 2;
}
}
else if(chargeSwitch ==2){
if(sensorBatValue > batteryCharge) {
}
else if(sensorBatValue < batteryCharge) {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
chargeSwitch = 1;
}
}
//then repeat to two hours
}
Do I need to do something to wake up the Arduino and Turn on the battery sensor pin and turn back on ADC?
Not sure how to do this Please HELP.
condition
is?) and indent your code properly. I'm not going to solve that puzzle...