-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino_code.ino
53 lines (46 loc) · 1.12 KB
/
arduino_code.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
#include <SoftwareSerial.h>
const int buttonPin = 2; // the number of the pushbutton pin
// the number of the LED pin
// variables will change:
int buttonState = 0;
SoftwareSerial BTserial(10, 11); // RX | TX
#include "DHT.h"
#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
pinMode(buttonPin,INPUT);
BTserial.begin(9600);
dht.begin();
}
void loop()
{
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
BTserial.print("Accident ");
}
else {
// turn LED off:
BTserial.print(" Safe ");
}
readSensor();
delay(5000);
}
void readSensor() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
BTserial.println("Failed to read from DHT sensor!");
return;
}
float hic = dht.computeHeatIndex(t, h, false);
BTserial.print("Temperature: ");
BTserial.print(t);
BTserial.print(" *C ");
BTserial.print("Heat index: ");
BTserial.print(hic);
BTserial.print(" *C ");
BTserial.print("\n");
}