#include //Serial communication library
const byte rxPin = 9;
const byte txPin = 10;
SoftwareSerial mySerial (rxPin, txPin); //defining communication pins
char data = 0;
//Variable for storing received data
void setup()
{
mySerial.begin(9600);
//Sets the data rate in bits per second (baud) for serial data transmission
pinMode(13, OUTPUT);
//Sets digital pin 13 as output pin
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
if(mySerial.available() > 0) // Send data only when you receive data:
//motor 1 forward
{
data = mySerial.read(); //Read the incoming data and store it into variable data
mySerial.print(data); //Print Value inside data in Serial monitor
mySerial.print("\n"); //New line
if(data == 'a') //Checks whether value of data is equal to 1
digitalWrite(13, HIGH);//If value is 1 then LED turns ON
delay(1000);
digitalWrite(13, LOW); //If value is 0 then LED turns OFF
}
//motor 1 reverse
{
data = mySerial.read(); //Read the incoming data and store it into variable data
mySerial.print(data); //Print Value inside data in Serial monitor
mySerial.print("\n"); //New line
if(data == 'b') //Checks whether value of data is equal to 1
digitalWrite(12, HIGH); //If value is 1 then LED turns ON
delay(1000);
digitalWrite(12, LOW); //If value is 0 then LED turns OFF
}
}