stevie135s
Created September 25, 2022 © GPL3+

Hourly Timer With IR Control

An hourly timer relay controlled by almost any infra red keypad.

BeginnerProtip87
Hourly Timer With IR Control

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
5 Volt Relay
×1
KY-022 IR Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

IR control relay

The wiring diagram

Code

IR control relay

Arduino
Arduino code
Edit with your own keycodes
/* Programmed using the Arduino Nano
 *  Edit the Key codes using the
 *  Serial Monitor
 */





#include <IRremote.h>

#define TIMER_INTERRUPT_DEBUG 0
#define _TIMERINTERRUPT_LOGLEVEL_ 0
#define USE_TIMER_1     true
//#define LED_BUILTIN 13

#include <TimerInterrupt.h>

const int IR_Pin = 3;
const int Buzz_Pin = 4;
bool timer_1 = LOW;    //Timer 1 State
static int relay = 2;  //Relay Pin
bool flash_led = LOW;  //BuitIN Led State
volatile int dwel = -1; //Countdown Timer :: -1 OFF, 0 SWITCH RELAY
unsigned long Press; 
byte Buzz = 100;


void TimerHandler1(void) {
  if (dwel > 0) {
    dwel--;
  }
  digitalWrite(LED_BUILTIN,flash_led);
  flash_led = !flash_led;
}



void setup() {
  pinMode (relay,OUTPUT);
  pinMode (Buzz_Pin,OUTPUT);
  digitalWrite(relay,timer_1);
  digitalWrite(Buzz_Pin, LOW);
  
//  Serial.begin(115200);     *** Enable to see the Key Codes on the serial monitor
  IrReceiver.begin(IR_Pin);
  
  ITimer1.init();
  ITimer1.attachInterruptInterval(1000,TimerHandler1);

}

void loop() {
  if (dwel == 0) {
    dwel--;
    timer_1 = !timer_1;
    digitalWrite(relay,timer_1);
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    delay(Buzz);
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    delay(Buzz);
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
  }

  if (IrReceiver.decode()) {
//    Serial.print("Code: ");
    Press = (IrReceiver.decodedIRData.decodedRawData);
    Key_Press();
//    Serial.println(Press); *** Enable to see the Key Codes on the serial monitor
    IrReceiver.resume();
  }
  
}

void Key_Press() {
  switch (Press) {
    
    case 3125149440 :  // ON/OFF
    timer_1 = !timer_1;
    digitalWrite(relay,timer_1);
    dwel = -1;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    delay(Buzz);
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;

    case 4061003520 : // 0
    dwel = 0;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    delay(Buzz);
    timer_1 = !timer_1;  //dummy .. to keep relay state the same
    break;

    case 4077715200 : // 1
    dwel = 3600;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;

    case 3877175054 : // 2
    dwel = 7200;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;

    case 2707357440 : //3
    dwel = 10800;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);    
    break;

    case 4144561920 : //4
    dwel = 14400;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;

    case 3810328320 : //5
    dwel = 18000;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;

    case 2774204160 : //6
    dwel = 21600;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;

    case 3175284480 : //7
    dwel = 25200;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;

    case 2907897600 : //8
    dwel = 28800;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;

    case 3041591040 : //9
    dwel = 32400;
    digitalWrite(Buzz_Pin, HIGH);
    delay(Buzz);
    digitalWrite(Buzz_Pin, LOW);
    break;
  }
}

Credits

stevie135s
28 projects • 12 followers
I've been interested in microprocessors for a long time.
Contact

Comments

Please log in or sign up to comment.