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.#definePOWER0x1FE48B7 //power#defineMODE0x1FE58A7 //menu#defineMUTE0x1FE7887#definePLAY0x1FE807F#defineREWIND0x1FE40BF#defineFORWARD0x1FEC03F#defineEQUIL0x1FE20DF#defineVOLUMEM0x1FEA05F#defineVOLUMEP0x1FE609F#defineZER00x1FEE01F#defineREPT0x1FE10EF#defineUSD0x1FE906F#defineONE0x1FE50AF#defineTWO0x1FED827#defineTHREE0x1FEF807#defineFOUR0x1FE30CF#defineFIVE0x1FEB04F#defineSIX0x1FE708F#defineSEVEN0x1FE00FF#defineEIGHT0x1FEF00F#defineNINE0x1FE9867IRrecvirrecv(IRRX);decode_results results;unsignedlong irCode =0;int ledState = LOW;voidsetup(){pinMode(LED_BUILTIN, OUTPUT);Serial.begin(9600); // Set up serial communicationirrecv.enableIRIn(); // Start the receiverpinMode(LED_BUILTIN, OUTPUT); // set arduino pin to output mode}voidloop(){if (irrecv.decode(&results)) { irCode =results.value;if (irCode !=0xFFFFFFFF) {Serial.print("Hex Value = ");Serial.print(irCode, HEX); // print raw valuestranslateIR(); }irrecv.resume(); // wait for the next valuecontrolComponents(); }}voidtranslateIR(){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 extendedvoidcontrolComponents() {if (irCode == POWER) { ledState =!ledState;digitalWrite(LED_BUILTIN, ledState); }}