-
Notifications
You must be signed in to change notification settings - Fork 0
/
sideStandAutomation.ino
42 lines (36 loc) · 959 Bytes
/
sideStandAutomation.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <Servo.h>
Servo myservo; // initialising servo motor
int sensor = 4; // tilt sensor as input pin
int LED = 13; // led as output pin
boolean switchState = false;
int sensorState=0; // Setting current state as 0
void openStand()
{
myservo.write(110); // Function to open bike stand
}
void closeStand()
{
myservo.write(20); // Function to close the bike stand
}
void setup()
{
pinMode(sensor, INPUT);
digitalWrite(sensor, HIGH); //set the sensor as HIGH
pinMode(LED, OUTPUT);
myservo.attach(LED);
myservo.write(15);
}
void loop()
{
sensorState=digitalRead(sensor); //read value of the sensor either high or low
if(sensorState==LOW) //when tilt switch lays flat
{
//digitalWrite(LED,HIGH);
closeStand();
}
else
{
//digitalWrite(LED, LOW); //when switch tilt on some angle
openStand();
}
}