4 Channel Relay
byte RelayPins[4] = {8,7,2,4};
char Input[1];
void setup()
{
for(int i = 0; i < 4; i++) pinMode(RelayPins[i],OUTPUT);
Serial.begin(9600);
delay(100);
Serial.println("4ChannelRelayTesting");
Serial.println("Enter Number 0 to 3 Respectively");
for(int j = 0; j < 4; j++) digitalWrite(RelayPins[j],LOW);
}
void loop()
{
String Status;
if (Serial.available())
{
Serial.readBytesUntil(13, Input, 2);
int State = Input[1] - 48;
int RelayNum = Input[0]-48;
if((State == 0) || (State == 1))
{
digitalWrite(RelayPins[RelayNum], State);
}
else
{
Serial.println("Incorrect parameter");
}
Status=String("Relay")+String(RelayNum)+String("State is set to")+String(State);
Serial.println(Status);
}
}
Comments