-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code: Combined Sensors
96 lines (75 loc) · 2.36 KB
/
Code: Combined Sensors
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
#include <ParticleSoftSerial.h> //Dust Sensor
#include <Arduino.h> //Implementing Arduino
#include <Adafruit_DHT.h> //DHT22
#include "Adafruit_SSD1306.h" //OLED Display
#define ADDR_6713 0x15 // default I2C slave address
#define DHTPIN 2 //Assign Pin to DHT22
#define DHTTYPE DHT22 // default the DHT pins
#define OLED_DC D3 // use hardware SPI
#define OLED_CS D4
#define OLED_RESET D5
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
int data [4];
int CO2ppmValue;
int temperature;
int humidity;
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
dht.begin();
Wire.begin ();
display.clearDisplay();
Serial.begin(9600);
// Serial.println("Application Note AN161_ardunio_T6713_I2C");
}
int readC02()
{
Wire.beginTransmission(ADDR_6713);
Wire.write(0x04); Wire.write(0x13); Wire.write(0x8B);
Wire.write(0x00); Wire.write(0x01);
Wire.endTransmission();
delay(2000);
Wire.requestFrom(ADDR_6713, 4);
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
CO2ppmValue = ((data[2] * 0xFF ) + data[3]);
}
void loop() {
int co2Value = readC02();
//Display Settings
display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
//Display temperature
display.setCursor(15, 8);
display.println("Temp: " + String(temperature) + "*C,");
//Display humidity
display.setCursor(15, 20);
display.println("Humidity: " + String(humidity) + "%");
//Display c02
display.setCursor(15, 30);
display.println("CO2: " + String(co2Value) + " ppm");
display.setCursor(15, 40);
// display.println("Particles: " + String(PM2_5Value) + " ug/m3");
display.display();
//Publish console
Particle.publish("gas", String(co2Value) + " ppm");
Particle.publish ("gas",String(co2Value), PRIVATE);
delay(2000);
temperature = dht.getTempCelcius();
humidity = dht.getHumidity();
Particle.publish("temp", String(temperature) + " °C");
Particle.publish("humidity", String(humidity) + "%");
delay(2000);
// Particle.publish("Particles: ", String(PM2_5Value) + " ug/m3");
// delay(2000);
}