VEEROBOT Docs
StoreBlogWiki
  • 🌐Introduction
  • ROS Based Robots
    • 🐺Wolf Robot
      • ROS Introduction
      • Getting Started with ROS 2
      • Introduction to Wolf Robot
      • ROS 2 Setup
      • ROS Concepts
      • Using Wolf Examples
      • Creating a URDF File
      • Visualising in Gazebo
      • Controlling motors from ROS
      • LiDAR Basics & Control
      • Using a Camera with ROS2
      • ROS 2 Cleanup
      • ROS 2 Controller
      • Teleoperation
      • Slam Navigation
      • Wolf : Conclusion
  • Arduino Based Robots
    • 🚜Micro:Xbot
      • Preparations before First Use
      • Programming the Board
      • Powering the Board
      • Pin Mapping
      • Basic Programs
        • Blinking LED
        • Buzzer Program
        • Fading LED
        • RGB LED
        • Light Detection
        • Battery Voltage
        • Line Follower Module
        • Ultrasonic Sensor
        • Infrared Remote Control
        • Motor Control
        • Bluetooth Control
        • Display Test
        • Test Me
      • Robot Assembly
      • Advanced Programs
        • Bluetooth Controlled Robot
        • Obstacle Avoidance Robot
        • Line Follower Robot
  • ROS2 Repo
    • Introduction
    • Page 1
      • Sub Page 1
    • Page 2
Powered by GitBook
On this page
  1. Arduino Based Robots
  2. Micro:Xbot
  3. Basic Programs

Infrared Remote Control

Control micro:Xbot from an external source

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.

  1. Read the values from an IR remote so that we know how to read signals from any remote

  2. 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);
  }
}

PreviousUltrasonic SensorNextMotor Control

Last updated 2 years ago

🚜