Hi guys,
I'm trying to make a robot with the Arduino that will be commanded trought the serial port of a router with DD Wrt. So, I've tried a little code I learned from the internet that is the following:
#define LED 13
int input = 0;
void setup() {
pinMode(LED,OUTPUT);
Serial.begin(9600);
}
void loop () {
input = Serial.read();
if (input == '1' ) {
digitalWrite(LED,HIGH);
Serial.println("LED13 is ON");
}
if (input == '0'){
digitalWrite(LED, LOW);
Serial.println("LED13 is OFF");
}
}
Simple. 0 for LED turned off, 1 for LED turned on. However, this has a little problem: since the router is always sending serial data trought it's serial port, the LED (and other components in the future) will always answering to orders that I don't want. So, I tought and I guess that I could use instead of "0" and "1" and other characters, use a string of them. Like, for LED on, "010101010" or simply "LEDON". So, I replaced the code with various alternatives, but I was not successfull.
Then I made a few reading and I found that the baud rate could be to high to the arduino from the router (they were the same, and at this moment I had a baudrate of 115200bps). I tought I've changed it on the router (I'm not even sure I can do that with this version of ddwrt) and on arduino to 9600bps. However, even with the Arduino connected only to the PC it wouldn't still not work!
A few moments of research later I found that I might need to use a string. But, according to what I've read this brings me two main problems:
1- The coding. I've seen a few examples of code with string and I just don't get it!
2- I've read that strings take a lot of memory from the Arduino, and I need a relatively fast processing time.
So, what I need to use are strings? If yes, can you teach me how to code them, please? Or should I use an alternative?
Thank you guys in advance, so much! This problem is really messing with me, I don't even know to where should I turn to!
Best regardings,
Tiago Ferreira.