mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-06-26 16:21:33 +02:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
c270cda600 | |||
0753a4c9dd | |||
1a5ac64aa1 | |||
f170404c03 | |||
16a29b4646 | |||
bb3c57297e | |||
89e1d35a49 | |||
4f8bd0dbee | |||
ccfe271f0d |
@ -11,7 +11,7 @@
|
||||
#include <SoftwareSerial.h>
|
||||
#include "Arduino.h"
|
||||
#include <Wire.h>
|
||||
#include <Math.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
// Constructor /////////////////////////////////////////////////////////////////
|
||||
|
BIN
AirGradient.zip
BIN
AirGradient.zip
Binary file not shown.
@ -3,6 +3,6 @@ AirGradient Arduino Library for ESP8266 (Wemos D1 MINI)
|
||||
|
||||
Build your own low cost air quality sensor with optional display measuring PM2.5, CO2, Temperature and Humidity.
|
||||
|
||||
This library makes it easy to read the sensor data from the Plantower PMS5003 PM2.5 sensor, the Senseair S8 and the SHT30/31 Temperature and Humidity sensor. Visit our blog for detailed build instructions and PCB layout.
|
||||
This library makes it easy to read the sensor data from the Plantower PMS5003 PM2.5 sensor, the Senseair S8 and the SHT30/31 Temperature and Humidity sensor. Visit our DIY section for detailed build instructions and PCB layout.
|
||||
|
||||
https://www.airgradient.com/blog/
|
||||
https://www.airgradient.com/diy/
|
||||
|
BIN
examples/C02_PM_SHT/.DS_Store
vendored
BIN
examples/C02_PM_SHT/.DS_Store
vendored
Binary file not shown.
@ -1,26 +0,0 @@
|
||||
#include <AirGradient.h>
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
ag.PMS_Init();
|
||||
ag.CO2_Init();
|
||||
ag.TMP_RH_Init(0x44); //check for SHT sensor with address 0x44
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
Serial.print("PM2: ");
|
||||
Serial.println(ag.getPM2());
|
||||
|
||||
|
||||
Serial.print("CO2: ");
|
||||
Serial.println(ag.getCO2());
|
||||
|
||||
TMP_RH result = ag.periodicFetchData();
|
||||
Serial.print("Humidity: ");
|
||||
Serial.print(result.rh);
|
||||
Serial.print(" Temperature: ");
|
||||
Serial.println(result.t);
|
||||
delay(5000);
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#include <AirGradient.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
AirGradient ag = AirGradient();
|
||||
#define OLED_RESET 0
|
||||
Adafruit_SSD1306 display(OLED_RESET);
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||
ag.PMS_Init();
|
||||
ag.CO2_Init();
|
||||
ag.TMP_RH_Init(0x44); //check for SHT sensor with address 0x44
|
||||
showTextRectangle("Init", String(ESP.getChipId(),HEX),"AirGradient");
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
int PM2 = ag.getPM2_Raw();
|
||||
int CO2 = ag.getCO2_Raw();
|
||||
TMP_RH result = ag.periodicFetchData();
|
||||
showTextRectangle(String(result.t)+"c "+String(result.rh)+"%", "PM2: "+ String(ag.getPM2()), "CO2: "+String(ag.getCO2())+"");
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
// DISPLAY
|
||||
void showTextRectangle(String ln1, String ln2, String ln3) {
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(32,8);
|
||||
display.println(ln1);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(32,16);
|
||||
display.println(ln2);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(32,24);
|
||||
display.println(ln3);
|
||||
display.display();
|
||||
}
|
@ -1,77 +1,141 @@
|
||||
/*
|
||||
This is the code for the AirGradient DIY Air Quality Sensor with an ESP8266 Microcontroller.
|
||||
|
||||
It is a high quality sensor showing PM2.5, CO2, Temperature and Humidity on a small display and can send data over Wifi.
|
||||
|
||||
For build instructions please visit https://www.airgradient.com/diy/
|
||||
|
||||
Compatible with the following sensors:
|
||||
Plantower PMS5003 (Fine Particle Sensor)
|
||||
SenseAir S8 (CO2 Sensor)
|
||||
SHT30/31 (Temperature/Humidity Sensor)
|
||||
|
||||
Please install ESP8266 board manager (tested with version 3.0.0)
|
||||
|
||||
The codes needs the following libraries installed:
|
||||
"WifiManager by tzapu, tablatronix" tested with Version 2.0.3-alpha
|
||||
"ESP8266 and ESP32 OLED driver for SSD1306 displays by ThingPulse, Fabrice Weinberg" tested with Version 4.1.0
|
||||
|
||||
Configuration:
|
||||
Please set in the code below which sensor you are using and if you want to connect it to WiFi.
|
||||
|
||||
If you are a school or university contact us for a free trial on the AirGradient platform.
|
||||
https://www.airgradient.com/schools/
|
||||
|
||||
MIT License
|
||||
*/
|
||||
|
||||
#include <AirGradient.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
|
||||
AirGradient ag = AirGradient();
|
||||
#define OLED_RESET 0
|
||||
Adafruit_SSD1306 display(OLED_RESET);
|
||||
#include <Wire.h>
|
||||
#include "SSD1306Wire.h"
|
||||
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
SSD1306Wire display(0x3c, SDA, SCL);
|
||||
|
||||
// set sensors that you do not use to false
|
||||
boolean hasPM=true;
|
||||
boolean hasCO2=true;
|
||||
boolean hasSHT=true;
|
||||
|
||||
// set to true if you want to connect to wifi. The display will show values only when the sensor has wifi connection
|
||||
boolean connectWIFI=false;
|
||||
|
||||
// change if you want to send the data to another server
|
||||
String APIROOT = "http://hw.airgradient.com/";
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||
ag.PMS_Init();
|
||||
ag.CO2_Init();
|
||||
ag.TMP_RH_Init(0x44); //check for SHT sensor with address 0x44
|
||||
showTextRectangle("Init", String(ESP.getChipId(),HEX),"AirGradient");
|
||||
connectToWifi();
|
||||
|
||||
display.init();
|
||||
display.flipScreenVertically();
|
||||
showTextRectangle("Init", String(ESP.getChipId(),HEX),true);
|
||||
|
||||
if (hasPM) ag.PMS_Init();
|
||||
if (hasCO2) ag.CO2_Init();
|
||||
if (hasSHT) ag.TMP_RH_Init(0x44);
|
||||
|
||||
if (connectWIFI) connectToWifi();
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
int PM2 = ag.getPM2_Raw();
|
||||
int CO2 = ag.getCO2_Raw();
|
||||
TMP_RH result = ag.periodicFetchData();
|
||||
showTextRectangle(String(result.t)+"c "+String(result.rh)+"%", "PM2: "+ String(PM2), "CO2: "+String(CO2)+"");
|
||||
|
||||
|
||||
// create payload
|
||||
|
||||
String payload = "{\"wifi\":" + String(WiFi.RSSI()) + ",";
|
||||
|
||||
if (hasPM) {
|
||||
int PM2 = ag.getPM2_Raw();
|
||||
payload=payload+"\"pm02\":" + String(PM2);
|
||||
showTextRectangle("PM2",String(PM2),false);
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
if (hasCO2) {
|
||||
if (hasPM) payload=payload+",";
|
||||
int CO2 = ag.getCO2_Raw();
|
||||
payload=payload+"\"rco2\":" + String(CO2);
|
||||
showTextRectangle("CO2",String(CO2),false);
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
if (hasSHT) {
|
||||
if (hasCO2 || hasPM) payload=payload+",";
|
||||
TMP_RH result = ag.periodicFetchData();
|
||||
payload=payload+"\"atmp\":" + String(result.t) + ",\"rhum\":" + String(result.rh);
|
||||
showTextRectangle(String(result.t),String(result.rh)+"%",false);
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
payload=payload+"}";
|
||||
|
||||
// send payload
|
||||
String payload = "{\"pm02\":" + String(ag.getPM2()) + ",\"wifi\":" + String(WiFi.RSSI()) + ",\"rco2\":" + String(ag.getCO2()) + ",\"atmp\":" + String(result.t) + ",\"rhum\":" + String(result.rh) + "}";
|
||||
if (connectWIFI){
|
||||
Serial.println(payload);
|
||||
String POSTURL = APIROOT + "sensors/airgradient:" + String(ESP.getChipId(),HEX) + "/measures";
|
||||
Serial.println(POSTURL);
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
http.begin(POSTURL);
|
||||
http.begin(client, POSTURL);
|
||||
http.addHeader("content-type", "application/json");
|
||||
int httpCode = http.POST(payload);
|
||||
String response = http.getString();
|
||||
Serial.println(httpCode);
|
||||
Serial.println(response);
|
||||
http.end();
|
||||
|
||||
delay(15000);
|
||||
}
|
||||
}
|
||||
|
||||
// DISPLAY
|
||||
void showTextRectangle(String ln1, String ln2, String ln3) {
|
||||
display.clearDisplay();
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(32,8);
|
||||
display.println(ln1);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(32,16);
|
||||
display.println(ln2);
|
||||
display.setTextSize(1);
|
||||
display.setCursor(32,24);
|
||||
display.println(ln3);
|
||||
void showTextRectangle(String ln1, String ln2, boolean small) {
|
||||
display.clear();
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
if (small) {
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
} else {
|
||||
display.setFont(ArialMT_Plain_24);
|
||||
}
|
||||
display.drawString(32, 16, ln1);
|
||||
display.drawString(32, 36, ln2);
|
||||
display.display();
|
||||
}
|
||||
|
||||
// Wifi Manager
|
||||
void connectToWifi(){
|
||||
WiFiManager wifiManager;
|
||||
//chWiFi.disconnect(); //to delete previous saved hotspot
|
||||
//WiFi.disconnect(); //to delete previous saved hotspot
|
||||
String HOTSPOT = "AIRGRADIENT-"+String(ESP.getChipId(),HEX);
|
||||
wifiManager.setTimeout(120);
|
||||
if(!wifiManager.autoConnect((const char*)HOTSPOT.c_str())) {
|
||||
//Serial.println("failed to connect and hit timeout");
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(3000);
|
||||
ESP.restart();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
34
examples/C02_SIMPLE/C02_SIMPLE.ino
Normal file
34
examples/C02_SIMPLE/C02_SIMPLE.ino
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
This is the code for the AirGradient DIY Air Quality Sensor with an ESP8266 Microcontroller.
|
||||
|
||||
It is a high quality sensor showing PM2.5, CO2, Temperature and Humidity on a small display and can send data over Wifi.
|
||||
|
||||
For build instructions please visit https://www.airgradient.com/diy/
|
||||
|
||||
Compatible with the following sensors:
|
||||
SenseAir S8 (CO2 Sensor)
|
||||
|
||||
Please install ESP8266 board manager (tested with version 3.0.0)
|
||||
|
||||
If you are a school or university contact us for a free trial on the AirGradient platform.
|
||||
https://www.airgradient.com/schools/
|
||||
|
||||
MIT License
|
||||
*/
|
||||
|
||||
#include <AirGradient.h>
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
ag.CO2_Init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
int CO2 = ag.getCO2_Raw();
|
||||
Serial.print("C02: ");
|
||||
Serial.println(ag.getCO2());
|
||||
|
||||
delay(5000);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#include <AirGradient.h>
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
ag.CO2_Init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
int CO2 = ag.getCO2_Raw();
|
||||
Serial.print("C02: ");
|
||||
Serial.println(ag.getCO2());
|
||||
|
||||
delay(5000);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#include <AirGradient.h>
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
ag.MHZ19_Init(MHZ19B);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
int MHZ19_C02 = ag.readMHZ19();
|
||||
Serial.print("C02: ");
|
||||
Serial.println(MHZ19_C02);
|
||||
|
||||
delay(5000);
|
||||
}
|
34
examples/PM2_SIMPLE/PM2_SIMPLE.ino
Normal file
34
examples/PM2_SIMPLE/PM2_SIMPLE.ino
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
This is the code for the AirGradient DIY Air Quality Sensor with an ESP8266 Microcontroller.
|
||||
|
||||
It is a high quality sensor showing PM2.5, CO2, Temperature and Humidity on a small display and can send data over Wifi.
|
||||
|
||||
For build instructions please visit https://www.airgradient.com/diy/
|
||||
|
||||
Compatible with the following sensors:
|
||||
Plantower PMS5003 (Fine Particle Sensor)
|
||||
|
||||
Please install ESP8266 board manager (tested with version 3.0.0)
|
||||
|
||||
If you are a school or university contact us for a free trial on the AirGradient platform.
|
||||
https://www.airgradient.com/schools/
|
||||
|
||||
MIT License
|
||||
*/
|
||||
|
||||
#include <AirGradient.h>
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
ag.PMS_Init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
int PM2 = ag.getPM2_Raw();
|
||||
Serial.print("PM2: ");
|
||||
Serial.println(ag.getPM2());
|
||||
|
||||
delay(5000);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#include <AirGradient.h>
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
ag.PMS_Init();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
int PM2 = ag.getPM2_Raw();
|
||||
Serial.print("PM2: ");
|
||||
Serial.println(ag.getPM2());
|
||||
|
||||
delay(5000);
|
||||
}
|
34
examples/SHT_SIMPLE/SHT_SIMPLE.ino
Normal file
34
examples/SHT_SIMPLE/SHT_SIMPLE.ino
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
This is the code for the AirGradient DIY Air Quality Sensor with an ESP8266 Microcontroller.
|
||||
|
||||
It is a high quality sensor showing PM2.5, CO2, Temperature and Humidity on a small display and can send data over Wifi.
|
||||
|
||||
For build instructions please visit https://www.airgradient.com/diy/
|
||||
|
||||
Compatible with the following sensors:
|
||||
SHT30/31 (Temperature/Humidity Sensor)
|
||||
|
||||
Please install ESP8266 board manager (tested with version 3.0.0)
|
||||
|
||||
If you are a school or university contact us for a free trial on the AirGradient platform.
|
||||
https://www.airgradient.com/schools/
|
||||
|
||||
MIT License
|
||||
*/
|
||||
|
||||
#include <AirGradient.h>
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
ag.TMP_RH_Init(0x44); //check for SHT sensor with address 0x44
|
||||
}
|
||||
|
||||
void loop(){
|
||||
TMP_RH result = ag.periodicFetchData();
|
||||
Serial.print("Humidity: ");
|
||||
Serial.print(result.rh_char);
|
||||
Serial.print(" Temperature: ");
|
||||
Serial.println(result.t_char);
|
||||
delay(5000);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#include <AirGradient.h>
|
||||
AirGradient ag = AirGradient();
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
ag.TMP_RH_Init(0x44); //check for SHT sensor with address 0x44
|
||||
}
|
||||
|
||||
void loop(){
|
||||
TMP_RH result = ag.periodicFetchData();
|
||||
Serial.print("Humidity: ");
|
||||
Serial.print(result.rh_char);
|
||||
Serial.print(" Temperature: ");
|
||||
Serial.println(result.t_char);
|
||||
delay(5000);
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
name=AirGradient Air Quality Sensor
|
||||
version=1.0.0
|
||||
version=1.3.5
|
||||
author=AirGradient <support@airgradient.com>
|
||||
maintainer=AirGradient <support@airgradient.com>
|
||||
sentence=ESP8266 library for an air quality sensor featuring PM2.5, CO2, Temperature and Humidity with OLED display.
|
||||
paragraph=The library is very robust and works with the Plantower PMS5003 particle sensor, the Senseair S8 CO2 sensor and the SHT30/31 sensor for humidity and temperature. You can also connect an OLED display or send the air quality data to the AirGradient platform or any other backend.
|
||||
category=Sensors
|
||||
url=https://github.com/airgradienthq/arduino
|
||||
architectures=*
|
||||
architectures=*
|
||||
|
41
readme.txt
41
readme.txt
@ -1,39 +1,8 @@
|
||||
This is an example C++ library for Arduino 0004+, based on one created by
|
||||
Nicholas Zambetti for Wiring 0006+
|
||||
AirGradient Arduino Library for ESP8266 (Wemos D1 MINI)
|
||||
=====================================================================================================
|
||||
|
||||
Installation
|
||||
--------------------------------------------------------------------------------
|
||||
Build your own low cost air quality sensor with optional display measuring PM2.5, CO2, Temperature and Humidity.
|
||||
|
||||
To install this library, just place this entire folder as a subfolder in your
|
||||
Arduino/lib/targets/libraries folder.
|
||||
|
||||
When installed, this library should look like:
|
||||
|
||||
Arduino/lib/targets/libraries/Test (this library's folder)
|
||||
Arduino/lib/targets/libraries/Test/Test.cpp (the library implementation file)
|
||||
Arduino/lib/targets/libraries/Test/Test.h (the library description file)
|
||||
Arduino/lib/targets/libraries/Test/keywords.txt (the syntax coloring file)
|
||||
Arduino/lib/targets/libraries/Test/examples (the examples in the "open" menu)
|
||||
Arduino/lib/targets/libraries/Test/readme.txt (this file)
|
||||
|
||||
Building
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
After this library is installed, you just have to start the Arduino application.
|
||||
You may see a few warning messages as it's built.
|
||||
|
||||
To use this library in a sketch, go to the Sketch | Import Library menu and
|
||||
select Test. This will add a corresponding line to the top of your sketch:
|
||||
#include <Test.h>
|
||||
|
||||
To stop using this library, delete that line from your sketch.
|
||||
|
||||
Geeky information:
|
||||
After a successful build of this library, a new file named "Test.o" will appear
|
||||
in "Arduino/lib/targets/libraries/Test". This file is the built/compiled library
|
||||
code.
|
||||
|
||||
If you choose to modify the code for this library (i.e. "Test.cpp" or "Test.h"),
|
||||
then you must first 'unbuild' this library by deleting the "Test.o" file. The
|
||||
new "Test.o" with your code will appear after the next press of "verify"
|
||||
This library makes it easy to read the sensor data from the Plantower PMS5003 PM2.5 sensor, the Senseair S8 and the SHT30/31 Temperature and Humidity sensor. Visit our DIY section for detailed build instructions and PCB layout.
|
||||
|
||||
https://www.airgradient.com/diy/
|
||||
|
Reference in New Issue
Block a user