-
Notifications
You must be signed in to change notification settings - Fork 0
/
sense_all.ino
99 lines (86 loc) · 2.21 KB
/
sense_all.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
#include <PID_v1.h>
#include <Time.h>
#include <DHT.h>
#include <DS1307RTC.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "max6675.h"
//initialize sensors with i2c or spi or wire protocol
#define DHTPIN 4 // DHT 22 PIN
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;
int thermoDO = 12;
int thermoCS = 5;
int thermoCLK = 13;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
//initialize IRQ for measuring motor speed
volatile int IRQcount;
int pin_irq0 = 0; //IRQ that matches to pin 2
int pin_irq1 = 1; //IRQ that matches to pin 3
//Define PID
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor!");
while (1) {}
}
dht.begin();
attachInterrupt(pin_irq0, IRQcounter, RISING);
attachInterrupt(pin_irq1, IRQcounter, RISING);
}
void IRQcounter() {
IRQcount++;
}
void loop() {
// put your main code here, to run repeatedly:
tmElements_t tm;
if (RTC.read(tm)) {
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(" ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.print("\t");
}
Serial.print(bmp.readTemperature());
Serial.print("\t");
Serial.print(bmp.readPressure());
Serial.print("\t");
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
// Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print(h);
Serial.print("\t");
Serial.print(t);
Serial.print("\t");
Serial.print(thermocouple.readCelsius());
cli();//disable interrupts
IRQcount = 0;
sei();//enable interrupts
delay(500);
cli();//disable interrupts
int result = IRQcount*15;
sei();//enable interrupts
Serial.print("\t");
Serial.println(result);
delay(300);
}
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}