Hello
How can I reduce the power consumption of Arduino by getting it into sleep mode, and it turns on or wakes up when the sensor reads something?
This code is being used to read continuously. But i want it to read whenever the sensor reads or senses data using interrupt.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(3,4,5,6,7,8);
// Threshold values for the led bar
#define TH1 45
#define TH2 95
#define TH3 200
#define TH4 400
#define TH5 600
// Conversion factor - CPM to uSV/h
#define CONV_FACTOR 0.00812
// Variables
int ledArray [] = {10,11,12,13,9};
int geiger_input = 2;
long count = 0;
long countPerMinute = 0;
long timePrevious = 0;
long timePreviousMeassure = 0;
long time = 0;
long countPrevious = 0;
float radiationValue = 0.0;
void setup(){
pinMode(geiger_input, INPUT);
digitalWrite(geiger_input,HIGH);
for (int i=0;i<5;i++){
pinMode(ledArray*,OUTPUT);*
-
}*
-
Serial.begin(19200);*
-
lcd.clear(); *
-
attachInterrupt(0,countPulse,FALLING);*
}
void loop(){ -
if (millis()-timePreviousMeassure > 1){*
_ countPerMinute = 60*count;_
radiationValue = countPerMinute * CONV_FACTOR; -
timePreviousMeassure = millis();*
-
if(count>=1){*
-
Serial.println(millis()); *
-
lcd.clear(); *
-
lcd.setCursor(0, 0);*
-
lcd.print("Counting ...");*
-
}*
-
if(countPerMinute <= TH1) ledVar(0);*
-
if((countPerMinute <= TH2)&&(countPerMinute>TH1)) ledVar(1);*
-
if((countPerMinute <= TH3)&&(countPerMinute>TH2)) ledVar(2);*
-
if((countPerMinute <= TH4)&&(countPerMinute>TH3)) ledVar(3);*
-
if((countPerMinute <= TH5)&&(countPerMinute>TH4)) ledVar(4);*
-
if(countPerMinute>TH5) ledVar(5);*
-
count = 0;*
-
}*
}
void countPulse(){ -
detachInterrupt(0);*
-
count++;*
-
while(digitalRead(2)==0){*
-
}*
-
attachInterrupt(0,countPulse,FALLING);*
}
void ledVar(int value){ -
if (value > 0){*
-
for(int i=0;i<=value;i++){*
_ digitalWrite(ledArray*,HIGH);_
_ }_
_ for(int i=5;i>value;i--){_
_ digitalWrite(ledArray,LOW);
}
}
else {
for(int i=5;i>=0;i--){
digitalWrite(ledArray,LOW);
}
}
}*_