Last active
June 27, 2019 11:06
-
-
Save sandipndev/4e6caf7d4b7322472561e9d145eb6dd3 to your computer and use it in GitHub Desktop.
Arduino Code to work with two channels of Relay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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