Temperature, Humidity, Soil Moisture Monitoring with Particle, DHT22 and Blynk

While testing out our new Logger widget, I decided to make a simple setup, to monitor something in my apartment. Since we have lot’s of plants, I’ve taken the most thirsty ones to look closely at them.


Duplicate Gauges were used to determine min/max for data mapping later.


Materials:

This is the code I used in Particle Web IDE:

#include "blynk/blynk.h"
#include "blynk/BlynkSimpleSparkCore.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
#include "Adafruit_DHT/Adafruit_DHT.h"
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT22		// DHT 22 (AM2302)
#define BLYNK_PRINT Serial

SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
void OnTimer(void);   //Prototype for timer callback method

DHT dht(DHTPIN, DHTTYPE);
float h, t, f, c, 
int m, mRaw, l, lRaw;

char auth[] = "MY_AUTH_TOKEN";  

void setup() {
    Serial.begin(9600);
    updateTimer.SetCallback(OnTimer);
    Serial.println("DHTxx test!");
    dht.begin();
    delay(5000); // Allow board to settle
    pinMode(A4, OUTPUT);
    pinMode(A5, OUTPUT);
    Blynk.begin(auth);
}

void loop() {

    Blynk.run();
    updateTimer.Update();
    
    h = dht.getHumidity();
    t = dht.getTempCelcius();
    mRaw = analogRead(A4);
    lRaw = analogRead(A5);
    m = map(mRaw, 400, 3200, 0, 100);
    l = map(lRaw, 400, 3200, 0, 100);
  
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		return;
	}
}

void OnTimer(void) {  //Handler for the timer, will be called automatically
  
  t = ((int) (t * 10) / 10.0);
  h = ((int) (h * 10) / 10.0);

  Blynk.virtualWrite(21, t);
  Blynk.virtualWrite(22, h);
  Blynk.virtualWrite(23, m);
  Blynk.virtualWrite(24, l);
}

You will also need to re-include Adafruit and Blynk libraries in Particle Web IDE.

5 Likes

Cool. What’s map() and what’s that widget in the second row? How do I do a multi-value graph? Sorry if simple, still new to Arduino, Blynk, and 0-Particle Core (is that photon, or spark, or ?, not been there yet either).

Forget map() needles question.

It’s Particle Core. Logger Widget will be available soon. This project set up to test it out.

Yeah, rtf-post. I jumped from screen shot->code->question. High anticipation of that and other widgets (on IOS).

I spent the other night learning about rooting/cm/recovery junk just so I could make use of a discarded nook-tablet. Now running 5.1 and Blynk. I like the android version, wishing for iOS parity. (Wishing for a snappy android device too)

No problem:)

iOS is slightly behind, but we are trying to fix this issue. Logger for android will be live in 2 days max.

Please, how did You do to present 2 or more curves of values ​​in the same Graph widget?
Rubens

This is a new widget we are working on, it will be soon released for Android version.

OK! Thank you.
congratulations. the app is getting very good. I’m using the iOS version.

1 Like

why not can complie?
look picture this


give solution
i want to learning blynk

Try reinstalling Arduino IDE and Blynk library

how many pin graph?
how to export to excell?
how to data logger?

what meaning?
how read to program?
i sorry
i am how many quention^^
please answers

Please read here:
https://www.arduino.cc/en/Reference/Map

For me, raw values form sensor are not very usable, so I mapped incoming data to 0-100%

This is my first project and I’ve been reading for 2 days before replying. I’m a beginner at programming & appreciate the patients. However I am unable to see/understand how to get the Photon to do multiple things. I’m trying to open/close/(Status) of the garage door while also integrating a DHT11 sensor reporting in Farenheit. Any assistance & expertise would be greatly appreciated & hope a chuckle is had at my nievetie…
Found this link/code as well for the Temp Sensors (no Blynk)

//GARAGE DOOR


#include "blynk/blynk.h"
#include "blynk/BlynkSimpleParticle.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
#include "Adafruit_DHT/Adafruit_DHT.h"
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT11		// DHT 22 (AM2302)
#define BLYNK_PRINT Serial

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

const int reedSwitch = D2;

const int relaySwitch1 = D0;

const int relaySwitch2 = D3;

int reedStatus = 0;

int ledStatus = 0;

void setup()

{

Serial.begin(9600);

Blynk.begin(auth);

pinMode(relaySwitch1, OUTPUT);

pinMode(relaySwitch2, OUTPUT);

pinMode(reedSwitch, INPUT);

pinMode(D3, OUTPUT);

}

//add button in Blynk app corresponding to V0

BLYNK_WRITE (0){ //close garage

if (reedStatus == HIGH) {

digitalWrite(relaySwitch1, HIGH);

delay(1000);

digitalWrite(relaySwitch1, LOW);

}

}

//add button in Blynk app corresponding to V1

BLYNK_WRITE (1){ //open garage

if (reedStatus == LOW) {

digitalWrite(relaySwitch1, HIGH);

delay(1000);

digitalWrite(relaySwitch1, LOW);

}

}

//add LED in Blynk app corresponding to V3

BLYNK_READ(3) //report garage status

{

Blynk.virtualWrite(3, ledStatus);

}

void loop()

{

Blynk.run();

//constantly monitor the reed switch status (garage open or closed)

reedStatus = digitalRead(reedSwitch);

if (reedStatus == HIGH) {

ledStatus = 1023;

}

else {

ledStatus = 0;

}

}







//#include "blynk/blynk.h"
//#include "blynk/BlynkSimpleSparkCore.h"
//#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
//#include "Adafruit_DHT/Adafruit_DHT.h"
//#define DHTPIN 2     // what pin we're connected to
//#define DHTTYPE DHT11		// DHT 22 (AM2302)
//#define BLYNK_PRINT Serial

SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
void OnTimer(void);   //Prototype for timer callback method

DHT dht(DHTPIN, DHTTYPE);
float h, t, f, c, 
int m, mRaw, l, lRaw;

//char auth[] = "MY_AUTH_TOKEN";  

void setup() {
    Serial.begin(9600);
    updateTimer.SetCallback(OnTimer);
    Serial.println("DHTxx test!");
    dht.begin();
    delay(5000); // Allow board to settle
    pinMode(A4, OUTPUT);
    pinMode(A5, OUTPUT);
    Blynk.begin(auth);
}

void loop() {

    Blynk.run();
    updateTimer.Update();
    
    h = dht.getHumidity();
    --t = dht.getTempFarenheit();
    t = dht.getTempCelcius();
    mRaw = analogRead(A4);
    lRaw = analogRead(A5);
    m = map(mRaw, 400, 3200, 0, 100);
    l = map(lRaw, 400, 3200, 0, 100);
  
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		return;
	}
}

void OnTimer(void) {  //Handler for the timer, will be called automatically
  
  t = ((int) (t * 10) / 10.0);
  h = ((int) (h * 10) / 10.0);

  Blynk.virtualWrite(21, t);
  Blynk.virtualWrite(22, h);
  Blynk.virtualWrite(23, m);
  Blynk.virtualWrite(24, l);
}

*ERRORS

In file included from blynk/BlynkParticle.h:16:0,
                 from blynk/BlynkSimpleParticle.h:14,
                 from blynk/blynk.h:2,
                 from blynkapiparticle.cpp:5:
blynk/BlynkApiParticle.h:78:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
     #warning "analogInputToDigitalPin not defined => Named analog pins will not work"
      ^
blynkapiparticle.cpp:128:1: error: expected unqualified-id before 'int'
 //#define BLYNK_PRINT Serial
 ^

blynkapiparticle.cpp: In function 'void setup()':
blynkapiparticle.cpp:132:6: error: redefinition of 'void setup()'
 
      ^

blynkapiparticle.cpp:25:6: error: 'void setup()' previously defined here
 
      ^

blynkapiparticle.cpp: In function 'void loop()':
blynkapiparticle.cpp:143:6: error: redefinition of 'void loop()'
     dht.begin();
      ^

blynkapiparticle.cpp:85:6: error: 'void loop()' previously defined here
 
      ^

blynkapiparticle.cpp:151:5: error: 'mRaw' was not declared in this scope
 
     ^

blynkapiparticle.cpp:152:5: error: 'lRaw' was not declared in this scope
     Blynk.run();
     ^

blynkapiparticle.cpp:153:5: error: 'm' was not declared in this scope
     updateTimer.Update();
     ^

blynkapiparticle.cpp:154:5: error: 'l' was not declared in this scope
     
     ^

blynkapiparticle.cpp: In function 'void OnTimer()':
blynkapiparticle.cpp:170:26: error: 'm' was not declared in this scope
 void OnTimer(void) {  //Handler for the timer, will be called automatically
                          ^

blynkapiparticle.cpp:171:26: error: 'l' was not declared in this scope
   
                          ^

make[1]: *** [../build/target/user/platform-6blynkapiparticle.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

Thank you so much, it works me excelent :smile:

how did you connect to your wifi?
i am using esp8266 do you have any suggestions for me? i am a beginner.

Please use search on our forum and on internet. This question was covered many many times

hi there, nice project, I try to install it on my node mcu in arduino ide, but cant find these libraries
#include “blynk/BlynkSimpleSparkCore.h”
#include “SparkCorePolledTimer/SparkCorePolledTimer.h”
#include “Adafruit_DHT/Adafruit_DHT.h”

how can I nclude them?

It was a project build on Particle Photon, not Node MCU. You need to find libraries for your board.