You are on page 1of 3

MICROPROCESSOR

EXPERIMENT NO. 20 : Automatic Door Opener


Connection:

Coding:
#include <Servo.h>
const int buttonPin=2;
int led1=3;
int led2=4;
int buttonState;
const int servoPin=9;
int pos=180;
Servo myservo;
void setup(){
Serial.begin(9600);
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
myservo.attach(servoPin);
myservo.write(0);
}
void loop(){
buttonState = digitalRead(buttonPin);
if(buttonState == LOW){
MICROPROCESSOR

Serial.println("OPEN");
myservo.write(pos);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
}
else{
Serial.println("CLOSE");
myservo.write(0);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
}
delay(1000);
}
MICROPROCESSOR

You might also like