49713 Designing for the Internet of Things
· 25 members
A hands-on introductory course exploring the Internet of Things and connected product experiences.
Want to monitor your baby proactively by a quick and simple temperature/humidity monitor set in baby room? With the idea of IoT (internet of thing), I can help you to achieve that!
We all experience the drive to sleep during the day, new born baby are no different.They have developed their own circadian rhythm. If we overlook their need to sleep during the times when their body temperature dips and metabolism production increases, we see babies who do not settle easily or sleep for long stretches. Thus, we want to ensure baby’s sleep environment is slightly cooler than room temperature.
One of the great things about living in this era is that there is always technology for whichever challenge you’re facing. With the idea of IoT (internet of thing), we can monitor room temperature proactively and always make sure our baby feel the best. What's better, you can access real-time temperature/humidity data from a iOS and Android App anywhere, anytime. Great thing always starts from small. Let's give baby the best we can!
How Internet of thing works?
In this project, IoT concept is realized through both hardware (Particle Photon) and software platform Blynk. If you haven't heard about Blynk, Blynk is a popular mobile app for the IoT, which compatible with ESP8266, Arduino, Raspberry Pi, SparkFun and many others. What's cool about Blynk is that it allows user to build graphic interface for project by simply dragging and dropping widgets. You may ask, how hardware provider and software platform work together seamless? Simply put, Hardware provider (Particle in this case) will request token from the software platform for token services that user could be authenticated. Once user authentication complete, IoT hub (software platform) will provide services to the IoT device.
What challenge I faced?
In this project, adding libraries to the code is necessary. This is actually the challenge of my project, it keeps telling me there are some bugs I add the library. To add the library, you can go to Particle build, click library and add the any library you want.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_Sensor.h>
// This #include statement was automatically added by the Particle IDE.
#include <PietteTech_DHT.h>
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
// system defines
#define DHTTYPE DHT22 // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN 4 // Digital pin for communications
#define DHT_SAMPLE_INTERVAL 60000 // Sample every minute
//declaration
void dht_wrapper(); // must be declared before the lib initialization
// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);
// globals
unsigned int DHTnextSampleTime; // Next time we want to start sample
bool bDHTstarted; // flag to indicate we started acquisition
int n; // counter
//this is coming from http://www.instructables.com/id/Datalogging-with-Spark-Core-Google-Drive/?ALLSTEPS
char resultstr[64]; //String to store the sensor data
//DANGER - DO NOT SHARE!!!!
char auth[] = "4a77b40967dd4c2aac3bd0b2c16573b1"; // Put your blynk token here
//DANGER - DO NOT SHARE!!!!
char VERSION[64] = "0.04";
#define READ_INTERVAL 60000
void setup()
{
Blynk.begin(auth);
DHTnextSampleTime = 0; // Start the first sample immediately
Particle.variable("result", resultstr, STRING);
Particle.publish("DHT22 - firmware version", VERSION, 60, PRIVATE);
}
// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() {
DHT.isrCallback();
}
void loop()
{
Blynk.run(); // all the Blynk magic happens here
// Check if we need to start the next sample
if (millis() > DHTnextSampleTime) {
if (!bDHTstarted) { // start the sample
DHT.acquire();
bDHTstarted = true;
}
if (!DHT.acquiring()) { // has sample completed?
float temp = (float)DHT.getCelsius();
int temp1 = (temp - (int)temp) * 100;
char tempInChar[32];
sprintf(tempInChar,"%0d.%d", (int)temp, temp1);
Particle.publish("The temperature from the dht22 is:", tempInChar, 60, PRIVATE);
//virtual pin 1 will be the temperature
Blynk.virtualWrite(V1, tempInChar);
//google docs can get this variable
sprintf(resultstr, "{\"t\":%s}", tempInChar);
float humid = (float)DHT.getHumidity();
int humid1 = (humid - (int)humid) * 100;
sprintf(tempInChar,"%0d.%d", (int)humid, humid1);
Particle.publish("The humidity from the dht22 is:", tempInChar, 60, PRIVATE);
//virtual pin 2 will be the humidity
Blynk.virtualWrite(V2, tempInChar);
n++; // increment counter
bDHTstarted = false; // reset the sample flag so we can take another
DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL; // set the time for next sample
}
}
}
Click to Expand
There are two take away from this project. One is to understand the process of product develop from product prototype, parts sourcing and product design. Two is get a peek of the mechanism between the IoT in terms of hardware and software interaction. In addition, I am also able to have some basic understanding on Particle language -variables, function and library.
A hands-on introductory course exploring the Internet of Things and connected product experiences.
Want to monitor your baby proactively by a quick and simple temperature/humidity monitor set in baby room?
With the idea of IoT (internet of thing), I can help you to achieve that!
January 24th, 2018