-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project_UltrasonicSensorTempHum.ino
52 lines (43 loc) · 1.27 KB
/
Project_UltrasonicSensorTempHum.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
#include <DHT.h>
#include <Wire.h>
#include <Ultrasonic.h> //import ultrosonic library
#include <LiquidCrystal.h> //import LCD library
#define DHTPIN A0
Ultrasonic ultrasonic(2,3); //Register ultrasonic sensor with interface pins trig:2, echo:3
LiquidCrystal lcd(0,1,8,9,10,11); //Register the LCD with interface pins RS:0, E:1, D4:8, D5:9, D6:10, D7:11
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
//setup the LCD's number of columns and rows
lcd.begin(16,2);
dht.begin();
}
void loop() {
//take a measurement and display it on the LCD
delay(500);
lcd.clear(); //Clears the screen in preparation of new measurement
lcd.setCursor(0,0);
lcd.print("H:");
float h = dht.readHumidity();
lcd.setCursor(0,1);
lcd.print("T:");
float f = dht.readTemperature(true);
if (isnan(h) || isnan(f)) {
lcd.print("ERROR");
}
lcd.setCursor(2,0);
lcd.print(h);
lcd.setCursor(7,0);
lcd.print("%");
lcd.setCursor(2,1);
lcd.print(f);
lcd.setCursor(7,1);
lcd.print("F");
lcd.setCursor(9,0);
lcd.print("D:"); //Prints the first line of the display
lcd.setCursor(11,0); //Takes measurement from US and prints it to LCD
lcd.print(ultrasonic.distanceRead()); //waits half a second
lcd.setCursor(14,0);
lcd.print("cm");
return;
}