0% found this document useful (0 votes)
12 views

Code Snippet 1

This Arduino code controls 3 light bulbs (Bulb1, Bulb2, Bulb3) and an LED. It defines the pins for the bulbs and LED, sets their initial states, and includes functions to receive SMS commands via serial communication and toggle the bulb and LED states accordingly. Commands like "bulb1 on", "all off", etc. are parsed from the received SMS and used to control the outputs.

Uploaded by

ahmed salem
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Code Snippet 1

This Arduino code controls 3 light bulbs (Bulb1, Bulb2, Bulb3) and an LED. It defines the pins for the bulbs and LED, sets their initial states, and includes functions to receive SMS commands via serial communication and toggle the bulb and LED states accordingly. Commands like "bulb1 on", "all off", etc. are parsed from the received SMS and used to control the outputs.

Uploaded by

ahmed salem
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Techatronic.

com
#define Bulb1 3
#define Bulb2 4
#define Bulb3 5
int temp=0,i=0;
int led=8;
char str[15];
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(Bulb1, OUTPUT);
pinMode(Bulb2, OUTPUT);
pinMode(Bulb3, OUTPUT);
digitalWrite(Bulb1,HIGH);
digitalWrite(Bulb2,HIGH);
digitalWrite(Bulb3,HIGH);
Serial.println("AT+CNMI=2,2,0,0,0");
delay(500);
Serial.println("AT+CMGF=1");
delay(1000);
}
void loop()
{
if(temp==1)
{
check();
temp=0;
i=0;
delay(1000);
}
}
void serialEvent()
{
while(Serial.available())
{
if(Serial.find("#A."))
{
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
while (Serial.available())
{
char inChar=Serial.read();
str[i++]=inChar;
if(inChar=='*')
{
temp=1;
return;
}
}
}
}
}
void check()
{
if(!(strncmp(str,"bulb1 on",8)))
{
digitalWrite(Bulb1, LOW);
delay(200);
}
else if(!(strncmp(str,"bulb1 off",9)))
{
digitalWrite(Bulb1, HIGH);
delay(200);
}
else if(!(strncmp(str,"bulb2 on",8)))
{
digitalWrite(Bulb2, LOW);
delay(200);
}
else if(!(strncmp(str,"bulb2 off",9)))
{
digitalWrite(Bulb2, HIGH);
delay(200);
}
else if(!(strncmp(str,"bulb3 on",8)))
{
digitalWrite(Bulb3, LOW);
delay(200);
}
else if(!(strncmp(str,"bulb3 off",9)))
{
digitalWrite(Bulb3, HIGH);
delay(200);
}
else if(!(strncmp(str,"all on",6)))
{
digitalWrite(Bulb1, LOW);
digitalWrite(Bulb2, LOW);
digitalWrite(Bulb3, LOW);
delay(200);
}
else if(!(strncmp(str,"all off",7)))
{
digitalWrite(Bulb1, HIGH);
digitalWrite(Bulb2, HIGH);
digitalWrite(Bulb3, HIGH);
delay(200);
}
}

You might also like