Arduino code:
#define fan 2
#define light 3
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(fan, OUTPUT);
pinMode(light, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() == 1)
{
String val = Serial.readString();
Serial.println(val);
if(val == "fan on")
{
digitalWrite(fan, HIGH);
}
if(val == "fan off")
{
digitalWrite(fan, LOW);
}
if(val == "lights on")
{
digitalWrite(lights, HIGH);
}
if(val == "lights off")
{
digitalWrite(light, LOW);
}
if(val == "all on")
{
digitalWrite(fan, HIGH);
digitalWrite(light, HIGH);
}
if(val == "all off")
{
digitalWrite(light, LOW);
digitalWrite(fan, LOW);
}
}
}
4 Comments
Thanks
ReplyDeleteSir I have a doubt-Can we upload Arduino Uno code in Arduino Nano
ReplyDeleteCir can you reply as fast as you can I have a project to do,And time is less
DeleteBro when I compile code is showing error 😟what can I do
ReplyDelete