Dear all
I’m made project counter control with Arduino board.
In my project have Arduino, LCD, Relay, Proximity.
Concept
PC (RS232) --- send cycle ---> Arduino board ( Show on LCD )
Proximity detect cycle on Machine if cycle = 1 then Relay is High.
Machine will stop = and Arduino LCD show “OK”
In my code, I can send cycle to many time no problem.
My problem come from after cycle = 1 and show “OK” ? After PC(rs232) send data again sometime OK,
Some time show error ( see in attach file picture )
I suspect that your relay operation is causing intermittent power problem.
It is not clear what command operates the relays ( HIGH on/ LOW off ?) - the comments are contradicting.
Are you driving the relay directly from pin 11 and if so do you have a reverse EMF diode in the circuit?
Can you repeat the lcd outputs AFTER you operate the relay - like this:
lcd.clear();
lcd.setCursor(0,0); // 2-Oct-2014
lcd.print("CYCLE"); // test print encoder0Pos
lcd.setCursor(6,1);
//lcd.print(" ");
lcd.print("OK");
digitalWrite(RELAY1,HIGH); // Turns Off Relays 1
delay(1000); // Wait 1 seconds
//digitalWrite(RELAY1,LOW); // Turns Relay Off
repeat the lcd output again
lcd.clear();
lcd.setCursor(0,0); // 2-Oct-2014
lcd.print("CYCLE"); // test print encoder0Pos
lcd.setCursor(6,1);
//lcd.print(" ");
lcd.print("OK");
repeat the lcd output again
//Serial.flush(); //test clear buffer after receive data 18-09-2014
Serial.end(); //'26-09-2014 end cycle clear buffer and data testing
delay(1000);
Serial.begin(9600);
delay(1000);
QQ = 9;
delay(1000);
//lcd.blink();
//lcd.noBlink();
BTW - it is not a good practice to detect input ( button) from idle ground to active high.
If the input get accidentally grounded you will not detect it as failure.
But accidentally grounding circuit which is idle high gets detected if no button is pressed.
Serial.end(); //'26-09-2014 end cycle clear buffer and data testing
delay(1000);
Serial.begin(9600);
Why are you doing this? What do you think you are doing by calling end() and begin() again?
If the intention is to empty the outgoing buffer, Serial.flush() will do that. If the intention is to empty the incoming buffer, STOP THAT! Only an idiot would dump random amounts of unread data. If you just insist, though: