I am trying to get an LED to light up when a certain message comes through on the serial port but nothing is working! please help me!!
int awsState = "AWS:0"; // for incoming serial data
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
awsState = Serial.read();
// say what you got:
Serial.print(incomingByte);
Serial.println("Good");
if (awsState == "AWS:1"){
digitalWrite(13, HIGH);
}
else if (awsState == "AWS:0"){
digitalWrite(13, LOW);
}
}
}
Here is a way to read a command from the
Serial
link.Step 1 - declare a String to store input data as global variable
Instead of:
Step 2 - initialize the String in the
setup()
Step 3 - extract all received character, display them and process the command