Skip to content

Instantly share code, notes, and snippets.

@sandipndev
Last active June 27, 2019 11:06
Show Gist options
  • Save sandipndev/4e6caf7d4b7322472561e9d145eb6dd3 to your computer and use it in GitHub Desktop.
Save sandipndev/4e6caf7d4b7322472561e9d145eb6dd3 to your computer and use it in GitHub Desktop.
Arduino Code to work with two channels of Relay
int lightPin = 6;
int fanPin = 7;
void setup() {
pinMode(fanPin, OUTPUT);
pinMode(lightPin, OUTPUT);
digitalWrite(fanPin, HIGH);
digitalWrite(lightPin, HIGH);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
int data = (int) Serial.read();
if (data == 49) // data sent = 1
digitalWrite(lightPin, LOW);
else if (data == 50) // data sent = 2
digitalWrite(lightPin, HIGH);
else if (data == 51) // data sent = 3
digitalWrite(fanPin, LOW);
else if (data == 52) // data sent = 4
digitalWrite(fanPin, HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment