BOD_OFF
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
}
#include "LowPower.h"
unsigned int sleepCounter = 0;
unsigned int sleepCounter2 = 0;
unsigned int batteryCounter = 110; // 8 sec X 110 = 15 min approx.
unsigned int sensorCounter = 900; // 8 sec X 900 = 2 hours approx.
unsigned int voltageReading = 0;
void setup(){
// Test using pin 13 and Serial Monitor.
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Serial.begin(9600);
}
void loop(){
// Enter power down state for 8 seconds.
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// Increment counters.
sleepCounter++;
sleepCounter2++;
// Check the battery voltage.
if(sleepCounter == batteryCounter){
// Reset the counter.
sleepCounter = 0;
delay(10);
voltageReading = analogRead(A0);
// Turn the built in LED On for 1 second then Off.
// Send the voltage reading to the Serial Monitor.
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
Serial.print("Voltage=");
Serial.println(voltageReading);
Serial.flush();
}
// Check the sensors.
if(sleepCounter2 == sensorCounter){
// Reset the counter.
sleepCounter2 = 0;
// Turn the built in LED On for 2 seconds then Off.
// Send a message to the Serial Monitor.
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Checking Sensors.");
Serial.flush();
}
}
#include "LowPower.h" // import the lowpoer library
int led = 13;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); // instead of delay(1000) ;
digitalWrite(led, LOW);
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); // instead of delay(1000) ;
}
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
}