-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.ino
76 lines (59 loc) · 1.31 KB
/
robot.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// James C
// 2024-01-25
// Description: A self driving car that takes data like the temperature as it drives around and send it using bluetooth to the laptop, which usese python to anaylize the Data
#include <Servo.h>
#include "DHT.h"
Servo frservo;
Servo flservo;
Servo brservo;
Servo blservo;
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int trig = 4;
int echo = 3;
int pos = 0;
void setup() {
Serial.begin(9600);
analogReference(DEFAULT);
frservo.attach(9);
flservo.attach(6);
brservo.attach(10);
blservo.attach(11);
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
dht.begin();
}
void loop()
{
int dist = get_distance();
if(dist < 5)
{
while(dist < 5){
Serial.println("turn");
brservo.write(180);
frservo.write(180);
blservo.write(0);
flservo.write(0);
dist = get_distance();
}
}
else{
brservo.write(0);
blservo.write(180);
flservo.write(0);
frservo.write(180);
}
Serial.flush();
Serial.println("Temperature:" + String(dht.readTemperature()) );
Serial.println("Humidite: " + String(dht.readHumidity()));
}
int get_distance()
{
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
long time = pulseIn(echo,HIGH);
int distance = (time*0.034)/2;
return distance;
}