-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmulltisesor_Day7.ino
111 lines (93 loc) · 2.4 KB
/
mulltisesor_Day7.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "DHT.h"
#include <Wire.h>
#include <BH1750.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
const int trigPin = 12;
const int echoPin = 13 ;
#define DHTPIN 2
#define SOUND_SPEED 0.033
#define DHTTYPE DHT11
#define seaLevelPressure_hPa 1013.25
BH1750 lightMeter;
DHT dht(DHTPIN, DHTTYPE);
long duration;
float distanceCm;
Adafruit_BMP085 bmp;
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);
if (!mpu.begin()) {
Serial.println("Sensor init failed");
while (1)
}
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.begin(115200);
if (!bmp.begin()) {
Serial.println("BMP180 Not Found. CHECK CIRCUIT!");
while (1) {}
}
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
float h = dht.readHumidity();
float t = dht.readTemperature();
//Ultrasonic
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * SOUND_SPEED/2;
Serial.print("Distance (cm): ");
Serial.println(distanceCm);
//DHT
Serial.print("Humidity:");
Serial.print(h);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print("\n");
//light sensor
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
//Accelerometer
Serial.print(a"Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
//Gyroscope
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
//Pressure
Serial.print("Pressure = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
//Crash sensor
int val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(ledPin, LOW);
} else {
digitalWrite(ledPin, HIGH);
Serial.println("Switch Pressed!");
}
delay(500);
}