Hi guys, I’m new to arduino and C++ programming. What I want to achieve is to put arduino in sleep mode and wake up with interrupt, but I want that interrupt sygnal must last at least one second. As a sygnal interrupt I use IR pilot and IR receiver. Sleep mode is working, attachinterrupt is working but I get a lot of incidental wake ups. I know it’s because IR receiver is bouncing and waking up by random. I don’t know how to contain debounce with attachInterrupt together, to disable sleep only when FALLING stay on for in example one second. How to make this more insensible? Is that possible?
test06.ino (837 Bytes)
uint32_t begin_time = millis();
if (digitalRead(interruptpin) == HIGH )
begin_time = millis();
attachInterrupt(int, whatever, LOW);
if( millis() - begin_time > 1000 )
The only this the whatever ISR should do is detachInterrupt.
Untested, but I was actually thinking about a similar thing a couple weeks ago. This is the method I came up with. Obviously will not compile as is, you will have to substitute in actual code for the parts I’ve shorthanded.
but I want that interrupt sygnal must last at least one second
An interrupt is always an instantaneous thing - there is no such thing as a long interrupt.
The Arduino must be awake in order to measure time.
If you want to ignore IR interrupts for a second AND for the Arduino to sleep for most of the time while it is doing so then I think you need to set up another Timer interrupt that can wake up the Arduino briefly for N occasions during which the IR interrupt is OFF and when the Nth timer interrupt happens it turns on the IR interrupt and turns off the timer interrupt. When the following IR interrupt happens it will turn on the timer interrupts and turn off the IR interrupts.
However I wonder if what you are trying to do is worth that much trouble?
What are you trying to achieve?
I want to control light in my room with remote control, I used Arduino Pro mini, IR receiver and a relay and at moment everything is working but now power source is the problem. I must recharge batteries I reckon too often for this little project (4-5 days), so I'm looking for ideas how make this consume less power. I though about sleeping mode in majority of time and waking up only to change lights ON or OFF, and now I have problem bcs sleeping mode don't remain as long as I want.
That's a bit of a different thing then. An IR remote sends data codes, so holding the button for 1 second doesn't hold down the data line for 1 second, it just sends repeat codes at intervals.
What batteries are you using? What are you using to regulate voltage to the Pro Mini, or are you putting unregulated voltage on RAW?
I note that the device will only go to sleep if it gets the correct IR command. If you use any other IR remote in the vicinity of this device, it will wake up and check the code. If it's not the right code, it stays awake until it receives the correct one. I highly doubt that this is what you want.
I used Arduino Pro mini, IR receiver and a relay
Forgot about this, but relays suck a LOT of power.
now I have problem bcs sleeping mode don't remain as long as I want.
The length of time it sleeps for does not matter. Suppose it sleeps for 1 second then wakes for 5 millisecs. That means it is asleep for 99.5% of the time. If you want to "sleep" for a minute just increment a counter every time it wakes up. If it wakes every second then when the count gets to 60 a minute will have elapsed.