0% found this document useful (0 votes)
29 views5 pages

Reciever Code

This code summarizes an Arduino sketch that controls a robot via RF module. It initializes serial communication and pins for the RF module. The scan function reads data from the RF module, isolates the command string, and controls motors and LEDs based on the command string value. The setup function initializes serial ports and pins. The loop continuously calls the scan function to check for and execute new commands received over RF.

Uploaded by

SiddharthMittal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

Reciever Code

This code summarizes an Arduino sketch that controls a robot via RF module. It initializes serial communication and pins for the RF module. The scan function reads data from the RF module, isolates the command string, and controls motors and LEDs based on the command string value. The setup function initializes serial ports and pins. The loop continuously calls the scan function to check for and execute new commands received over RF.

Uploaded by

SiddharthMittal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Rf module code

#include<SoftwareSerial.h>

int pin5=5;
int pin6=6;
int pin3=3;
int pin4=4;
int ledpin=13;

SoftwareSerial mySerial(0,1); //setting pins 0,1 for rx,tx resp

//**************scan function****************//
void scan()
{
char temp[10];
char data[10];
int i=0;
for(int i=0;i<10;i++)
{
temp[i]=0;

// initializing by 0

data[i]=0;
}
byte len =0;

// var to store length

//*********algorithm to scan/read data*****************//


if(mySerial.available()) // if any data gets detected, start

{
mySerial.flush(); // flush the buffer
mySerial.setTimeout(5000);

//set timeout of 5 seconds

if(mySerial.findUntil("$","$")) //checking for $ character for termination of


string
{
len = mySerial.readBytesUntil('$',temp,10); // saved string in temp and
got length of string

Serial.println(temp); // for debugging


Serial.println(len); // for debugging

// ===Algorithm for Sorting main data from Total String======

while(temp[i]!='*') //main data starts after *


{
i++;
}
i++;

// increment once to go to main data

int j=0;
while(temp[i]!='$')
{
data[j]=temp[i];
temp
i++;
j++;
}

// writing main data to data variable from

}
}
if (strcmp("00",data)==0)
{
Serial.println("1212");
digitalWrite(pin5,HIGH);//straight
digitalWrite(ledpin,HIGH);
delay(10000);
digitalWrite(ledpin,LOW);
delay(1000);
}
if (strcmp("01",data)==0)
{

digitalWrite(pin6,HIGH);//left
digitalWrite(ledpin,HIGH);
delay(5000);
digitalWrite(ledpin,LOW);
delay(1000);
}
if (strcmp("10",data)==0)
{
digitalWrite(pin3,HIGH); //right
digitalWrite(ledpin,HIGH);
delay(1000);
digitalWrite(ledpin,LOW);
delay(1000);
}

if (strcmp("11",data)==0)
{
digitalWrite(pin4,HIGH); //back
digitalWrite(ledpin,HIGH);
delay(15000);
digitalWrite(ledpin,LOW);
delay(1000);
}
}
void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

// Serial Port initialization by 9600 Bps

mySerial.begin(1200);//SoftwareSerial port initialization by 1200 bps

mySerial.setTimeout(5000);

// Set time out 5 sec

mySerial.flush();

pinMode(pin5,OUTPUT);
pinMode(pin6,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);
pinMode(ledpin,OUTPUT);

void loop() {

// put your main code here, to run repeatedly:

scan();
}

You might also like