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.
Components and supplies
1
5 mm LED: Yellow
2
Resistor 220 ohm
1
5 mm LED: Red
1
Arduino Mega 2560
1
5 mm LED: Green
1
SparkFun 7-Segment Serial Display - Red
1
IR receiver (generic)
1
Speaker: 3W, 4 ohms
Project description
Code
KungFuTimerNEC.ino
c_cpp
1/* 2 Kung Fu Timer 2021 3*/ 4#define NEC 1 5//#define SONY 2 6#include <IRLibAll.h> 7#include <Wire.h> 8#include <pitches.h> 9#include <Adafruit_LEDBackpack.h> 10 11 12// I2C address of the display. Stick with the default address of 0x70 13// unless you've changed the address jumpers on the back of the display. 14#define DISPLAY_ADDRESS 0x70 15 16// Define sensor pin 17IRrecv myReceiver(5);//create the receiver, use pin 5. 18 19 20#include <IRLib_P01_NEC.h> 21IRdecode myDecoder; 22 23// Define LED pin constants 24const int LEDRED = 4; 25const int LEDYEL = 7; 26const int LEDGRN = 8; 27 28 29//define musical tone 30#define NOTE_C 262 //Hz 31 32//Create display objects. These are global variables that 33//can be accessed from both the setup and loop function below. 34Adafruit_7segment matrix = Adafruit_7segment(); 35 36//Set up buzzer 37const int BUZZER_PIN = 12; 38 39// Remember if the colon was drawn on the display so it can be blinked 40// on and off every second. 41bool blinkColon = false; 42 43//declare tot_Time 44int tot_Time = 60; 45 46int seconds; 47int now; 48 49void setup() 50{ 51 52 // Enable the IR Receiver 53 myReceiver.enableIRIn();//start receiving 54 55 // Set LED pins as Outputs 56 pinMode(LEDRED, OUTPUT); 57 pinMode(LEDYEL, OUTPUT); 58 pinMode(LEDGRN, OUTPUT); 59 60 pinMode(BUZZER_PIN, OUTPUT); 61 62 //Setup Serial port 63 Serial.begin(115200); 64 matrix.begin(0x70); 65 66 Serial.println("IR Remote Timer Adjustable"); 67 68} 69 70 71 72 73void countDown() 74{ 75 76 //turn off LEDs 77 digitalWrite(LEDGRN, LOW); 78 digitalWrite(LEDRED, LOW); 79 digitalWrite(LEDYEL, LOW); 80 81 tone(BUZZER_PIN, 262, 2000); 82 digitalWrite(LEDGRN, HIGH); 83 noTone(BUZZER_PIN); 84 85 int now = tot_Time; 86 matrix.print(now); 87 matrix.writeDisplay(); 88 89 for (int i = 1; i <= tot_Time; i++) 90 { 91 int now = tot_Time - i; 92 int displayValue = now; 93 Serial.print("Seconds = "); 94 Serial.println(now); 95 96 //Write to 7 segment display 97 matrix.print(now); 98 matrix.writeDisplay(); 99 delay(1000); 100 101 //Control LEDs 102 if (now <= 5 && now >= 2) 103 digitalWrite(LEDYEL, HIGH); 104 else 105 digitalWrite(LEDYEL, LOW); 106 107 if (now <= 90 && now >= 5) 108 digitalWrite(LEDGRN, HIGH); 109 else 110 digitalWrite(LEDGRN, LOW); 111 112 if (now <= 2 && now >= 1) 113 digitalWrite (LEDRED, HIGH); 114 else 115 digitalWrite (LEDRED, LOW); 116 117 118 //Sound buzzer if now = 1; 119 if (now == 1) 120 { 121 122 tone(BUZZER_PIN, 262, 1000); 123 digitalWrite(LEDRED, HIGH); 124 delay(2000); 125 noTone(BUZZER_PIN); 126 127 } 128 else 129 noTone(BUZZER_PIN); 130 131 } 132 133 delay(1000); 134 135 136 Serial.print("tot_Time = "); 137 Serial.println(tot_Time); 138 139} 140 141 142void loop() 143{ 144 145 if (myReceiver.getResults()) { 146 //Continue looping until it returns true 147 myDecoder.decode();// decode it 148 myDecoder.dumpResults(false);//now print results 149 150 151 switch (myDecoder.value) 152 153 //NEC 1 154 155 case 0xFFE21D: //lft 156 { myReceiver.disableIRIn(); //stop receiver 157 tot_Time = 90; 158 matrix.writeDisplay(); 159 matrix.print(90); 160 // Turn on LED 161 digitalWrite(LEDRED, HIGH); 162 digitalWrite(LEDGRN, LOW); 163 digitalWrite(LEDYEL, LOW); 164 Serial.println("case 0xFFE21D"); 165 166 break; 167 168 169 170 case 0xFF02FD: //#Rt 171 // Turn on LED 172 myReceiver.disableIRIn(); //stop receiver 173 tot_Time = 60; 174 matrix.writeDisplay(); 175 matrix.print(60); 176 digitalWrite(LEDYEL, HIGH); 177 digitalWrite(LEDRED, LOW); 178 digitalWrite(LEDGRN, LOW); 179 180 Serial.println("case 0xFF02FD"); 181 break; 182 183 184 case 0xFF609F: //up 185 // Turn on LED 186 myReceiver.disableIRIn(); //stop receiver 187 188 Serial.println("case FF609F"); 189 digitalWrite(LEDGRN, HIGH); 190 digitalWrite(LEDYEL, LOW); 191 digitalWrite(LEDRED, LOW); 192 delay(500); 193 for (int k = 0; k < 4; k++) 194 { 195 digitalWrite(LEDGRN, LOW); 196 delay(500); 197 digitalWrite(LEDGRN, HIGH); 198 delay(500); 199 } 200 201 digitalWrite(LEDGRN, HIGH); 202 203 204 tone(BUZZER_PIN, 262, 1000); 205 delay(2000); 206 noTone(BUZZER_PIN); 207 digitalWrite(LEDGRN, LOW); 208 countDown(); 209 break; 210 211 } 212 213 } 214 myReceiver.enableIRIn(); //restart the receiver 215} 216
KungFuTimerNEC.ino
c_cpp
1/* 2 Kung Fu Timer 2021 3*/ 4#define NEC 1 5//#define SONY 2 6#include <IRLibAll.h> 7#include <Wire.h> 8#include <pitches.h> 9#include <Adafruit_LEDBackpack.h> 10 11 12// I2C address of the display. Stick with the default address of 0x70 13// unless you've changed the address jumpers on the back of the display. 14#define DISPLAY_ADDRESS 0x70 15 16// Define sensor pin 17IRrecv myReceiver(5);//create the receiver, use pin 5. 18 19 20#include <IRLib_P01_NEC.h> 21IRdecode myDecoder; 22 23// Define LED pin constants 24const int LEDRED = 4; 25const int LEDYEL = 7; 26const int LEDGRN = 8; 27 28 29//define musical tone 30#define NOTE_C 262 //Hz 31 32//Create display objects. These are global variables that 33//can be accessed from both the setup and loop function below. 34Adafruit_7segment matrix = Adafruit_7segment(); 35 36//Set up buzzer 37const int BUZZER_PIN = 12; 38 39// Remember if the colon was drawn on the display so it can be blinked 40// on and off every second. 41bool blinkColon = false; 42 43//declare tot_Time 44int tot_Time = 60; 45 46int seconds; 47int now; 48 49void setup() 50{ 51 52 // Enable the IR Receiver 53 myReceiver.enableIRIn();//start receiving 54 55 // Set LED pins as Outputs 56 pinMode(LEDRED, OUTPUT); 57 pinMode(LEDYEL, OUTPUT); 58 pinMode(LEDGRN, OUTPUT); 59 60 pinMode(BUZZER_PIN, OUTPUT); 61 62 //Setup Serial port 63 Serial.begin(115200); 64 matrix.begin(0x70); 65 66 Serial.println("IR Remote Timer Adjustable"); 67 68} 69 70 71 72 73void countDown() 74{ 75 76 //turn off LEDs 77 digitalWrite(LEDGRN, LOW); 78 digitalWrite(LEDRED, LOW); 79 digitalWrite(LEDYEL, LOW); 80 81 tone(BUZZER_PIN, 262, 2000); 82 digitalWrite(LEDGRN, HIGH); 83 noTone(BUZZER_PIN); 84 85 int now = tot_Time; 86 matrix.print(now); 87 matrix.writeDisplay(); 88 89 for (int i = 1; i <= tot_Time; i++) 90 { 91 int now = tot_Time - i; 92 int displayValue = now; 93 Serial.print("Seconds = "); 94 Serial.println(now); 95 96 //Write to 7 segment display 97 matrix.print(now); 98 matrix.writeDisplay(); 99 delay(1000); 100 101 //Control LEDs 102 if (now <= 5 && now >= 2) 103 digitalWrite(LEDYEL, HIGH); 104 else 105 digitalWrite(LEDYEL, LOW); 106 107 if (now <= 90 && now >= 5) 108 digitalWrite(LEDGRN, HIGH); 109 else 110 digitalWrite(LEDGRN, LOW); 111 112 if (now <= 2 && now >= 1) 113 digitalWrite (LEDRED, HIGH); 114 else 115 digitalWrite (LEDRED, LOW); 116 117 118 //Sound buzzer if now = 1; 119 if (now == 1) 120 { 121 122 tone(BUZZER_PIN, 262, 1000); 123 digitalWrite(LEDRED, HIGH); 124 delay(2000); 125 noTone(BUZZER_PIN); 126 127 } 128 else 129 noTone(BUZZER_PIN); 130 131 } 132 133 delay(1000); 134 135 136 Serial.print("tot_Time = "); 137 Serial.println(tot_Time); 138 139} 140 141 142void loop() 143{ 144 145 if (myReceiver.getResults()) { 146 //Continue looping until it returns true 147 myDecoder.decode();// decode it 148 myDecoder.dumpResults(false);//now print results 149 150 151 switch (myDecoder.value) 152 153 //NEC 1 154 155 case 0xFFE21D: //lft 156 { myReceiver.disableIRIn(); //stop receiver 157 tot_Time = 90; 158 matrix.writeDisplay(); 159 matrix.print(90); 160 // Turn on LED 161 digitalWrite(LEDRED, HIGH); 162 digitalWrite(LEDGRN, LOW); 163 digitalWrite(LEDYEL, LOW); 164 Serial.println("case 0xFFE21D"); 165 166 break; 167 168 169 170 case 0xFF02FD: //#Rt 171 // Turn on LED 172 myReceiver.disableIRIn(); //stop receiver 173 tot_Time = 60; 174 matrix.writeDisplay(); 175 matrix.print(60); 176 digitalWrite(LEDYEL, HIGH); 177 digitalWrite(LEDRED, LOW); 178 digitalWrite(LEDGRN, LOW); 179 180 Serial.println("case 0xFF02FD"); 181 break; 182 183 184 case 0xFF609F: //up 185 // Turn on LED 186 myReceiver.disableIRIn(); //stop receiver 187 188 Serial.println("case FF609F"); 189 digitalWrite(LEDGRN, HIGH); 190 digitalWrite(LEDYEL, LOW); 191 digitalWrite(LEDRED, LOW); 192 delay(500); 193 for (int k = 0; k < 4; k++) 194 { 195 digitalWrite(LEDGRN, LOW); 196 delay(500); 197 digitalWrite(LEDGRN, HIGH); 198 delay(500); 199 } 200 201 digitalWrite(LEDGRN, HIGH); 202 203 204 tone(BUZZER_PIN, 262, 1000); 205 delay(2000); 206 noTone(BUZZER_PIN); 207 digitalWrite(LEDGRN, LOW); 208 countDown(); 209 break; 210 211 } 212 213 } 214 myReceiver.enableIRIn(); //restart the receiver 215} 216
Downloadable files
IR Remote Timer
It is an adjustable IR Remote Timer.
IR Remote Timer
Comments
Only logged in users can leave comments