ESP8266에 Deep_Sleep 모드가 있는 것처럼 아두이노 보드에 있는 Sleep Mode를 사용해봅니다.

<참고글>

https://cafe.naver.com/dgarduino/4028

 

아두이노 잠재우기와 깨우기 - Don...

대한민국 모임의 시작, 네이버 카페

cafe.naver.com

 

https://playground.arduino.cc/Learning/ArduinoSleepCode/

 

Arduino Playground - ArduinoSleepCode

attachInterrupt(0, pin2_isr, LOW); /* 0, 1, or many lines of code here */ set_sleep_mode(SLEEP_MODE_PWR_DOWN); cli(); sleep_enable(); sleep_bod_disable(); sei(); sleep_cpu(); /* wake up here */ sleep_disable();

playground.arduino.cc

 

https://www.element14.com/community/thread/40538/l/arduino-sleep-pin-interrupt?displayFullThread=true

불러오는 중입니다...

 

다섯가지 방법중 첫번째인 외부인터럽트를 이용한 방법으로 LED Blink를 10회 실행하며, Blink 횟수를 카운트하여 시리얼모니터로 출력하고  "Good Night.."출력 후 Sleep모드로 진입합니다.

버튼을 누르면 다시 깨어나 Blink를 시작합니다.

#include <avr/sleep.h>

int wakePin = 2; // pin used for waking up

int led=13;

void wakeUpNow() {

// execute code here after wake-up before returning to the loop() function

// timers and code using timers (serial.print and more...) will not work here.

// we don't really need to execute any special functions here, since we

// just want the thing to wake up

}

void setup() {

Serial.begin(115200);

pinMode(wakePin, INPUT_PULLUP);

pinMode(led, OUTPUT);

attachInterrupt(0, wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW

}

void sleepNow() {

set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here

sleep_enable(); // enables the sleep bit in the mcucr register

attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function

sleep_mode(); // here the device is actually put to sleep!!

// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP

sleep_disable(); // first thing after waking from sleep: disable sleep...

detachInterrupt(0); // disables interrupt 0 on pin 2 so the wakeUpNow code will not be executed during normal running time.

}

void loop() {

Serial.println("Blink Start...");

for(int i=0; i<10; i++){

digitalWrite(led, HIGH);

delay(1000);

digitalWrite(led, LOW);

delay(1000);

Serial.println(i);

}

Serial.println("Good Night..");

delay(1);

sleepNow(); // sleep function called here

//Serial.println("Hello!");

}

 

 

버튼을 누른 후 깨어나 Blink Start...를 출력할때 제대로 출력되지 않는 현상이 보입니다.

미니 파워서플라이인 B3603을 이용하여 소모전류를 측정한 결과

Blink동작중 41mA

 

슬립모드 진입후 29mA로 확인되었습니다.

 

슬립모드 진입후에도 29mA의 소모전류가 흐르는 것은 LED, Regulator, usb시리얼용 IC(Atmega16u2)등이 계속 동작하기 때문일 것입니다.

전원이 공급되면 항상 켜지는 전원 표시용 LED를 제거한 후 소모전류를 확인해본 결과

<제거전>

 

<제거후>

 

Blink동작시 41mA -> 37mA로 4mA 감소

 

슬립모드 진입시 29mA -> 23mA로 6mA 감소되는 것이 보입니다.

+ Recent posts