This is what I am doing,
I have an Xbee connected to PC through Explorer USB. I am trying to send command to an arduino connected with Xbee too in the following format, for example,
"O6000",
Which means the pin 8 will output high (Open) for 6000ms.
However, I dont know why, this code doesnt not work out, when I connect the Xbee to PC, I keep getting rubbish information on my console log even I suppose there is no output to be transmitted from Arduino side.
char Array[6];
boolean newdata=false;
char endMarker = '\n';
char rc;
int count=0;
int SOLENOID=8;
int duration;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available() > 0 && newdata == false) {
char rc = Serial.read();
if (rc != endMarker) {
Array[count] = rc;
count++;
}
else {
Array[count] = '\0'; // terminate the string
count = 0;
newdata = true;
}
}
Serial.println(Array);
if (Array[1]=='O'){
digitalWrite(SOLENOID, HIGH);
duration=(Array[2]-'0')*1000+(Array[3]-'0')*100+(Array[4]-'0')*10+(Array[5]-'0');
delay(duration);
}
}
This is my code. Anyone got an idea?