forked from saswatsamal/anticollider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheAntiCollider.ino
56 lines (48 loc) · 1.24 KB
/
TheAntiCollider.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
int trigPin = 9;
int echoPin = 10;
int ledRed = 11;
int ledGreen = 12;
int ledYellow = 7;
int motor = 8;
void setup() {
Serial.begin(9600);
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(motor, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(echoPin, INPUT);
// put your setup code here, to run once:
}
void loop() {
long duration, distance;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration=pulseIn(echoPin, HIGH);
distance =(duration/2)/29.1;
Serial.print(distance);
Serial.println("CM");
delay(10);
if((distance<=30))
{
digitalWrite(ledRed, HIGH);// turn the LED on (HIGH is the voltage level)
digitalWrite(ledGreen, LOW);
digitalWrite(motor, LOW);
digitalWrite(ledYellow, LOW);
}
else if(distance>30 and distance<49)
{
digitalWrite(ledRed, LOW);// turn the LED off by making the voltage LOW
digitalWrite(ledYellow, HIGH);
digitalWrite(ledGreen, LOW);
digitalWrite(motor, HIGH);
}
else if(distance>50)
{
digitalWrite(ledRed, LOW);// turn the LED off by making the voltage LOW
digitalWrite(ledYellow, LOW);
digitalWrite(ledGreen, HIGH);
digitalWrite(motor, HIGH);
}
}