Tuesday, May 3, 2016

Arduino Servo Light Switch

This is a light switch servo that turn off the light temperately. Eventually I'll put a motion sensor that will turn the lights on when I walk in a room.



Here is the code:



#include <Servo.h>

Servo myservo; 

int switchpin = 13;
int val = 0;  

void setup()
{
  myservo.attach(9); 
}

void loop()
{
  val = digitalRead(switchpin);     

if (val == HIGH){
 myservo.write(70);
 delay(2000);
}
else myservo.write(1);
}

This is the video: