Guillermo Alberto Perez Guillen
Created August 7, 2018 © CC BY-SA

RF Remote Control With Infineon 3D Magnetic Sensor 2Go

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

AdvancedFull instructions provided24 hours87

Things used in this project

Story

Read more

Schematics

RF Transmitter

Electrical diagram showing the connections between the boards: "Infineon 3D Magnetic Sensor 2Go" and "Mega 2560"
02 transmitter c8ws9yyzhy

RF Receiver

Electrical diagram showing the connections of the "Arduino UNO" board as receiver
02 receiver mb5vlgfnj0

Code

"Infineon 3D Magnetic Sensor 2Go" Code

Arduino
This code is uploaded to the "Infineon 3D Magnetic Sensor 2Go" board
#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);
    }  
}

"Mega 2560" Code

Arduino
This code is uploaded to the "Mega 2560" board as RF Transmitter
#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); //Pin 2 as RF output 
}

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

"Arduino UNO" Code

Arduino
This code is uploaded to the "Arduino UNO" board as RF Receiver
#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 RF input
    vw_rx_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;
    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");           
        }        
    }
}

    

Credits

Guillermo Alberto Perez Guillen

Guillermo Alberto Perez Guillen

21 projects • 17 followers
Communications and Electronics Engineer I'm interested in robotics, electronics, programming in C language and developing new projects.

Comments