All the while we have configured and controlled the board using hard-coded programs. In the mobile world, we need to control a robot or any system wireless. The most basic wireless setup is to use an Infrared Remote controller. These controllers are used in most household to control TV, AC, Music System etc. We will use the built-in receiver to do two things.
Read the values from an IR remote so that we know how to read signals from any remote
Use the provided IR remote to send signals and control modules
Infrared Communication
Like any other communications systems, Infrared communication should have a transmitter and receiver. The transmitter looks just like an LED, but it produces light in the IR spectrum instead of the visible spectrum. Check the remote provided in the kit and you can see an IR light in front of it. However, when you press any button, the Infrared light is not visible to the naked eye. Flash it against a camera and you can see Infrared pulses.
IR receiver is a photo-diode embedded with a pre-amplifier that changes the IR light into an electrical signal. For IR communication both transmitter and receiver should be pointed to each other.
When a remote button is pressed, IR LED (Transmitter) emits infrared light. This light is received by the Receiver that is typically a photo-diode or photo-transistor. But the IR light is also emitted by the sun, light bulbs, and anything else that produces heat. This can interfere with our transmitter. To prevent this, the transmitter signal is modulated using a carrier frequency between 36 kHz to 46 kHz. Upon receiving the signal, the IR receiver demodulates the signal and converts it to binary before sending it to the micro-controller.
Here we are using the remote in the kit for sending IR signal and TSOP1838 module on the board for receiving them. We need a IR remote library which is included in the example folder.
/*
Ultrasonic Sensor: Sends a ping and calculates distance to obstacle in cms
At VEEROBOT, we invest time and resources providing this open source code,
Please support VEEROBOT and open-source hardware by purchasing products
from us @ http://veerobot.com
-----------------------------------------------------------------------------
You are free to redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
This Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
See <http://www.gnu.org/licenses/>
*/
#include "config.h"
#include "src/IRstepI/IRstepI.h"
// Hex values of each button on remote control. These are
// specific for the remote controller provided with thie kit.
// In case you have a different remote control, all you need to
// do is uncomment Serial.print("Hex Value = "); and find
// appropriate Hex value which can be later mapped to buttons.
#define POWER 0x1FE48B7 //power
#define MODE 0x1FE58A7 //menu
#define MUTE 0x1FE7887
#define PLAY 0x1FE807F
#define REWIND 0x1FE40BF
#define FORWARD 0x1FEC03F
#define EQUIL 0x1FE20DF
#define VOLUMEM 0x1FEA05F
#define VOLUMEP 0x1FE609F
#define ZER0 0x1FEE01F
#define REPT 0x1FE10EF
#define USD 0x1FE906F
#define ONE 0x1FE50AF
#define TWO 0x1FED827
#define THREE 0x1FEF807
#define FOUR 0x1FE30CF
#define FIVE 0x1FEB04F
#define SIX 0x1FE708F
#define SEVEN 0x1FE00FF
#define EIGHT 0x1FEF00F
#define NINE 0x1FE9867
IRrecv irrecv(IRRX);
decode_results results;
unsigned long irCode = 0;
int ledState = LOW;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600); // Set up serial communication
irrecv.enableIRIn(); // Start the receiver
pinMode(LED_BUILTIN, OUTPUT); // set arduino pin to output mode
}
void loop()
{
if (irrecv.decode(&results))
{
irCode = results.value;
if (irCode != 0xFFFFFFFF) {
Serial.print("Hex Value = ");
Serial.print(irCode, HEX); // print raw values
translateIR();
}
irrecv.resume(); // wait for the next value
controlComponents();
}
}
void translateIR()
{
Serial.print(" : Button = ");
switch (irCode)
{
case POWER:
Serial.print(" POWER");
break;
case MODE:
Serial.print(" MODE");
break;
case MUTE:
Serial.print(" MUTE");
break;
case PLAY:
Serial.print(" PLAY");
break;
case REWIND:
Serial.print(" REWIND");
break;
case FORWARD:
Serial.print(" FORWARD");
break;
case EQUIL:
Serial.print(" EQUILISER");
break;
case VOLUMEM:
Serial.print(" VOLUME MINUS");
break;
case VOLUMEP:
Serial.print(" VOLUME PLUS");
break;
case ZER0:
Serial.print(" ZERO");
break;
case REPT:
Serial.print(" REPEAT");
break;
case USD:
Serial.print(" US/D");
break;
case ONE:
Serial.print(" ONE");
break;
case TWO:
Serial.print(" TWO");
break;
case THREE:
Serial.print(" THREE");
break;
case FOUR:
Serial.print(" FOUR");
break;
case FIVE:
Serial.print(" FIVE");
break;
case SIX:
Serial.print(" SIX");
break;
case SEVEN:
Serial.print(" SEVEN");
break;
case EIGHT:
Serial.print(" EIGHT");
break;
case NINE:
Serial.print(" NINE");
break;
default:
Serial.print(" #NOT MAPPED");
}
Serial.println();
delay(30); // Software debouncing
}
// This is the main logic function. Any additional components
// can be attached here and extended
void controlComponents() {
if (irCode == POWER) {
ledState = !ledState;
digitalWrite(LED_BUILTIN, ledState);
}
}