-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcs project
62 lines (60 loc) · 1.67 KB
/
tcs project
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Servo.h>
int value = 0;
int avg_value = 0;
int sensorPin = A5; //connect ir receiver output to this pin
int buttonPin = 18; // button pin to A4
boolean buttonState = HIGH;
boolean sanitiserState = LOW;
int ledPin = 13; //this is for testing purpose
int sanitisertank = 0;
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(buttonPin, HIGH);
//servo motor is connected to Arduino digital pin 3
myservo.attach(3);
}
void loop() {
buttonState = digitalRead(buttonPin);
delay(50);
if(buttonState==LOW && tapState==LOW){
digitalWrite(ledPin, HIGH);
myservo.write(0);
delay(7000);
sanitisertankState = HIGH;
sanitisertank = 1; // check either tap was on for button press or not
}
else if(buttonState==LOW && sanitisertank1==HIGH && sanitisertank==1){
digitalWrite(ledPin, LOW);
myservo.write(80);
delay(100);
sanitisertank1 = LOW;
sanitisertank = 0;
}
// put your main code here, to run repeatedly:
for(int i=0; i<20; i++){
value += analogRead(sensorPin);
delay(5);
}
avg_value = value / 20;
Serial.println(avg_value);
if(avg_value<=500){
digitalWrite(ledPin, HIGH);
myservo.write(0);
delay(7000);
sanitisertank1 = HIGH;
if(sanitisertank==0)
sanitisertank = 2; // check sanitisercrane was on using sensor data
}
if(avg_value>500 && sanitisertank==2){
digitalWrite(ledPin, LOW);
myservo.write(80);
delay(100);
tapState = LOW;
}
value = 0;
}