int relay=2;
String data;
void setup()
{
Serial.begin(9600);
Serial.print("welcome to my project:");
pinMode(relay,OUTPUT);
}
void loop()
{
if(Serial.available()>0)
{
data=Serial.readString();
data.trim();
if(data=="relay on")
{
Serial.println("relay is on condition");
digitalWrite(relay,HIGH);
}
if(data=="relay off")
{
Serial.println("relay is off condition");
digitalWrite(relay,LOW);
}
}
}