Shai Perednik
Published © CC BY

Temperature/humidity monitor with Dweet & Freeboard

I need a quick and simple temp/humidity monitor for a baby room to post and monitor through a dashboard.

IntermediateShowcase (no instructions)11,310
Temperature/humidity monitor with Dweet & Freeboard

Things used in this project

Hardware components

Resistor 1k ohm
Resistor 1k ohm
DHT22 Temperature Sensor
DHT22 Temperature Sensor
Breadboard (generic)
Breadboard (generic)
Jumper wires (generic)
Jumper wires (generic)
Particle Photon

Software apps and online services



Read more


Fritzing File

breadboard and layout in fritzing


Breadboard Image



****REMEMBER to import the DHT and HTTP Client libraries into the Particle Web IDE****

Upload this code to the particle web IDE. Change the delay as appropriate. In my case, I needed near real time and this was going to be plugged into the wall, so I left it @ 1 second.

443 and SSL is supposed to work, however, it didn't for me when changing the port, and since I'm not sending any sensitive info, there's no need for the SSL overhead.
// This #include statement was automatically added by the Particle IDE.
#include "HttpClient/HttpClient.h"

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11		// DHT 11 
#define DHTTYPE DHT22		// DHT 22 (AM2302)
//#define DHTTYPE DHT21		// DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor


* Declaring the variables.
unsigned int nextTime = 0;    // Next time to contact the server
HttpClient http;

// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
    //  { "Content-Type", "application/json" },
    //  { "Accept" , "application/json" },
    { "Accept" , "*/*"},
    { NULL, NULL } // NOTE: Always terminate headers will NULL

http_request_t request;
http_response_t response;

void setup() {
	Particle.publish("DEBUG","DHT22 test!");


void loop() {
// Wait a few seconds between measurements.

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a 
// very slow sensor)
	float h = dht.getHumidity();
// Read temperature as Celsius
	float t = dht.getTempCelcius();
// Read temperature as Farenheit
	float f = dht.getTempFarenheit();
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t) || isnan(f)) {
		Particle.publish("DEBUG","Failed to read from DHT sensor!");

// Compute heat index
// Must send in temp in Fahrenheit!
	float hi = dht.getHeatIndex();
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin();

	//Serial.print("Humid: "); 
	//Serial.print("% - ");
	//Serial.print("Temp: "); 
	//Serial.print("*C ");
	//Serial.print("*F ");
	//Serial.print("*K - ");
	//Serial.print("DewP: ");
	//Serial.print("*C - ");
	//Serial.print("HeatI: ");
	//cast floats to string
	String sf(f, 2);
	String sh(h, 2);
	//pblish tests
	//post to dweet
	request.hostname = "";
    request.port = 80;
    request.path = "/dweet/for/particlehumiditysesor?temp=" + sf + "&humidity=" + sh;
	//json body doesn't work
	//request.body = "{\"humidity\":\"43%\",\"temp\":\"45f\"}"; //"{\"key\":\"value\"}";
    // Get request
    http.get(request, response, headers);
    //Spark.publish("DEBUG","Application Response status: ");

    //Spark.publish("DEBUG","Application HTTP Response Body: ");


Shai Perednik

Shai Perednik

1 project • 9 followers