Project tutorial
RF Remote Control With Infineon 3D Magnetic Sensor 2Go

RF Remote Control With Infineon 3D Magnetic Sensor 2Go © CC BY-SA

This project shows us how we control a "Micro Robot Car" and using a RF Remote Control with "Infineon 3D Magnetic Sensor 2Go".

  • 243 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

Introduction

This project shows us the use of a remote control via RF to control a micro-robot car. To achieve this goal, we divide the project into two parts: the transmitting part and the receiving part. In the transmitting part I use the "Infineon 3D Magnetic Sensor 2Go" board to capture and process the data that this sensor gave me and I use the "Mega 2560" board to send this data by “Radio Frequency”. In the receiving part I use the "Arduino UNO" board to execute the received orders. To make this prototype, I was inspired by my project:

We have to review the technical sheet of our magnetic sensor. In the following image we can see the components of this board.

In the following image we can see the configuration of the pins of our board.

To program our board, we have to download and install the following software:

  • Arduino IDE.
  • 3D Magnetic Sensor 2 Go.
  • USB Driver from SEGGER.
  • Library: TLE493D-W2B6-3DMagnetic-Sensor
  • Board: XMC Microcontroller by Infineon

The latest version of Arduino IDE is downloaded from: https://www.arduino.cc/en/Main/Software

3D Magnetic Sensor 2 Go, serves us to test with our device and download it from the official site of Infineon. This program only runs under Windows and has an old USB version of SEGGER. We have to download and install the latest version of SEGGER USB Driver so that our device works correctly.

The library TLE493D-W2B6-3DMagnetic-Sensor is downloaded from the official Infineon site on github. There we will find the instructions to follow for its correct installation. https://github.com/Infineon/TLE493D-W2B6-3DMagnetic-Sensor

The XMC Microcontroller board is downloaded from the official Infineon site on github. There we will find the instructions for a correct installation.

https://github.com/Infineon/XMC-for-Arduino

In my case, I installed version 1.1.0 since version 1.1.1 indicated an error. Later we added the url of the card and installed it: https://github.com/Infineon/Assets/releases/download/current/package_infineon_index.json

RF Transmitter

Theelectrical diagram of the “RF Transmitter” is as follows:

The operation of the RF Transmitter is as follows:

We rotate the "Rotation Knob" of our magnetic sensor and we can execute four orders that are programmed by software and using the GPIO4 and GPIO5 pins as outputs:

  • Stop: order to stop the car and send the code "00".
  • Right: order to turn the car to the right and send the code "01".
  • Forward: order to go forward and send the code "10".
  • Left: order to turn the car to the left and send the code "11".

Each order has a range of 30 degrees and in the following image you can see this configuration in a visual way.

Infineon.ino

#include <Tle493d_w2b6.h>
Tle493d_w2b6 Tle493dMagnetic3DSensor = Tle493d_w2b6();
void setup() {
 Serial.begin(9600);
 pinMode (4,OUTPUT);
 pinMode (5,OUTPUT);
 while (!Serial);
 Tle493dMagnetic3DSensor.begin();
 Tle493dMagnetic3DSensor.enableTemp();
}
void loop() {
 Tle493dMagnetic3DSensor.updateData();
 float angle = Tle493dMagnetic3DSensor.getAzimuth() * 57.3;
 int angle1 = angle;
 float Norm = Tle493dMagnetic3DSensor.getNorm();
 if ((angle1>=165 && angle1<=180 && Norm>=90)||(angle1>=-180 && angle1<=-165 && Norm>=90)){    // STOP
       Serial.print(angle1);
       Serial.println(" = STOP");
       digitalWrite (4,LOW);
       digitalWrite (5,LOW);
       delay (10);
   }  
 else if (angle1>=-105 && angle1<=-75 && Norm>=90){    // RIGHT
       Serial.print(angle1);
       Serial.println(" = RIGHT");
       digitalWrite (4,LOW);
       digitalWrite (5,HIGH);
       delay (10);
   }  
 if (angle1>=-15 && angle1<=15 && Norm>=90){    // FORWARD
       Serial.print(angle1);
       Serial.println(" = FORWARD");
       digitalWrite (4,HIGH);
       digitalWrite (5,LOW);
       delay(10);
   }
 else if (angle1>=75 && angle1<=105 && Norm>=90){    // LEFT
       Serial.print(angle1);
       Serial.println(" = LEFT");
       digitalWrite (4,HIGH);
       digitalWrite (5,HIGH);
       delay (10);
   }  
}

The "Mega 2560" board receives these four orders from the magnetic sensor, encodes them and sends them through the transmitter "TLP434A", which works at 433 MHz. These encodings are the following:

  • Stop: we send the character "S".
  • Right: we send the character "R".
  • Forward: we send the character "F".
  • Left: we send the character "L".

We can use several libraries to validate the data sent by Radio Frequency, in my case I have used the library "VirtualWire.h" and this library works very well. The codes of the boards "Infineon 3D Magnetic Sensor 2Go" and "Mega 2560" can be downloaded at the end of this tutorial.

TX_mega.ino

#include <VirtualWire.h>
#define SWITCH1 8   //input for SWITCH1
#define SWITCH2 9   //input for SWITCH2
void setup()
{
   Serial.begin(9600);    
   Serial.println("Tx RF");
   pinMode (SWITCH1,INPUT);
   pinMode (SWITCH2,INPUT);
   // Se inicializa el RF
   vw_setup(2000); // bps
   vw_set_tx_pin(2); //output RF 
}
void loop()
{
char dato[1];
    if ((digitalRead(SWITCH1)==LOW) && (digitalRead(SWITCH2)==LOW)) {   // STOP
     dato[0] = 'S';      
     vw_send((uint8_t*)dato,sizeof(dato));
     vw_wait_tx();      
     Serial.println("STOP");
    }
    if ((digitalRead(SWITCH1)==LOW) && (digitalRead(SWITCH2)==HIGH)) {   // RIGHT
     dato[0] = 'R';      
     vw_send((uint8_t*)dato,sizeof(dato));
     vw_wait_tx(); 
     Serial.println("RIGHT");
    }
    if ((digitalRead(SWITCH1)==HIGH) && (digitalRead(SWITCH2)==LOW)) {   // FORWARD
     dato[0] = 'F';
     vw_send((uint8_t*)dato,sizeof(dato));
     vw_wait_tx();             
     Serial.println("FORWARD");      
    }
    if ((digitalRead(SWITCH1)==HIGH) && (digitalRead(SWITCH2)==HIGH)) {   // LEFT
     dato[0] = 'L';
     vw_send((uint8_t*)dato,sizeof(dato));
     vw_wait_tx();             
     Serial.println("LEFT");
    }
   delay(200);
}

RF Receiver

The electrical diagram of the “RF Receiver” is as follows:

The operation of the RF Receiver is as follows:

The "Arduino UNO" board receives four orders from the RF Transmitter through the receiver "RLP434", which works at 433 MHz. These commands are decoded and executed in the following way:

  • Stop: we receive the character "S" and the car stops.
  • Right: we receive the character "R" and the car turns to the right.
  • Forward: we receive the character "F" and the car moves forward.
  • Left: we receive the character "L" and the car moves to the left.

Each time the car moves, we use the "L293B" driver and two reduction motors.

We can use several libraries to validate the data sent by Radio Frequency; in my case I have used the library "VirtualWire.h" and this library works very well. The code of the "Arduino UNO" board can be downloaded at the end of this tutorial.

Rx_arduino.ino

#include <VirtualWire.h>
void setup()
{
   Serial.begin(9600);  // Debugging only
   Serial.println("setup");
   // Se inicializa el RF
   vw_setup(2000);  // bps
   vw_set_rx_pin(2);  //Pin 2 as input RF
   vw_rx_start();       // start
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT); 
}
void loop()
{
   uint8_t dato;
   uint8_t datoleng=1;
   //verufy RF data
   if (vw_get_message(&dato,&datoleng))
   {
       if((char)dato=='S')   // STOP
       {
          digitalWrite(3,LOW);
          digitalWrite(4,LOW);
          digitalWrite(5,LOW);  //en1 
          digitalWrite(6,LOW);  //en2
          digitalWrite(7,LOW);
          digitalWrite(8,LOW);                                           
          delay(10);
          Serial.println("STOP");           
       }
       if((char)dato=='R')   // RIGHT
       {
          digitalWrite(3,HIGH);
          digitalWrite(4,LOW);
          digitalWrite(5,HIGH);  //en1 
          digitalWrite(6,HIGH);  //en2
          digitalWrite(7,HIGH);
          digitalWrite(8,LOW);                                          
          delay(10);
          Serial.println("RIGHT");           
       }
       if((char)dato=='L')   // LEFT
       {
          digitalWrite(3,LOW);
          digitalWrite(4,HIGH);
          digitalWrite(5,HIGH);  //en1 
          digitalWrite(6,HIGH);  //en2
          digitalWrite(7,LOW);
          digitalWrite(8,HIGH);                                          
          delay(10);
          Serial.println("LEFT");           
       }
       if((char)dato=='F')   // FORWARD
       {
          digitalWrite(3,HIGH);
          digitalWrite(4,LOW);
          digitalWrite(5,HIGH);  //en1 
          digitalWrite(6,HIGH);  //en2
          digitalWrite(7,LOW);
          digitalWrite(8,HIGH);                                        
          delay(10);
          Serial.println("FORWARD");           
       }        
   }
}

Test

Conclusions

I first tested the prototype with the devices connected to my PC to verify that the communication was being made and that the "RF Receiver" received the data that the "RF Transmitter" was sending. The serial port of the Arduino UNO board shows us this data that I was waiting for. In the second test I used a prototype of a "Microrobot Car" to demonstrate an application of this prototype.

The main goal was met. Using the "Infineon 3D Magnetic Sensor 2Go" board in a remote control is a good option to control a "Micro Robot Car", since it gives you the opportunity to maneuver your cart in a practical and efficient way. An important observation is the following one: When our remote control prototype has been blocked or stunned, it is convenient to reinitialize it from the beginning or to give it a "reset" and in this way it will continue working correctly.

Code

Infineon.inoArduino
#include <Tle493d_w2b6.h>

Tle493d_w2b6 Tle493dMagnetic3DSensor = Tle493d_w2b6();
void setup() {
  Serial.begin(9600);
  pinMode (4,OUTPUT);
  pinMode (5,OUTPUT);
  while (!Serial);
  Tle493dMagnetic3DSensor.begin();
  Tle493dMagnetic3DSensor.enableTemp();
}

void loop() {
  Tle493dMagnetic3DSensor.updateData();
  float angle = Tle493dMagnetic3DSensor.getAzimuth() * 57.3;
  int angle1 = angle;
  float Norm = Tle493dMagnetic3DSensor.getNorm();

  if ((angle1>=165 && angle1<=180 && Norm>=90)||(angle1>=-180 && angle1<=-165 && Norm>=90)){    // STOP
        Serial.print(angle1);
        Serial.println(" = STOP");
        digitalWrite (4,LOW);
        digitalWrite (5,LOW);
        delay (10);
    }  

  else if (angle1>=-105 && angle1<=-75 && Norm>=90){    // RIGHT
        Serial.print(angle1);
        Serial.println(" = RIGHT");
        digitalWrite (4,LOW);
        digitalWrite (5,HIGH);
        delay (10);
    }  

  if (angle1>=-15 && angle1<=15 && Norm>=90){    // FORWARD
        Serial.print(angle1);
        Serial.println(" = FORWARD");
        digitalWrite (4,HIGH);
        digitalWrite (5,LOW);
        delay(10);
    }

  else if (angle1>=75 && angle1<=105 && Norm>=90){    // LEFT
        Serial.print(angle1);
        Serial.println(" = LEFT");
        digitalWrite (4,HIGH);
        digitalWrite (5,HIGH);
        delay (10);
    }  
}
Tx_mega.inoArduino
#include <VirtualWire.h>

#define SWITCH1 8   //input for SWITCH1
#define SWITCH2 9   //input for SWITCH2

void setup()
{
    Serial.begin(9600);    
    Serial.println("Tx RF");
    pinMode (SWITCH1,INPUT);
    pinMode (SWITCH2,INPUT);

    // Se inicializa el RF
    vw_setup(2000); // bps
    vw_set_tx_pin(2); //output RF 
}

void loop()
{
char dato[1];

     if ((digitalRead(SWITCH1)==LOW) && (digitalRead(SWITCH2)==LOW)) {   // STOP
      dato[0] = 'S';      
      vw_send((uint8_t*)dato,sizeof(dato));
      vw_wait_tx();      
      Serial.println("STOP");
     }

     if ((digitalRead(SWITCH1)==LOW) && (digitalRead(SWITCH2)==HIGH)) {   // RIGHT
      dato[0] = 'R';      
      vw_send((uint8_t*)dato,sizeof(dato));
      vw_wait_tx(); 
      Serial.println("RIGHT");
     }

     if ((digitalRead(SWITCH1)==HIGH) && (digitalRead(SWITCH2)==LOW)) {   // FORWARD
      dato[0] = 'F';
      vw_send((uint8_t*)dato,sizeof(dato));
      vw_wait_tx();             
      Serial.println("FORWARD");      
     }

     if ((digitalRead(SWITCH1)==HIGH) && (digitalRead(SWITCH2)==HIGH)) {   // LEFT
      dato[0] = 'L';
      vw_send((uint8_t*)dato,sizeof(dato));
      vw_wait_tx();             
      Serial.println("LEFT");
     }
    delay(200);
}
Rx_arduino.inoArduino
#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);  // Debugging only
    Serial.println("setup");

    // Se inicializa el RF
    vw_setup(2000);  // bps
    vw_set_rx_pin(2);  //Pin 2 as input RF
    vw_rx_start();       // start
    
   pinMode(3,OUTPUT);
   pinMode(4,OUTPUT);
   pinMode(5,OUTPUT);
   pinMode(6,OUTPUT);
   pinMode(7,OUTPUT);
   pinMode(8,OUTPUT); 
}

void loop()
{
    uint8_t dato;
    uint8_t datoleng=1;
    //verufy RF data
    if (vw_get_message(&dato,&datoleng))
    {
        if((char)dato=='S')   // STOP
        {
           digitalWrite(3,LOW);
           digitalWrite(4,LOW);
           digitalWrite(5,LOW);  //en1 
           digitalWrite(6,LOW);  //en2
           digitalWrite(7,LOW);
           digitalWrite(8,LOW);                                           
           delay(10);
           Serial.println("STOP");           
        }
        
        if((char)dato=='R')   // RIGHT
        {
           digitalWrite(3,HIGH);
           digitalWrite(4,LOW);
           digitalWrite(5,HIGH);  //en1 
           digitalWrite(6,HIGH);  //en2
           digitalWrite(7,HIGH);
           digitalWrite(8,LOW);                                          
           delay(10);
           Serial.println("RIGHT");           
        }

        if((char)dato=='L')   // LEFT
        {
           digitalWrite(3,LOW);
           digitalWrite(4,HIGH);
           digitalWrite(5,HIGH);  //en1 
           digitalWrite(6,HIGH);  //en2
           digitalWrite(7,LOW);
           digitalWrite(8,HIGH);                                          
           delay(10);
           Serial.println("LEFT");           
        }

        if((char)dato=='F')   // FORWARD
        {
           digitalWrite(3,HIGH);
           digitalWrite(4,LOW);
           digitalWrite(5,HIGH);  //en1 
           digitalWrite(6,HIGH);  //en2
           digitalWrite(7,LOW);
           digitalWrite(8,HIGH);                                        
           delay(10);
           Serial.println("FORWARD");           
        }        
    }
}

Schematics

RF Transmitter
02 transmitter c8ws9yyzhy ok6eu6p8hb
RF Receiver
02 receiver mb5vlgfnj0 pdkm0mhozt

Comments

Similar projects you might like

Control an LED with the Remote Control

Project showcase by Nicholas_N

  • 8,939 views
  • 3 comments
  • 16 respects

Servo Control with TV Remote Control

Project showcase by eldo85

  • 9,035 views
  • 5 comments
  • 25 respects

Turn LEDs On/Off via Remote Control

Project tutorial by ismystore

  • 8,815 views
  • 1 comment
  • 8 respects

RGB Infinity Mirror with 3D Magnetic Sensor

Project tutorial by Abdullah Sadiq

  • 3,167 views
  • 2 comments
  • 13 respects

Wireless Magnetic Data Transfer

Project tutorial by Tomi Chen

  • 5,376 views
  • 4 comments
  • 23 respects
Add projectSign up / Login