imranahmed
Advanced Member level 3
- Joined
- Dec 4, 2011
- Messages
- 817
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Karachi,Pakistan
- Activity points
- 6,493
Please let me know I connected a LDR to Arduino UNO at pin A0 analog pin and Arduino UNO`s sleep and wake instructions are programmed. But only external interrupt is available for wake up of microcontroller cpu. I want to wake up microcontroller at a certain voltage level defined by me. Do we set external interrupt voltage to trigger at pre-defined level?
Full working code is below but voltage level to trigger external interrupt at pin2 is want to know?
Full working code is below but voltage level to trigger external interrupt at pin2 is want to know?
Code:
#include <avr/sleep.h>
#define interruptPin 2
unsigned long lastTimeOut = 0;
unsigned long timeOut = 5000;
const int LDR_PIN = A0;
void Sleep(){
sleep_enable(); // Enable sleep mode
attachInterrupt(0,wakeUp, LOW); //Attach interrupt to pin 2
set_sleep_mode(SLEEP_MODE_PWR_DOWN);//Full Sleep mode
delay(1000);
digitalWrite(LED_BUILTIN, LOW);// LED OFF
//delay(1000);
sleep_cpu();
Serial.println("Just Woke Up");
digitalWrite(LED_BUILTIN, HIGH);// LED ON
}
void setup() {
Serial.begin(9600);
pinMode(interruptPin, INPUT_PULLUP);
pinMode(LDR_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
lastTimeOut = millis();
}
void loop() {
int ldr = analogRead(A0);
int v = (5*ldr)/1023;
Serial.println(v);
if((millis() - lastTimeOut) > timeOut){
lastTimeOut = millis();
Sleep();
}
// delay(1000);
}
void wakeUp(){
Serial.println("Interrupt Fired");// message to serial port
sleep_disable();// Disable sleep mode
detachInterrupt(0);// remove interrupt from pin 2
}