Compare commits
No commits in common. 'f4c9f2a73d15489626c59a414613428f765c2730' and '4936461bb62ba482172f25889611ae0105cf78f6' have entirely different histories.
f4c9f2a73d
...
4936461bb6
4 changed files with 61 additions and 139 deletions
@ -1,39 +1,70 @@ |
|||||||
// https://www.youtube.com/watch?v=M-UKXCUI0rE&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=53
|
// https://www.youtube.com/watch?v=-AvF2TsB2GI&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=50
|
||||||
// https://www.youtube.com/watch?v=BTMMNsL0_b0&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=54
|
// https://www.youtube.com/watch?v=ep7uBz43fCI&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=51
|
||||||
// https://www.youtube.com/watch?v=2hwrDSVHQ-E&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=55
|
|
||||||
|
|
||||||
|
|
||||||
#include <Arduino.h> |
#include <Arduino.h> |
||||||
|
|
||||||
int trigPin = 12; |
#include <Adafruit_Sensor.h> |
||||||
int echoPin = 11; |
#include <DHT.h> |
||||||
int pingTravleTime; |
// #include <DHT_U.h>
|
||||||
float distance; |
|
||||||
const int pulsTime = 40; // uS
|
#include <LiquidCrystal.h> |
||||||
const float pingTimeToDistance = 0.017; // uS to cm, travletime[s] * 340 m/s / 2
|
|
||||||
|
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12; |
||||||
|
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); |
||||||
|
|
||||||
|
#define DHTTYPE DHT11 |
||||||
|
#define DHTPIN 2 |
||||||
|
|
||||||
|
DHT dht(DHTPIN, DHTTYPE); |
||||||
|
|
||||||
|
float humidity; |
||||||
|
float tempC; |
||||||
|
float tempF; |
||||||
|
|
||||||
|
int setTime = 500; |
||||||
|
int dt = 1000; |
||||||
|
|
||||||
|
|
||||||
void setup() { |
void setup() { |
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(9600); |
Serial.begin(9600); |
||||||
pinMode(trigPin, OUTPUT); |
Serial.println("DHT11 test!"); |
||||||
pinMode(echoPin, INPUT); |
|
||||||
|
dht.begin(); |
||||||
|
delay(setTime); |
||||||
|
|
||||||
|
lcd.begin(16, 2); |
||||||
|
lcd.print("Hello, World!"); |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
void loop() { |
void loop() { |
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
digitalWrite(trigPin, LOW); |
humidity = dht.readHumidity(); |
||||||
delayMicroseconds(pulsTime); |
tempC = dht.readTemperature(); |
||||||
digitalWrite(trigPin, HIGH); |
tempF = dht.readTemperature(true); |
||||||
delayMicroseconds(pulsTime); |
|
||||||
digitalWrite(trigPin, LOW); |
Serial.print("Humidity: "); |
||||||
pingTravleTime = pulseIn(echoPin, HIGH); |
Serial.print(humidity); |
||||||
delay(25); |
Serial.print(" Temperature: "); |
||||||
Serial.print("Ping Time: "); |
Serial.print(tempC); |
||||||
Serial.print(pingTravleTime); |
Serial.print(" *C "); |
||||||
|
Serial.print(tempF); |
||||||
distance = pingTravleTime * pingTimeToDistance; |
Serial.println(" *F"); |
||||||
Serial.print(" Distance: "); |
|
||||||
Serial.print(distance); |
lcd.clear(); |
||||||
Serial.println(" cm"); |
lcd.setCursor(0, 0); |
||||||
|
lcd.print("Humidity: "); |
||||||
|
lcd.print(humidity); |
||||||
|
lcd.print("%"); |
||||||
|
|
||||||
|
lcd.setCursor(0, 1); |
||||||
|
lcd.print("Temp: "); |
||||||
|
lcd.print(tempC); |
||||||
|
lcd.print("oC "); |
||||||
|
delay(dt); |
||||||
|
lcd.clear(); |
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
@ -1,70 +0,0 @@ |
|||||||
// https://www.youtube.com/watch?v=-AvF2TsB2GI&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=50
|
|
||||||
// https://www.youtube.com/watch?v=ep7uBz43fCI&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=51
|
|
||||||
|
|
||||||
|
|
||||||
#include <Arduino.h> |
|
||||||
|
|
||||||
#include <Adafruit_Sensor.h> |
|
||||||
#include <DHT.h> |
|
||||||
// #include <DHT_U.h>
|
|
||||||
|
|
||||||
#include <LiquidCrystal.h> |
|
||||||
|
|
||||||
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12; |
|
||||||
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); |
|
||||||
|
|
||||||
#define DHTTYPE DHT11 |
|
||||||
#define DHTPIN 2 |
|
||||||
|
|
||||||
DHT dht(DHTPIN, DHTTYPE); |
|
||||||
|
|
||||||
float humidity; |
|
||||||
float tempC; |
|
||||||
float tempF; |
|
||||||
|
|
||||||
int setTime = 500; |
|
||||||
int dt = 1000; |
|
||||||
|
|
||||||
|
|
||||||
void setup() { |
|
||||||
// put your setup code here, to run once:
|
|
||||||
Serial.begin(9600); |
|
||||||
Serial.println("DHT11 test!"); |
|
||||||
|
|
||||||
dht.begin(); |
|
||||||
delay(setTime); |
|
||||||
|
|
||||||
lcd.begin(16, 2); |
|
||||||
lcd.print("Hello, World!"); |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void loop() { |
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
humidity = dht.readHumidity(); |
|
||||||
tempC = dht.readTemperature(); |
|
||||||
tempF = dht.readTemperature(true); |
|
||||||
|
|
||||||
Serial.print("Humidity: "); |
|
||||||
Serial.print(humidity); |
|
||||||
Serial.print(" Temperature: "); |
|
||||||
Serial.print(tempC); |
|
||||||
Serial.print(" *C "); |
|
||||||
Serial.print(tempF); |
|
||||||
Serial.println(" *F"); |
|
||||||
|
|
||||||
lcd.clear(); |
|
||||||
lcd.setCursor(0, 0); |
|
||||||
lcd.print("Humidity: "); |
|
||||||
lcd.print(humidity); |
|
||||||
lcd.print("%"); |
|
||||||
|
|
||||||
lcd.setCursor(0, 1); |
|
||||||
lcd.print("Temp: "); |
|
||||||
lcd.print(tempC); |
|
||||||
lcd.print("oC "); |
|
||||||
delay(dt); |
|
||||||
lcd.clear(); |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,39 +0,0 @@ |
|||||||
// https://www.youtube.com/watch?v=M-UKXCUI0rE&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=53
|
|
||||||
// https://www.youtube.com/watch?v=BTMMNsL0_b0&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=54
|
|
||||||
// https://www.youtube.com/watch?v=2hwrDSVHQ-E&list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP&index=55
|
|
||||||
|
|
||||||
|
|
||||||
#include <Arduino.h> |
|
||||||
|
|
||||||
int trigPin = 12; |
|
||||||
int echoPin = 11; |
|
||||||
int pingTravleTime; |
|
||||||
float distance; |
|
||||||
const int pulsTime = 40; // uS
|
|
||||||
const float pingTimeToDistance = 0.017; // uS to cm, travletime[s] * 340 m/s / 2
|
|
||||||
|
|
||||||
void setup() { |
|
||||||
// put your setup code here, to run once:
|
|
||||||
Serial.begin(9600); |
|
||||||
pinMode(trigPin, OUTPUT); |
|
||||||
pinMode(echoPin, INPUT); |
|
||||||
} |
|
||||||
|
|
||||||
void loop() { |
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
digitalWrite(trigPin, LOW); |
|
||||||
delayMicroseconds(pulsTime); |
|
||||||
digitalWrite(trigPin, HIGH); |
|
||||||
delayMicroseconds(pulsTime); |
|
||||||
digitalWrite(trigPin, LOW); |
|
||||||
pingTravleTime = pulseIn(echoPin, HIGH); |
|
||||||
delay(25); |
|
||||||
Serial.print("Ping Time: "); |
|
||||||
Serial.print(pingTravleTime); |
|
||||||
|
|
||||||
distance = pingTravleTime * pingTimeToDistance; |
|
||||||
Serial.print(" Distance: "); |
|
||||||
Serial.print(distance); |
|
||||||
Serial.println(" cm"); |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue