danaweiss17
Published

IR Remote control LED countdown timer

Start the LED counter with the remote control for a 60 or 90 second countdown. The timer will beep to start and beep at the designated time.

IntermediateFull instructions provided1,215
IR Remote control LED countdown timer

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Speaker: 3W, 4 ohms
Speaker: 3W, 4 ohms
×1
IR receiver (generic)
×1
SparkFun 7-Segment Serial Display - Red
SparkFun 7-Segment Serial Display - Red
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
Resistor 220 ohm
Resistor 220 ohm
×2

Story

Read more

Schematics

IR Remote Timer

It is an adjustable IR Remote Timer.

Code

KungFuTimerNEC.ino

C/C++
/*
  Kung Fu Timer 2021
*/
#define NEC 1
//#define SONY 2
#include <IRLibAll.h>
#include <Wire.h>
#include <pitches.h>
#include <Adafruit_LEDBackpack.h>


// I2C address of the display.  Stick with the default address of 0x70
// unless you've changed the address jumpers on the back of the display.
#define DISPLAY_ADDRESS 0x70

// Define sensor pin
IRrecv myReceiver(5);//create the receiver, use pin 5.


#include <IRLib_P01_NEC.h>
IRdecode myDecoder;

// Define LED pin constants
const int LEDRED = 4;
const int LEDYEL = 7;
const int LEDGRN = 8;


//define musical tone
#define NOTE_C 262 //Hz

//Create display objects.  These are global variables that
//can be accessed from both the setup and loop function below.
Adafruit_7segment matrix = Adafruit_7segment();

//Set up buzzer
const int BUZZER_PIN = 12;

// Remember if the colon was drawn on the display so it can be blinked
// on and off every second.
bool blinkColon = false;

//declare tot_Time
int tot_Time = 60;

int seconds;
int now;

void setup()
{

  // Enable the IR Receiver
  myReceiver.enableIRIn();//start receiving

  // Set LED pins as Outputs
  pinMode(LEDRED, OUTPUT);
  pinMode(LEDYEL, OUTPUT);
  pinMode(LEDGRN, OUTPUT);

  pinMode(BUZZER_PIN, OUTPUT);

  //Setup Serial port
  Serial.begin(115200);
  matrix.begin(0x70);

  Serial.println("IR Remote Timer Adjustable");

}




void countDown()
{

  //turn off LEDs
  digitalWrite(LEDGRN, LOW);
  digitalWrite(LEDRED, LOW);
  digitalWrite(LEDYEL, LOW);

  tone(BUZZER_PIN, 262, 2000);
  digitalWrite(LEDGRN, HIGH);
  noTone(BUZZER_PIN);

  int now = tot_Time;
  matrix.print(now);
  matrix.writeDisplay();

  for (int i = 1; i <=  tot_Time; i++)
  {
    int now = tot_Time - i;
    int displayValue = now;
    Serial.print("Seconds = ");
    Serial.println(now);

    //Write to 7 segment display
    matrix.print(now);
    matrix.writeDisplay();
    delay(1000);

    //Control LEDs
    if (now <= 5 && now >= 2)
      digitalWrite(LEDYEL, HIGH);
    else
      digitalWrite(LEDYEL, LOW);

    if (now <= 90 && now >= 5)
      digitalWrite(LEDGRN, HIGH);
    else
      digitalWrite(LEDGRN, LOW);

    if (now <= 2 && now >= 1)
      digitalWrite (LEDRED, HIGH);
    else
      digitalWrite (LEDRED, LOW);


    //Sound buzzer if now = 1;
    if (now == 1)
    {

      tone(BUZZER_PIN, 262, 1000);
      digitalWrite(LEDRED, HIGH);
      delay(2000);
      noTone(BUZZER_PIN);

    }
    else
      noTone(BUZZER_PIN);

  }

  delay(1000);


  Serial.print("tot_Time = ");
  Serial.println(tot_Time);

}


void loop()
{

  if (myReceiver.getResults()) {
    //Continue looping until it returns true
    myDecoder.decode();// decode it
    myDecoder.dumpResults(false);//now print results


    switch (myDecoder.value)

      //NEC 1

    case 0xFFE21D: //lft
    { myReceiver.disableIRIn();      //stop receiver
      tot_Time = 90;
      matrix.writeDisplay();
      matrix.print(90);
      // Turn on LED
      digitalWrite(LEDRED, HIGH);
      digitalWrite(LEDGRN, LOW);
      digitalWrite(LEDYEL, LOW);
      Serial.println("case 0xFFE21D");

      break;



    case 0xFF02FD: //#Rt
      // Turn on LED
      myReceiver.disableIRIn();      //stop receiver
      tot_Time = 60;
      matrix.writeDisplay();
      matrix.print(60);
      digitalWrite(LEDYEL, HIGH);
      digitalWrite(LEDRED, LOW);
      digitalWrite(LEDGRN, LOW);

      Serial.println("case 0xFF02FD");
      break;


    case 0xFF609F: //up
      // Turn on LED
      myReceiver.disableIRIn();      //stop receiver

      Serial.println("case FF609F");
      digitalWrite(LEDGRN, HIGH);
      digitalWrite(LEDYEL, LOW);
      digitalWrite(LEDRED, LOW);
      delay(500);
      for (int k = 0; k < 4; k++)
      {
        digitalWrite(LEDGRN, LOW);
        delay(500);
        digitalWrite(LEDGRN, HIGH);
        delay(500);
      }

      digitalWrite(LEDGRN, HIGH);


      tone(BUZZER_PIN, 262, 1000);
      delay(2000);
      noTone(BUZZER_PIN);
      digitalWrite(LEDGRN, LOW);
      countDown();
      break;

    }

  }
  myReceiver.enableIRIn(); //restart the receiver
}

Credits

danaweiss17
2 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.