This is just a simple test program. I’m trying to have the Arduino print “received” on an LCD screen attached to it. I think it’s my if statement causing the error, any ideas?
Currently when “send” is put in the serial monitor nothing happens.
Here is the code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char serialinput; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
serialinput = Serial.read();
if (serialinput == 'send')
{
lcd.print("received");
}
}
}
You’re reading a byte (a
charin C) from your serial port, but you try to compare it to a string:If you want to read 4
charand compare it to"send"then you would have to do something like:Assuming that
<string.h>header is valid within the Arduino SDKPS : litteral strings in C code are written between
"(double quotation marks).'is for characters.