Hardware components | ||||||
![]() |
| × | 3 | |||
![]() |
| × | 2 | |||
![]() |
| × | 3 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
![]() |
| |||||
Hand tools and fabrication machines | ||||||
![]() |
| |||||
![]() |
| |||||
![]() |
|
We wanted to build a mesh device that allowed one to take data from any location and compare that data quickly and easily.
Schematics
Red - VCC connects 3V3
Yellow - Data Pin to D2
Black - Ground
Here is a link to our youtube video about our project and how it works.
https://www.youtube.com/watch?v=S5I_8SrXTpQ
Link to our ThingSpeak page
Node Code
C/C++This code is for the sensor nodes. For the second node, change the "t"'s to a "g"'s, and the "h"'s to "j"'s. This is simply just to ensure that there is no conflict in the data the LCD screen on the hub will output.
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
// This example assumes the sensor to be plugged into CONN2
#define DHTPIN D2 // what pin we're connected to
// Here we define the type of sensor used
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
int f=0;
bool humid = false;
TCPClient client;
unsigned long myChannelNumber =897398;
const char * myWriteAPIKey = "ZSGLMB2IDWW4LGD4";
void setup() {
ThingSpeak.begin(client);
pinMode(D7, OUTPUT);
Serial.begin(9600);
dht.begin();
Particle.subscribe("pleaseWork_2", l, ALL_DEVICES);
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
delay(2000); //2 second delay
float t = dht.getTempCelcius(); //Takes temp data in celcius
float h = dht.getHumidity();
;
if (isnan(h) || isnan(t) ) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Particle.publish("pleaseWork_t", String (t), PUBLIC);
Particle.publish("pleaseWork_h", String (h), PUBLIC);
ThingSpeak.setField(1,t);
ThingSpeak.setField(2,h);
Serial.print(dht.getHumidity());
Serial.println("h");
Serial.print(dht.getTempFarenheit());
Serial.println("t");
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(15000); // ThingSpeak will only accept updates every 15 seconds.
}
void l(const char *event, const char *data) {
digitalWrite(D7, HIGH);
delay(2000);
digitalWrite(D7, LOW);
delay(1000);
}
Hub Code
C/C++This code is for the hub argon. The code pulls data from Thing-speak and then displays onto the LCD screen.
// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.h>
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
// This example assumes the sensor to be plugged into CONN2
#define DHTPIN D2 // what pin we're connected to
// Here we define the type of sensor used
#define DHTTYPE DHT11 // DHT 11
//Define RGB LED1 PINS note green collor is note used so not required
//API_KEY (WRITE)
const String key = "ZSGLMB2IDWW4LGD4";
//DHT dht(DHTPIN, DHTTYPE);
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
lcd.clear();
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Sensor 1 T&H");
lcd.setCursor(0,1);
lcd.print("Sensor 2 T&H");
Particle.subscribe("pleaseWork_h", h, ALL_DEVICES);
delay(1000);
Particle.subscribe("pleaseWork_f", f, ALL_DEVICES);
delay(1000);
Particle.subscribe("pleaseWork_j", j, ALL_DEVICES);
delay(1000);
Particle.subscribe("pleaseWork_g", g, ALL_DEVICES);
delay(1000);
// We open up a serial port to monitor the sensor values
//Serial.begin(9600);
//Serial.println("DHT11 test!");
//dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(5000);
Particle.publish("pleaseWork_all", PUBLIC);
}
void f(const char *event, const char *data) {
// Print the data over serial
lcd.setCursor(2,0);
lcd.print(data);
lcd.setCursor(0,0);
lcd.print("A=");
}
void h(const char *event, const char *data) {
lcd.setCursor(10,0);
lcd.print(data);
lcd.setCursor(6,0);
lcd.print("C ");
lcd.setCursor(14,0);
lcd.print("% ");
}
void g(const char *event, const char *data) {
// Print the data over serial
lcd.setCursor(2,1);
lcd.print(data);
lcd.setCursor(0,1);
lcd.print("B=");
}
void j(const char *event, const char *data) {
lcd.setCursor(10,1);
lcd.print(data);
lcd.setCursor(6,1);
lcd.print("C ");
lcd.setCursor(14,1);
lcd.print("% ");
}
Comments