Components and supplies
M3 nut
Through Hole Resistor, 47 ohm
9V to Barrel Jack Connector
Machine Screw, M2.5
PCB push button
IR transmitter (generic)
Machine Screw, M3
Male-Header 36 Position 1 Row- Long (0.1")
9V battery (generic)
Prototyping board, 2.54 mm
M2.5 nut
Arduino UNO
Tools and machines
3D Printer (generic)
PLA filament, diameter 1.75 mm
Soldering iron (generic)
Solder Wire, Lead Free
Project description
Code
TV_remote.ino
arduino
1#include <IRremote.h> 2#include <avr/sleep.h> 3#include <avr/power.h> 4// Pin definition 5// An IR LED must be connected to Arduino PWM pin 3 6#define OnOff 1 7#define Source 0 8#define CH_plus 4 9#define CH_minus 5 10#define Vol_plus 6 11#define Vol_minus 7 12#define Interrupt_Pin 2 //Only pin 2 or 3 on Arduino Uno 13// TV model definition 14//#define LG_TV 15//#define SAMSUNG_TV 16#define SONY_TV 17// Codes definition 18#ifdef LG_TV 19 unsigned long on_off_code = 551489775; // HEX 20DF10EF 20 unsigned long vol_plus_code = 551502015; //HEX 20DF40BF 21 unsigned long vol_minus_code = 551534655; //HEX 20DFC03F 22 unsigned long ch_plus_code = 551485695; //HEX 20DF00FF 23 unsigned long ch_minus_code = 551518335; //HEX 20DF807F 24 unsigned long source_code = 551538735; //HEX 20DFD02F 25#endif 26#ifdef SAMSUNG_TV 27 unsigned long on_off_code = 3772793023; // HEX E0E040BF 28 unsigned long vol_plus_code = 3772833823; //HEX E0E0E01F 29 unsigned long vol_minus_code = 3772829743; //HEX E0E0D02F 30 unsigned long ch_plus_code = 3772795063; //HEX E0E048B7 31 unsigned long ch_minus_code = 3772778743; //HEX E0E008F7 32 unsigned long source_code = 3772809343; //HEX E0E0807F 33#endif 34#ifdef SONY_TV 35 unsigned long on_off_code = 2704; //HEX A90 36 unsigned long vol_plus_code = 1168; //HEX 490 37 unsigned long vol_minus_code = 3216; //HEX C90 38 unsigned long ch_plus_code = 144; //HEX 090 39 unsigned long ch_minus_code = 2192; //HEX 890 40 unsigned long source_code = 2640; //HEX A50 41#endif 42//Enable Debug 43//#define DEBUG 44// 45IRsend irsend; //Create IR object 46unsigned long debounce_time; 47unsigned long last_time; 48 49void setup() { 50 analogWrite(13,0); //turn of builtin led 51 //noInterrupts(); //disable interrupts 52 //CLKPR = _BV(CLKPCE); //enable clock prescaler settings 53 //CLKPR = _BV(CLKPS0); //set clock prescaler = 2 --> 8 MHz 54 //interrupts(); 55 pinMode(OnOff,INPUT_PULLUP); 56 pinMode(Source,INPUT_PULLUP); 57 pinMode(CH_plus,INPUT_PULLUP); 58 pinMode(CH_minus,INPUT_PULLUP); 59 pinMode(Vol_plus,INPUT_PULLUP); 60 pinMode(Vol_minus,INPUT_PULLUP); 61 pinMode(Interrupt_Pin,INPUT_PULLUP); 62 //power saving 63 power_adc_disable(); //disable all ADCs 64 power_spi_disable(); //disable SPI 65 power_timer1_disable(); //disbale timer 1 (0 is for millis(), 2 is for irremote.h) 66 power_usart0_disable(); //disable serial 67 power_twi_disable(); //disable TWI 68 #ifdef DEBUG 69 Serial.begin(9600); 70 #endif 71} 72 73void loop() { 74 //check OnOff 75 if (!digitalRead(OnOff)) { 76 debounce_time = millis(); 77 while (millis() - debounce_time < 40 ) { 78 ; 79 } 80 if (!digitalRead(OnOff)) { 81 #ifdef LG_TV 82 irsend.sendNEC(on_off_code, 32); 83 #endif 84 #ifdef SAMSUNG_TV 85 irsend.sendSAMSUNG(on_off_code, 32); 86 #endif 87 #ifdef SONY_TV 88 irsend.sendSony(on_off_code, 12); 89 #endif 90 last_time = millis(); //last time a button was pressed 91 #ifdef DEBUG 92 Serial.println("OnOff"); 93 #endif 94 } 95 } 96 //check Source 97 if (!digitalRead(Source)) { 98 debounce_time = millis(); 99 while (millis() - debounce_time < 40 ) { 100 ; 101 } 102 if (!digitalRead(Source)) { 103 #ifdef LG_TV 104 irsend.sendNEC(source_code, 32); 105 #endif 106 #ifdef SAMSUNG_TV 107 irsend.sendSAMSUNG(source_code, 32); 108 #endif 109 #ifdef SONY_TV 110 irsend.sendSony(source_code, 12); 111 #endif 112 last_time = millis(); //last time a button was pressed 113 #ifdef DEBUG 114 Serial.println("Source"); 115 #endif 116 } 117 } 118 //check CH_plus 119 if (!digitalRead(CH_plus)) { 120 debounce_time = millis(); 121 while (millis() - debounce_time < 40 ) { 122 ; 123 } 124 if (!digitalRead(CH_plus)) { 125 #ifdef LG_TV 126 irsend.sendNEC(ch_plus_code, 32); 127 #endif 128 #ifdef SAMSUNG_TV 129 irsend.sendSAMSUNG(ch_plus_code, 32); 130 #endif 131 #ifdef SONY_TV 132 irsend.sendSony(ch_plus_code, 12); 133 #endif 134 last_time = millis(); //last time a button was pressed 135 #ifdef DEBUG 136 Serial.println("CH+"); 137 #endif 138 } 139 } 140 //check CH_minus 141 if (!digitalRead(CH_minus)) { 142 debounce_time = millis(); 143 while (millis() - debounce_time < 40 ) { 144 ; 145 } 146 if (!digitalRead(CH_minus)) { 147 #ifdef LG_TV 148 irsend.sendNEC(ch_minus_code, 32); 149 #endif 150 #ifdef SAMSUNG_TV 151 irsend.sendSAMSUNG(ch_minus_code, 32); 152 #endif 153 #ifdef SONY_TV 154 irsend.sendSony(ch_minus_code, 12); 155 #endif 156 last_time = millis(); //last time a button was pressed 157 #ifdef DEBUG 158 Serial.println("CH-"); 159 #endif 160 } 161 } 162 //check Vol_plus 163 if (!digitalRead(Vol_plus)) { 164 debounce_time = millis(); 165 while (millis() - debounce_time < 40 ) { 166 ; 167 } 168 if (!digitalRead(Vol_plus)) { 169 #ifdef LG_TV 170 irsend.sendNEC(vol_plus_code, 32); 171 #endif 172 #ifdef SAMSUNG_TV 173 irsend.sendSAMSUNG(vol_plus_code, 32); 174 #endif 175 #ifdef SONY_TV 176 irsend.sendSony(vol_plus_code, 12); 177 #endif 178 last_time = millis(); //last time a button was pressed 179 #ifdef DEBUG 180 Serial.println("Vol+"); 181 #endif 182 } 183 } 184 //check Vol_minus 185 if (!digitalRead(Vol_minus)) { 186 debounce_time = millis(); 187 while (millis() - debounce_time < 40 ) { 188 ; 189 } 190 if (!digitalRead(Vol_minus)) { 191 #ifdef LG_TV 192 irsend.sendNEC(vol_minus_code, 32); 193 #endif 194 #ifdef SAMSUNG_TV 195 irsend.sendSAMSUNG(vol_minus_code, 32); 196 #endif 197 #ifdef SONY_TV 198 irsend.sendSony(vol_minus_code, 12); 199 #endif 200 last_time = millis(); //last time a button was pressed 201 #ifdef DEBUG 202 Serial.println("Vol-"); 203 #endif 204 } 205 } 206 if (millis()-last_time > 5000) { //a button has not been pressed for 10 s 207 #ifdef DEBUG 208 Serial.println("Going to sleep..."); 209 #endif 210 going_to_sleep(); //enter sleep mode 211 #ifdef DEBUG 212 Serial.println("Waking up..."); 213 #endif 214 } 215} 216 217//Sleep Mode function 218void going_to_sleep() { 219 sleep_enable(); //enable sleep mode 220 attachInterrupt(digitalPinToInterrupt(Interrupt_Pin), wake_up, LOW); //interrupt for waking up --> configure Interrupt Pin as a WIRED NOR!!! 221 set_sleep_mode(SLEEP_MODE_PWR_DOWN); //full sleep mode 222 sleep_cpu(); //activate sleep mode 223} 224 225//Wake Up function 226void wake_up() { 227 sleep_disable(); //disable sleep mode 228 detachInterrupt(digitalPinToInterrupt(Interrupt_Pin)); //remove the interrupt 229} 230
TV_remote.ino
arduino
1#include <IRremote.h> 2#include <avr/sleep.h> 3#include <avr/power.h> 4// 5 Pin definition 6// An IR LED must be connected to Arduino PWM pin 3 7#define 8 OnOff 1 9#define Source 0 10#define CH_plus 4 11#define CH_minus 5 12#define 13 Vol_plus 6 14#define Vol_minus 7 15#define Interrupt_Pin 2 //Only pin 2 or 3 on 16 Arduino Uno 17// TV model definition 18//#define LG_TV 19//#define SAMSUNG_TV 20#define 21 SONY_TV 22// Codes definition 23#ifdef LG_TV 24 unsigned long on_off_code = 25 551489775; // HEX 20DF10EF 26 unsigned long vol_plus_code = 551502015; //HEX 20DF40BF 27 28 unsigned long vol_minus_code = 551534655; //HEX 20DFC03F 29 unsigned long ch_plus_code 30 = 551485695; //HEX 20DF00FF 31 unsigned long ch_minus_code = 551518335; //HEX 32 20DF807F 33 unsigned long source_code = 551538735; //HEX 20DFD02F 34#endif 35#ifdef 36 SAMSUNG_TV 37 unsigned long on_off_code = 3772793023; // HEX E0E040BF 38 unsigned 39 long vol_plus_code = 3772833823; //HEX E0E0E01F 40 unsigned long vol_minus_code 41 = 3772829743; //HEX E0E0D02F 42 unsigned long ch_plus_code = 3772795063; //HEX 43 E0E048B7 44 unsigned long ch_minus_code = 3772778743; //HEX E0E008F7 45 unsigned 46 long source_code = 3772809343; //HEX E0E0807F 47#endif 48#ifdef SONY_TV 49 unsigned 50 long on_off_code = 2704; //HEX A90 51 unsigned long vol_plus_code = 1168; //HEX 52 490 53 unsigned long vol_minus_code = 3216; //HEX C90 54 unsigned long ch_plus_code 55 = 144; //HEX 090 56 unsigned long ch_minus_code = 2192; //HEX 890 57 unsigned 58 long source_code = 2640; //HEX A50 59#endif 60//Enable Debug 61//#define DEBUG 62// 63IRsend 64 irsend; //Create IR object 65unsigned long debounce_time; 66unsigned long last_time; 67 68void 69 setup() { 70 analogWrite(13,0); //turn of builtin led 71 //noInterrupts(); //disable 72 interrupts 73 //CLKPR = _BV(CLKPCE); //enable clock prescaler settings 74 //CLKPR 75 = _BV(CLKPS0); //set clock prescaler = 2 --> 8 MHz 76 //interrupts(); 77 pinMode(OnOff,INPUT_PULLUP); 78 79 pinMode(Source,INPUT_PULLUP); 80 pinMode(CH_plus,INPUT_PULLUP); 81 pinMode(CH_minus,INPUT_PULLUP); 82 83 pinMode(Vol_plus,INPUT_PULLUP); 84 pinMode(Vol_minus,INPUT_PULLUP); 85 pinMode(Interrupt_Pin,INPUT_PULLUP); 86 87 //power saving 88 power_adc_disable(); //disable all ADCs 89 power_spi_disable(); 90 //disable SPI 91 power_timer1_disable(); //disbale timer 1 (0 is for millis(), 92 2 is for irremote.h) 93 power_usart0_disable(); //disable serial 94 power_twi_disable(); 95 //disable TWI 96 #ifdef DEBUG 97 Serial.begin(9600); 98 #endif 99} 100 101void 102 loop() { 103 //check OnOff 104 if (!digitalRead(OnOff)) { 105 debounce_time = millis(); 106 107 while (millis() - debounce_time < 40 ) { 108 ; 109 } 110 if (!digitalRead(OnOff)) 111 { 112 #ifdef LG_TV 113 irsend.sendNEC(on_off_code, 32); 114 #endif 115 116 #ifdef SAMSUNG_TV 117 irsend.sendSAMSUNG(on_off_code, 32); 118 #endif 119 120 #ifdef SONY_TV 121 irsend.sendSony(on_off_code, 12); 122 #endif 123 124 last_time = millis(); //last time a button was pressed 125 #ifdef DEBUG 126 127 Serial.println("OnOff"); 128 #endif 129 } 130 } 131 //check Source 132 133 if (!digitalRead(Source)) { 134 debounce_time = millis(); 135 while (millis() 136 - debounce_time < 40 ) { 137 ; 138 } 139 if (!digitalRead(Source)) { 140 #ifdef 141 LG_TV 142 irsend.sendNEC(source_code, 32); 143 #endif 144 #ifdef SAMSUNG_TV 145 146 irsend.sendSAMSUNG(source_code, 32); 147 #endif 148 #ifdef SONY_TV 149 150 irsend.sendSony(source_code, 12); 151 #endif 152 last_time = millis(); 153 //last time a button was pressed 154 #ifdef DEBUG 155 Serial.println("Source"); 156 157 #endif 158 } 159 } 160 //check CH_plus 161 if (!digitalRead(CH_plus)) { 162 163 debounce_time = millis(); 164 while (millis() - debounce_time < 40 ) { 165 ; 166 167 } 168 if (!digitalRead(CH_plus)) { 169 #ifdef LG_TV 170 irsend.sendNEC(ch_plus_code, 171 32); 172 #endif 173 #ifdef SAMSUNG_TV 174 irsend.sendSAMSUNG(ch_plus_code, 175 32); 176 #endif 177 #ifdef SONY_TV 178 irsend.sendSony(ch_plus_code, 179 12); 180 #endif 181 last_time = millis(); //last time a button was pressed 182 183 #ifdef DEBUG 184 Serial.println("CH+"); 185 #endif 186 } 187 } 188 189 //check CH_minus 190 if (!digitalRead(CH_minus)) { 191 debounce_time = millis(); 192 193 while (millis() - debounce_time < 40 ) { 194 ; 195 } 196 if (!digitalRead(CH_minus)) 197 { 198 #ifdef LG_TV 199 irsend.sendNEC(ch_minus_code, 32); 200 #endif 201 202 #ifdef SAMSUNG_TV 203 irsend.sendSAMSUNG(ch_minus_code, 32); 204 #endif 205 206 #ifdef SONY_TV 207 irsend.sendSony(ch_minus_code, 12); 208 #endif 209 210 last_time = millis(); //last time a button was pressed 211 #ifdef DEBUG 212 213 Serial.println("CH-"); 214 #endif 215 } 216 } 217 //check Vol_plus 218 219 if (!digitalRead(Vol_plus)) { 220 debounce_time = millis(); 221 while (millis() 222 - debounce_time < 40 ) { 223 ; 224 } 225 if (!digitalRead(Vol_plus)) { 226 227 #ifdef LG_TV 228 irsend.sendNEC(vol_plus_code, 32); 229 #endif 230 #ifdef 231 SAMSUNG_TV 232 irsend.sendSAMSUNG(vol_plus_code, 32); 233 #endif 234 #ifdef 235 SONY_TV 236 irsend.sendSony(vol_plus_code, 12); 237 #endif 238 last_time 239 = millis(); //last time a button was pressed 240 #ifdef DEBUG 241 Serial.println("Vol+"); 242 243 #endif 244 } 245 } 246 //check Vol_minus 247 if (!digitalRead(Vol_minus)) { 248 249 debounce_time = millis(); 250 while (millis() - debounce_time < 40 ) { 251 ; 252 253 } 254 if (!digitalRead(Vol_minus)) { 255 #ifdef LG_TV 256 irsend.sendNEC(vol_minus_code, 257 32); 258 #endif 259 #ifdef SAMSUNG_TV 260 irsend.sendSAMSUNG(vol_minus_code, 261 32); 262 #endif 263 #ifdef SONY_TV 264 irsend.sendSony(vol_minus_code, 265 12); 266 #endif 267 last_time = millis(); //last time a button was pressed 268 269 #ifdef DEBUG 270 Serial.println("Vol-"); 271 #endif 272 } 273 } 274 275 if (millis()-last_time > 5000) { //a button has not been pressed for 10 s 276 #ifdef 277 DEBUG 278 Serial.println("Going to sleep..."); 279 #endif 280 going_to_sleep(); 281 //enter sleep mode 282 #ifdef DEBUG 283 Serial.println("Waking up..."); 284 285 #endif 286 } 287} 288 289//Sleep Mode function 290void going_to_sleep() { 291 292 sleep_enable(); //enable sleep mode 293 attachInterrupt(digitalPinToInterrupt(Interrupt_Pin), 294 wake_up, LOW); //interrupt for waking up --> configure Interrupt Pin as a WIRED 295 NOR!!! 296 set_sleep_mode(SLEEP_MODE_PWR_DOWN); //full sleep mode 297 sleep_cpu(); 298 //activate sleep mode 299} 300 301//Wake Up function 302void wake_up() { 303 sleep_disable(); 304 //disable sleep mode 305 detachInterrupt(digitalPinToInterrupt(Interrupt_Pin)); 306 //remove the interrupt 307} 308
Downloadable files
Breadboard view
Breadboard view
remote_zhQ3qUiq1W.pdf
remote_zhQ3qUiq1W.pdf
remote_zhQ3qUiq1W.pdf
remote_zhQ3qUiq1W.pdf
Fritzing diagram
Fritzing diagram
Breadboard view
Breadboard view
Documentation
base_stl_AlV48IAapv.STL
base_stl_AlV48IAapv.STL
coperchio_stl_TjKnGcR3uQ.STL
coperchio_stl_TjKnGcR3uQ.STL
coperchio_stl_TjKnGcR3uQ.STL
coperchio_stl_TjKnGcR3uQ.STL
base_stl_AlV48IAapv.STL
base_stl_AlV48IAapv.STL
Comments
Only logged in users can leave comments