Skip to content

WakeOnInterrupt.ino

Arnd edited this page Dec 11, 2020 · 5 revisions

Arduino sketch to demonstrate how the processor can be put to sleep in low-energy mode and be woken up by the hardware INT output pin on the VCNL4010 when a given condition is reached.

Compatibility

Serial Communications

The code contains conditional compile sections for the Arduino Micro. This is necessary because of the way that serial communications are handled on this chip. The USB communication port on the Micro needs to be turned off prior to the system going to sleep and then needs to be restarted and reinitialised after waking up.

Wake-up Interrupt Pins

Each Atmel processor has somewhat different pin allocations for wake-up calls. A description of which pins can be used on which processor can be found at Arduino attachInterrupt(). The constant WAKE_UP_PIN is set to use digital pin 7 in this sketch, which will work on the Arduino Micro and would need to be changed on other processors. Note that there should be a 4.7KOhm pull-up resistor attached to this pin.

Function

The VCNL4010 is initialised in the setup() method and the setInterrupt() function is called to trigger if the proximity reading changes by +/- 10% and then the processor is put to sleep until that event is triggered. Once woken up the program sends out a message on the serial port and then goes back to sleep again until once again woken up by a 10% change in reading.