Hi all I am having a small problemcontrolling a Safy Lighttower the tower is conected to a Arduino Unoand a Seedsrudio Relay shield what i would like to do is have a computer sending commands via usb toca control the Arduino attach is the code i am tring to configur can some one help me
Also i am getting the Arduino is resetting when it recive a comand from the usb
#include <arduino.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial (10, 11);
char serialin;
const byte Relay1 = 7;
const byte Relay2 = 6;
const byte Relay3 = 5;
const byte Relay4 = 4;
void setup() {
//Begin Serial Comunication(configured for 9600baud)
Serial.begin(9600);
//pin relay as OUTPUT
pinMode(Relay1, OUTPUT); //Red Light
pinMode(Relay2, OUTPUT); //Yellow Light
pinMode(Relay3, OUTPUT); //Green Light
pinMode(Relay4, OUTPUT); //Spare Relay
//Relay
digitalWrite(Relay1, LOW); //Red Light
digitalWrite(Relay2, LOW); //Yellow Light
digitalWrite(Relay3, HIGH); //Green Light
digitalWrite(Relay4, LOW);} //Spare Relay
void loop() {
//Verify connection by serial
while (Serial.available() > 0) {
//Read Serial data and alocate on serialin
serialin = Serial.read();
if (serialin == 'O'){ // No timer Green light on all other off
digitalWrite(Relay1, LOW); //Red Light
digitalWrite(Relay2, LOW); //Yellow Light
digitalWrite(Relay3, HIGH); //Green Light
digitalWrite(Relay4, LOW); //Spare Relay
}
else if (serialin == '1'){
// green light with timer to turn on Red Light if no input to rest timer
digitalWrite(Relay1, LOW); //Red Light
digitalWrite(Relay2, LOW); //Yellow Light
digitalWrite(Relay3, HIGH); //Green Light
digitalWrite(Relay4, LOW); //Spare Relay
delay(1000);
// Red light ON Green Light Off timed out
digitalWrite(Relay2, LOW); //Green Light
digitalWrite(Relay1, HIGH);} //Red Light
else if (serialin == '2'){
// the yellow light end of cycle
digitalWrite(Relay1, LOW); //Red Light
digitalWrite(Relay2, HIGH); //Yellow Light
digitalWrite(Relay3, LOW); //Green Light
digitalWrite(Relay4, LOW);} //Spare Relay
else if (serialin == '3'){
// the Red Light Mainence Needed cycle
digitalWrite(Relay1, HIGH); //Spare Light
digitalWrite(Relay2, LOW); //Yellow Light
digitalWrite(Relay3, LOW); //Green Light
digitalWrite(Relay4, LOW); } //Red Light
Serial.println(serialin);
}
}