-
Notifications
You must be signed in to change notification settings - Fork 7
/
multisensor_withoutpuskar.ino
55 lines (47 loc) · 1.18 KB
/
multisensor_withoutpuskar.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
#include "DHT.h"
#include <Wire.h>
#include <BH1750.h>
const int trigPin = 12;
const int echoPin = 13 ;
#define DHTPIN 2
#define SOUND_SPEED 0.033
#define DHTTYPE DHT11
BH1750 lightMeter;
DHT dht(DHTPIN, DHTTYPE);
long duration;
float distanceCm;
void setup() {
Serial.begin(115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Wire.begin();
lightMeter.begin();
Serial.println(F("BH1750 Test begin"));
Serial.begin(115200);
dht.begin();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
float h = dht.readHumidity();
float t = dht.readTemperature();
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * SOUND_SPEED/2;
Serial.print("Distance (cm): ");
Serial.println(distanceCm);
Serial.print("Humidity:");
Serial.print(h);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print("\n");
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(500);
}