シーリングライトリモコンタイマーv2   

どうも電池の減るのがはやい。12日目に電圧が下がって動作しなくなった。セリアのバッテリーチャージャーはイマイチか。そこで、電源を単3✕2+DCDCコンバータ(秋月電商、300円)に変えてみた。これでようすを見るべし。。


  



シーリングライトリモコンタイマー   

夜ベッドで寝る前に本を読んでいる。
しかし、天井灯(Panasonic製 HK9494)がついたままいつの間にか眠ってしまうことが多い。
そこで設定時間後に消灯するリモコンを作った。
赤外線リモコンは以前オーム電機リモコンセントの赤外線リモコンを作っているので、それに従った。

赤外線LEDのパワーがちょっとショボいようで、純正に比べて届く範囲がやや狭く不満ではあるが、
これで「また朝までついとったで」と嫌味いわれることはなくなるやろう。やれやれ。

(機能)
  点灯(赤ボタン)
  消灯(黒ボタン)
  リセット(茶ボタン、タイマーを解除するときに使用)
  タイマーオン(黄ボタン)
  タイマーボタンを押すと表示用LEDが点滅し30分後に消灯する。
   点滅速度は残り時間30~20分の時1秒ごと、20~10分の時1/2秒ごと、10~0分の時1/4秒ごと。

(パーツ)
  ブレッドボード(300穴)2枚、100均ケース(PP製)
  Arduino NANO(Amazon 中国製)、赤外線LED+100ohm抵抗、白色LED+1kohm抵抗
  セリアUSBチャージャー(改造して赤黒線を出す)、ジャンパー線
  タクトスイッチ4個、スライドスイッチ1個、

(回路)
  写真の通り(上側のLEDが赤外線LED、光っているLEDはタイマー作動時表示用)

     

(参考にしたサイト)
  試行錯誤な日々 Arduinoで赤外線リモコンの値を読み取り、送信する方法
  Make 赤外線リモコンを作る
  hawksnowlog Arduino で赤外線信号を学習してエアコンを制御してみた

(スケッチ) → sketch のダウンロード

/*  IR_timer_05.ino

    IR remote controller for Panasonic ceiling light (HK9494) by Arduino NANO

                           D1/TX・     ・Vin
                           D0/RX・     ・GND
                           RESET・     ・RESET    => reset button
                             GND・     ・5V
    for received IR sensor <= D2・     ・A7 cannot use for digital input and output
                    IR LED <= D3・     ・A6 cannot use for digital input and output
                              D4・     ・SCL/A5   => TIMER_button
                              D5・     ・SDA/A4
                              D6・     ・PIXEL/A3
                              D7・     ・D16/A2   => OFF_button
                              D8・     ・D15/A1
                              D9・     ・D14/A0   => ON_button
             indicate_LED <= D10・     ・AREF
                             D11・     ・3.3V
                             D12・[USB]・D13
*/

#include <MsTimer2.h>  // using MsTimer2, cannot use tone() function
//    and PMW output(analogWrite()) on 13pin and 11pin
#include <IRremote.h>   // for send and receive of IR signal

#define ON 1
#define OFF 2
#define indicate_LED 9
#define ON_button A2
#define OFF_button A1
#define TIMER_button A0  // When on Pin1, noise occured.

int loop_count = 300;  // 300 for 30min
int khz = 38;   // for IR controller
IRsend irsend; // for IR controller

void send_signal(int command) { //  function of send IR signal
  if ( command == ON) {   //  ON signal
    Serial.println("ON");
    unsigned int irSignal[83] = {3450, 1750, 400, 450, 400, 450, 400, 1350, 400, 1300, 400,
          450, 400, 1350, 400, 450, 400, 450, 400, 450, 400, 1300, 450, 400, 450, 400, 450, 
          1350, 400, 400, 450, 1300, 400, 450, 400, 1300, 450, 400, 450, 450, 400, 1300, 400,
          450, 450, 400, 450, 400, 450, 450, 400, 1300, 450, 350, 500, 1300, 400, 450, 400,
          1350, 400, 1300, 400, 450, 400, 450, 400, 450, 450, 400, 450, 1300, 400, 1350, 350,
          1350, 400, 1300, 400, 450, 400, 450, 450, };
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  if ( command == OFF) {   //  OFF signal
    Serial.println("OFF");
    unsigned int irSignal[83] = {3450, 1700, 450, 450, 400, 450, 400, 1300, 450, 1300, 400, 
          450, 400, 1300, 450, 400, 450, 450, 400, 450, 400, 1300, 450, 400, 450, 400, 450,
          1300, 400, 450, 450, 1250, 450, 450, 400, 1300, 450, 400, 450, 400, 450, 1300, 400,
          450, 450, 400, 450, 400, 450, 400, 450, 1300, 400, 1300, 450, 1300, 400, 450, 400, 
          1300, 450, 1300, 400, 450, 400, 450, 450, 400, 450, 1300, 400, 1300, 450, 1250, 450, 
          1300, 400, 1300, 450, 400, 450, 450, 400, };
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
}

void setup() {          // Pin3 is for IR signal
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(indicate_LED, OUTPUT);
  pinMode(ON_button, INPUT_PULLUP);
  pinMode(OFF_button, INPUT_PULLUP);
  pinMode(TIMER_button, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(TIMER_button) == LOW) {  // switch on is LOW, because input is pullup.
    Serial.println("TIMER_button ON!");
    send_signal(ON);          // light on
    Serial.println("1st loop: ");
    for (int i = 1; i <= loop_count; i++) {  // blink for 10min(600sec)
      Serial.print(i); Serial.print(" ");
      if (i % 10 == 0) {
        Serial.println("");
      }
      digitalWrite(indicate_LED, HIGH);
      delay(1000);
      digitalWrite(indicate_LED, LOW);
      delay(1000);
    }
    Serial.println("2nd loop: ");
    for (int i = 1; i <= loop_count * 2; i++) { // blink for 10min(600sec)
      Serial.print(i); Serial.print(" ");
      if (i % 10 == 0) {
        Serial.println("");
      }
      digitalWrite(indicate_LED, HIGH);
      delay(500);
      digitalWrite(indicate_LED, LOW);
      delay(500);
    }
    Serial.println("3rd loop: ");
    for (int i = 1; i <= loop_count * 4; i++) { // blink for 10min(600sec)
      Serial.print(i); Serial.print(" ");
      if (i % 10 == 0) {
        Serial.println("");
      }
      digitalWrite(indicate_LED, HIGH);
      delay(1000 / 4);
      digitalWrite(indicate_LED, LOW);
      delay(1000 / 4);
    }
    digitalWrite(indicate_LED, LOW);
    send_signal(OFF);          // light off
  }
  if (digitalRead(ON_button) == LOW) {      // switch on is LOW, because input is pullup.
    send_signal(ON);             // light on
    digitalWrite(13, HIGH);
  }
  if (digitalRead(OFF_button) == LOW) {
    send_signal(OFF);            // light off
    digitalWrite(13, LOW);
  }
  delay(100);
}



おまけ   

以下は天井灯(Panasonic製 HK9494)の純正リモコンををコピーした回路である。

(機能)
  点灯(肌色タン)
  消灯(緑色ボタン)
  全灯(黄色ボタン)
  明るい(水色ボタン)
  暗い(白色ボタン)
  常夜灯(茶色ボタン)
    +   タイマーオン(赤ボタン)
   タイマーボタンを押すと3つの表示用LEDが点灯し30分後に消灯する。
   残り時間30~20分の時は左のLEDが点滅、20~10分の時は左のLEDは消灯し真ん中のLEDが点滅、
   10~0分の時は左と真ん中が消灯し右のLEDが点滅する。

(回路)
  写真の通り

  

(スケッチ) → sketch のダウンロード

/*  IR remote controller for Panasonic ceiling light (HK9494) by Arduino NANO

                          D1/TX・     ・Vin
          TIMER_button <= D0/RX・     ・GND
                          RESET・     ・RESET
                            GND・     ・5V
   for received IR sensor <= D2・     ・A7 cannot use for digital input and output
                   IR LED <= D3・     ・A6 cannot use for digital input and output
                             D4・     ・SCL/A5   => ON_button
                             D5・     ・SDA/A4   => OFF_button
                             D6・     ・PIXEL/A3 => FULL_ON_button
                             D7・     ・D16/A2   => LIGHT_UP_button
                             D8・     ・D15/A1   => LIGHT_DOWN_button
                             D9・     ・D14/A0   => NIGHT_LIGHT_button
                            D10・     ・AREF
                            D11・     ・3.3V
                            D12・[USB]・D13
*/

//#include <MsTimer2.h>   // using MsTimer2, cannot use tone() function
//    and PMW output(analogWrite()) on 13pin and 11pin
#include <IRremote.h>    // for send and receive of IR signal

#define ON 1
#define OFF 2
#define FULL_ON 3
#define NIGHT_LIGHT 4
#define LIGHT_UP 5
#define LIGHT_DOWN 6

#define ON_button A5
#define OFF_button A4
#define FULL_ON_button A3
#define LIGHT_UP_button A2
#define LIGHT_DOWN_button A1
#define NIGHT_LIGHT_button A0
#define TIMER_button 0  // When on Pin1, noise occured.

#define LED_1 12
#define LED_2 10
#define LED_3 8

int loop_count = 300;  // for 30min

int khz = 38;   // for IR controller
IRsend irsend; // for IR controller

void send_signal(int command) { //  function of send IR signal
  if ( command == ON) {   //  ON signal
    Serial.println("ON");
    unsigned int irSignal[83] = {3450, 1750, 400, 450, 400, 450, 400, 1350, 400, 1300, 400, 
           450, 400, 1350, 400, 450, 400, 450, 400, 450, 400, 1300, 450, 400, 450, 400, 450,
           1350, 400, 400, 450, 1300, 400, 450, 400, 1300, 450, 400, 450, 450, 400, 1300, 400,
           450, 450, 400, 450, 400, 450, 450, 400, 1300, 450, 350, 500, 1300, 400, 450, 400,
           1350, 400, 1300, 400, 450, 400, 450, 400, 450, 450, 400, 450, 1300, 400, 1350, 350,
           1350, 400, 1300, 400, 450, 400, 450, 450, };
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  } else if ( command == OFF) {   //  OFF signal
    Serial.println("OFF");
    unsigned int irSignal[83] = {3450, 1700, 450, 450, 400, 450, 400, 1300, 450, 1300, 400, 
          450, 400, 1300, 450, 400, 450, 450, 400, 450, 400, 1300, 450, 400, 450, 400, 450, 
          1300, 400, 450, 450, 1250, 450, 450, 400, 1300, 450, 400, 450, 400, 450, 1300, 400,
          450, 450, 400, 450, 400, 450, 400, 450, 1300, 400, 1300, 450, 1300, 400, 450, 400,
          1300, 450, 1300, 400, 450, 400, 450, 450, 400, 450, 1300, 400, 1300, 450, 1250, 450,
          1300, 400, 1300, 450, 400, 450, 450, 400, };
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  } else if ( command == FULL_ON) {   //  FULL ON signal
    Serial.println("FULL ON");
    unsigned int irSignal[83] = {3450, 1700, 450, 450, 400, 450, 400, 1300, 450, 1300, 400,
          450, 400, 1300, 450, 400, 450, 400, 450, 450, 400, 1300, 450, 400, 450, 400, 450,
          1300, 400, 450, 400, 1300, 450, 450, 400, 1300, 400, 450, 450, 400, 450, 1300, 400,
          450, 400, 450, 450, 400, 450, 400, 450, 400, 450, 450, 400, 1300, 450, 400, 450, 1300,
          400, 1300, 450, 400, 450, 400, 450, 1300, 400, 450, 400, 1300, 450, 1300, 400, 1300,
          450, 1300, 400, 450, 400, 450, 400, };
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  } else if ( command == NIGHT_LIGHT) {   //  NIGHT LIGHT signal
    Serial.println("NIGHT LIGHT");
    unsigned int irSignal[83] = {3450, 1700, 450, 400, 450, 400, 450, 1300, 400, 1300, 450,
          400, 450, 1300, 400, 450, 400, 450, 450, 400, 450, 1300, 400, 450, 400, 450, 400,
          1300, 450, 400, 450, 1300, 400, 450, 450, 1250, 450, 450, 400, 450, 400, 1300, 450, 
          400, 450, 450, 400, 450, 400, 450, 400, 450, 450, 1250, 450, 1300, 400, 450, 450,
          1250, 450, 1300, 400, 450, 450, 400, 450, 1300, 400, 1300, 400, 1300, 450, 1300, 400,
          1300, 450, 1300, 400, 450, 400, 450, 400, };
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  } else if ( command == LIGHT_UP) {   //  LIGHT UP signal
    Serial.println("LIGHT UP");
    unsigned int irSignal[83] = {3400, 1750, 450, 400, 450, 400, 450, 1300, 400, 1300, 450, 
          400, 450, 1300, 400, 450, 400, 450, 450, 400, 450, 1300, 400, 450, 400, 450, 400,
          1300, 450, 400, 450, 1300, 400, 450, 450, 1250, 450, 450, 400, 450, 400, 1300, 450, 
          400, 450, 450, 400, 450, 400, 450, 400, 450, 450, 1250, 450, 450, 400, 450, 400, 1300, 
          450, 1300, 400, 450, 400, 450, 450, 1250, 450, 1300, 400, 450, 450, 1250, 450, 1300,
          400, 1300, 450, 400, 450, 450, 400, };
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  } else if ( command == LIGHT_DOWN) {   //  LIGHT DOWN signal
    Serial.println("LIGHT DOWN");
    unsigned int irSignal[83] = {3400, 1800, 350, 450, 400, 450, 400, 1350, 400, 1350, 350,
          450, 400, 1350, 400, 450, 400, 450, 400, 450, 400, 1350, 400, 450, 400, 450, 450, 1250,
          400, 500, 400, 1350, 350, 450, 400, 1350, 400, 450, 400, 450, 400, 1350, 350, 500, 400,
          450, 400, 450, 400, 450, 400, 1350, 400, 1300, 400, 450, 400, 450, 400, 1350, 400, 1350,
          350, 450, 400, 450, 400, 500, 400, 1300, 400, 450, 400, 1350, 400, 1300, 400, 1350, 350, 
          500, 400, 450, 400, };
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  // restart MsTimer2 because  when send IR signal MsTimer2 ends
  //  MsTimer2::set(MsTimer2_set_time, flash);  // call flash() every set time
  //  MsTimer2::start();                        // enables the interrupt
}

void setup() {          // Pin3 is for IR signal
  Serial.begin(9600);

  pinMode(13, OUTPUT);
  pinMode(LED_1, OUTPUT);
  pinMode(LED_2, OUTPUT);
  pinMode(LED_3, OUTPUT);
  pinMode(ON_button, INPUT_PULLUP);
  pinMode(OFF_button, INPUT_PULLUP);
  pinMode(FULL_ON_button, INPUT_PULLUP);
  pinMode(LIGHT_UP_button, INPUT_PULLUP);
  pinMode(LIGHT_DOWN_button, INPUT_PULLUP);
  pinMode(NIGHT_LIGHT_button, INPUT_PULLUP);
  pinMode(TIMER_button, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(TIMER_button) == LOW) {  // switch on is LOW, because input is pullup.
    Serial.println("TIMER_button");
    send_signal(ON);          // light on
    digitalWrite(LED_2, HIGH);
    digitalWrite(LED_3, HIGH);
    Serial.println("1st loop: ");
    for (int i = 1; i <= loop_count; i++) {  // blink for 10min(600sec)
      Serial.print(i); Serial.print(" ");
      if (i % 10 == 0) {
        Serial.println("");
      }
      digitalWrite(LED_1, HIGH);
      delay(1000);
      digitalWrite(LED_1, LOW);
      delay(1000);
    }
    digitalWrite(LED_1, LOW);   // output pin13(LED) (HIGH>ON LOW>OFF)
    Serial.println("2nd loop: ");
    for (int i = 1; i <= loop_count; i++) {  // blink for 10min(600sec)
      Serial.print(i); Serial.print(" ");
      if (i % 10 == 0) {
        Serial.println("");
      }
      digitalWrite(LED_2, HIGH);
      delay(1000);
      digitalWrite(LED_2, LOW);
      delay(1000);
    }
    digitalWrite(LED_2, LOW);   // output pin13(LED) (HIGH>ON LOW>OFF)
    Serial.println("3rd loop: ");
    for (int i = 1; i <= loop_count; i++) {  // blink for 10min(600sec)
      Serial.print(i); Serial.print(" ");
      if (i % 10 == 0) {
        Serial.println("");
      }
      digitalWrite(LED_3, HIGH);
      delay(1000);
      digitalWrite(LED_3, LOW);
      delay(1000);
    }
    digitalWrite(LED_3, LOW);
    send_signal(OFF);          // light off
  }

  if (digitalRead(ON_button) == LOW) {  // switch on is LOW, because input is pullup.
    send_signal(ON);          // light on
    digitalWrite(13, HIGH);
  }
  if (digitalRead(OFF_button) == LOW) {
    send_signal(OFF);         // light off
    digitalWrite(13, LOW);
  }
  if (digitalRead(FULL_ON_button) == LOW) {
    send_signal(FULL_ON);     // light on full
    digitalWrite(13, HIGH);
  }
  if (digitalRead(NIGHT_LIGHT_button) == LOW) {
    send_signal(NIGHT_LIGHT); // set night light
    digitalWrite(13, LOW);
  }
  if (digitalRead(LIGHT_UP_button) == LOW) {
    send_signal(LIGHT_UP);    // light up
    digitalWrite(13, HIGH);
  }
  if (digitalRead(LIGHT_DOWN_button) == LOW) {
    send_signal(LIGHT_DOWN);  // light doun
    digitalWrite(13, LOW);
  }
  delay(100);
}