Devices & Components
Breadboard - 840 contacts
Arduino Uno Rev3
7 segment Display (common cathode )
jumpers
variable resister
555 Timers
and gate
4026B Decade Counter
Potentiometer, 10k Ohms
Diode
22 gauge solid core wire
Capacitor 4.7 µF
Software & Tools
Arduino IDE
Project description
Code
Coe for timer
cpp
1#include <IRremote.hpp> // Include the IRremote library to work with IR remotes (modern version uses .hpp) 2 3// Define the pin where the IR receiver is connected 4#define IR_RECEIVE_PIN 5 5 6// Define the button codes you expect from your remote 7// These codes depend on the specific remote you're using 8#define IR_BUTTON_ON_OF 69 9#define IR_BUTTON_0 22 10#define IR_PAUSE_UNPAUSED 64 11#define SET_MINUTES 9 12#define SET_HOURS 7 13 14#define POWER_PIN 11 15#define PAUSE_UNPAUSED_PIN 12 16#define REST_PIN 8 17#define SET_MINUTES_PIN 3 18#define SET_HOURS_PIN 7 19 20 21void setup() { 22 Serial.begin(115200); 23 IrReceiver.begin(IR_RECEIVE_PIN); // Start the IR receiver on the defined pin 24 25 pinMode(POWER_PIN, OUTPUT); 26 pinMode(PAUSE_UNPAUSED_PIN, OUTPUT); 27 pinMode(REST_PIN, OUTPUT); 28 pinMode(SET_MINUTES_PIN, OUTPUT); 29 pinMode(SET_HOURS_PIN, OUTPUT); 30 31 pinMode(IR_RECEIVE_PIN, INPUT); 32 33 digitalWrite(POWER_PIN, 0); 34 digitalWrite(PAUSE_UNPAUSED_PIN, 0); 35 digitalWrite(REST_PIN, 0); 36 digitalWrite(SET_MINUTES_PIN, 0); 37 digitalWrite(SET_HOURS_PIN, 0); 38} 39 40unsigned int on_off = 0; 41unsigned int paused_unpaused = 0; 42 43 44void loop() { 45 // Check if a signal was received from the remote 46 if (IrReceiver.decode()) { 47 delay(100); 48 49 50 51 // Read the command (button code) that was received 52 unsigned long value = IrReceiver.decodedIRData.command; 53 54 55 56 // Check which button was pressed and print a message 57 if (value == IR_BUTTON_ON_OF) { 58 59 Serial.println("Button BUTTON_ON_OF pressed"); 60 61 62 if (on_off == 0) { 63 digitalWrite(POWER_PIN, 1); 64 digitalWrite(REST_PIN, 1); 65 digitalWrite(PAUSE_UNPAUSED_PIN, 1); 66 on_off = 1; 67 } 68 else { 69 digitalWrite(POWER_PIN, 0); 70 digitalWrite(REST_PIN, 0); 71 digitalWrite(PAUSE_UNPAUSED_PIN, 0); 72 on_off = 0; 73 } 74 75 } 76 else if(value == IR_PAUSE_UNPAUSED) { 77 Serial.println("Button PAUSE_UNPAUSED pressed"); 78 79 if (paused_unpaused == 1) { 80 81 digitalWrite(PAUSE_UNPAUSED_PIN, 1); 82 digitalWrite(REST_PIN, 0); 83 paused_unpaused = 0; 84 } 85 else { 86 digitalWrite(REST_PIN, 0); 87 digitalWrite(PAUSE_UNPAUSED_PIN, 0); 88 paused_unpaused = 1; 89 90 } 91 92 93 } 94 else if(value == IR_BUTTON_0) { 95 Serial.println("Button 0 pressed"); 96 digitalWrite(PAUSE_UNPAUSED_PIN, 1); 97 digitalWrite(REST_PIN, 1); 98 paused_unpaused = 0; 99 100 } 101 else if(value == SET_MINUTES){ 102 Serial.println("Button SET_MINUTES pressed"); 103 104 for(int i = 0; i < 5; i++){ 105 106 digitalWrite(SET_MINUTES_PIN, 0); 107 digitalWrite(SET_MINUTES_PIN, 1); 108 } 109 digitalWrite(SET_MINUTES_PIN, 0); 110 111 } 112 113 else if(value == SET_HOURS){ 114 Serial.println("Button SET_HOURS pressed"); 115 for(int i = 0; i < 60; i++){ 116 117 digitalWrite(SET_MINUTES_PIN, 0); 118 digitalWrite(SET_MINUTES_PIN, 1); 119 } 120 digitalWrite(SET_MINUTES_PIN, 0); 121 } 122 123 else { 124 // If it's a button you didn't define, print its code in HEX format 125 Serial.print("Unknown button: "); 126 Serial.println(value, HEX); 127 } 128 129 // Tell the IR receiver to get ready for the next signal 130 IrReceiver.resume(); 131 } 132}
Comments
Only logged in users can leave comments