Project tutorial

Infrared Control © LGPL

IR Control > Arduino > Sound/RGB LED

  • 1,517 views
  • 0 comments
  • 5 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
52ac2324 40
Infrared Receiver, 38 kHz
Elegoo Infrared Receiver on a breakout board from a Starter Kit
×1
5202164
Infrared Emitter, 18 °
Elegoo Remote Control from a Starter Kit
×1
11026 02
Jumper wires (generic)
×1
RGB LED
1x 4 legs RGB LED with R, (-), G, B
×1
Adafruit industries ada1536 image
Buzzer
×1

Apps and online services

About this project

Today I describe how the Arduino uses a remote control to pick up the signal via the receiver and then play a melody or a sound on a buzzer and so that you also have an optical control that switches the respective light on an RGB LED. In this example, I reduced myself to buttons 1-3 on the remote control.

Here you can see and hear the corresponding reaction to the push of button 1, 2 or 3:

example vid

With a remote control, you can silently trigger a trigger, even over a certain distance of several meters.

The buzzer usually doesn't matter how it's connected: the RGB LED with its 4 pins is different. the longest PIN is connected to GND; the remaining 3 pins each represent a color of red, green and blue. The implementation of the circuit can be found in the sketch.

Here the Uno can also be easily exchanged for other devices. The control of relays could also be realized in this way.

Code

Example code for ArduinoC/C++
// IRremote - Version: Latest 
#include <IRremote.h>
#include <IRremoteInt.h>

int redLED = 3;
int yellowLED = 4;
int blueLED = 5;

int speakerPin = 9;

// the calculation of the tones is made following the mathematical operation:
// > timeHigh = period / 2 = 1 / (2 * toneFrequency)
// where the different tones are described as in the table:
//note    frequency    period    timeHigh
  /*
  c       261 Hz       3830       1915   
  d       294 Hz       3400       1700  
  e       329 Hz       3038       1519  
  f       349 Hz       2864       1432  
  g       392 Hz       2550       1275  
  a       440 Hz       2272       1136  
  b       493 Hz       2028       1014  
  C       523 Hz       1912        956
  */

int length = 8; // the number of notes
char notes[] = "cdefgabC "; // a space represents a rest
int beats[] = { 1 };
int tempo = 300;

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode"); 
  irrecv.enableIRIn(); // Start the receiver
   
  pinMode(speakerPin, OUTPUT);

  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(blueLED, OUTPUT);

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
    Serial.println(results.value); // > here you get the integer from your Remote
    // use an Decimal to Hexadecimal Converter to get the Hex like this: http://www.binaryhexconverter.com/decimal-to-hex-converter
    // add your Mapping in the function translateIR > check the two examples with Power and number 5-Button
    translateIR(); 
    irrecv.resume(); // receive the next value
  }  
}/* --(end main loop )-- */

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes 

{

  switch(results.value)
    
  {
  case 0xFFA25D: Serial.println("POWER Elegoo"); break;     // 16753245 Elegoo
  case 0xE0E040BF: Serial.println("POWER Samsung"); break;  // 3772793023 Samsung
  case 0xD5AD0B51: Serial.println("POWER Technics"); break;  // 3584887633 Technics
  case 0xA0C: Serial.println("POWER TechniSat"); break; // TechniSat
  
  case 0xFFE21D: Serial.println("FUNC/STOP"); break; // 16769565 Elegoo
  case 0xFF629D: Serial.println("VOL+"); break;  // 16736925 Elegoo 
  case 0xFF22DD: Serial.println("FAST BACK");    break;  // 16720605 Elegoo
  case 0xFF02FD: Serial.println("PAUSE");    break;  // 16712445
  case 0xFFC23D: Serial.println("FAST FORWARD");   break;
  case 0xFFE01F: Serial.println("DOWN");    break;
  case 0xFFA857: Serial.println("VOL-");    break;
  case 0xFF906F: Serial.println("UP");    break;
  case 0xFF9867: Serial.println("EQ");    break;
  case 0xFFB04F: Serial.println("ST/REPT");    break;
  
  case 0xFF6897: Serial.println("0");    break;
  case 0x200: Serial.println("0 TechniSat"); break; // TechniSat
  case 0xA00: Serial.println("0 TechniSat"); break; // TechniSat
  
  case 0xFF30CF: Serial.println("1");  
  playNote(notes[1], 1 * tempo);
  digitalWrite(redLED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(redLED, LOW);    // turn the LED off by making the voltage LOW
  
 /*   for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }

    // pause between notes
    delay(tempo / 2); 
  }
  */
  break;
  
  case 0x201: Serial.println("1 TechniSat"); break; // TechniSat
  case 0xA01: Serial.println("1 TechniSat"); break; // TechniSat
  
  case 0xFF18E7: Serial.println("2");
  playNote(notes[2], 1 * tempo);
  digitalWrite(yellowLED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(yellowLED, LOW);    // turn the LED off by making the voltage LOW
  
  break;
  case 0x202: Serial.println("2 TechniSat"); break; // TechniSat
  case 0xA02: Serial.println("2 TechniSat"); break; // TechniSat
  
  case 0xFF7A85: Serial.println("3");
  playNote(notes[3], 1 * tempo);
  digitalWrite(blueLED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(blueLED, LOW);    // turn the LED off by making the voltage LOW
  
  break;
  case 0x203: Serial.println("3 TechniSat"); break; // TechniSat
  case 0xA03: Serial.println("3 TechniSat"); break; // TechniSat
  
  case 0xFF10EF: Serial.println("4");    break;
  case 0x204: Serial.println("4 TechniSat"); break; // TechniSat
  case 0xA04: Serial.println("4 TechniSat"); break; // TechniSat
  
  case 0xFF38C7: Serial.println("5 Elegoo");    break;     // 16726215 Elegoo
  case 0xE0E0906F: Serial.println("5 Samsung");    break;  // 3772813423 Samsung
  case 0xB1CE824B: Serial.println("5 Technics");    break;  // 2983101003 Technics
  case 0x205: Serial.println("5 TechniSat"); break; // TechniSat
  case 0xA05: Serial.println("5 TechniSat"); break; // TechniSat
  
  case 0xFF5AA5: Serial.println("6");    break;
  case 0x206: Serial.println("6 TechniSat"); break; // TechniSat
  case 0xA06: Serial.println("6 TechniSat"); break; // TechniSat
  
  case 0xFF42BD: Serial.println("7");    break;
  case 0x207: Serial.println("7 TechniSat"); break; // TechniSat
  case 0xA07: Serial.println("7 TechniSat"); break; // TechniSat

  case 0xFF4AB5: Serial.println("8");    break;
  case 0x208: Serial.println("8 TechniSat"); break; // TechniSat
  case 0xA08: Serial.println("8 TechniSat"); break; // TechniSat
  
  case 0xFF52AD: Serial.println("9");    break;
  case 0x209: Serial.println("9 TechniSat"); break; // TechniSat
  case 0xA09: Serial.println("9 TechniSat"); break; // TechniSat
  
  case 0xFFFFFFFF: Serial.println(" REPEAT");break;  

  default: 
    Serial.println(" other button   ");

  }// End Case

  delay(500); // Do not get immediate repeat


} //END translateIR

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}

Comments

Similar projects you might like

Servo Control with TV Remote Control

Project showcase by eldo85

  • 13,028 views
  • 6 comments
  • 35 respects

Control an LED with the Remote Control

Project showcase by Nicholas_N

  • 12,697 views
  • 8 comments
  • 19 respects

Control Your Computer With A Remote Control

Project tutorial by Arduino_Scuola

  • 8,197 views
  • 1 comment
  • 9 respects

Infrared Remote Emulator

Project tutorial by TATCO

  • 4,165 views
  • 0 comments
  • 15 respects

Infrared Remote

Project tutorial by 4 developers

  • 4,884 views
  • 0 comments
  • 37 respects
Add projectSign up / Login