/*
LEVEL CROSING over bluetooth
BY AREEB-UR-RUB
WEBSITE :- http://areeburrub.page.tl
*/
//
#include <Servo.h>
Servo myservo1;// create servo object to control a servo
// twelve servo objects can be created on most boards
void setup() {//setup code start here
Serial.begin(9600);//Initialize serial port
myservo1.attach(9);// attaches the servo on pin 9 to the servo object
pinMode(13,OUTPUT);//set pin number 13 for RED light
pinMode(12,OUTPUT);//set pin number 12 for GREEN light
//I am using a bi-color LED
//so by merging green and red i got a yellowish color
}//setup code end here here
void loop() {//loop code start here
int s = Serial.read();// read the oldest byte in the serial buffer
//----------------------OPEN_CODE_START_HERE---------------------------------
if (s=='o')//if serial read letter 'o'
{
Serial.println("opened the door");//it will print the messege on the serial screen
//---------- BI-color LED(yellow) -------------
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
delay(600);//it remain yellow for 600 milli-second
//1000 mili-second is equal to 1 second
//as I am using bi-color led i turend off the red color
//---------- BI-color LED(green) -------------
// because the door is open the led is green
digitalWrite(13,LOW);
//--------------seting the servo angel--------
myservo1.write(180);//it's angel is 180 degrees
//you can change it's angel as your need
delay(15);//time taken to close the door
}
//------------------------OPEN_CODE_END_HERE---------------------------------
//----------------------CLOSE_CODE_START_HERE---------------------------------
else if (s=='c'){
Serial.println("closed the door");//it will print the messege on the serial screen
//---------- BI-color LED(yellow) -------------
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
delay(600);//it remain yellow for 600 milli-second
//1000 mili-second is equal to 1 second
//as I am using bi-color led i turend off the green color
//---------- BI-color LED(RED) -------------
// because the door is close the led is red
digitalWrite(12,LOW);
//--------------seting the servo angel--------
myservo1.write(90);//it's angel is 180 degrees
//you can change it's angel as your need
delay(15);//time taken to close the door
}
//------------------------CLOSE_CODE_END_HERE---------------------------------
}//loop ends here
|