ESP8266 with 3 sensors and blynk

How can i adapt this code to blynk? It is a code that displays on serial monitor of Arduino IDE values for temperature&humidity, vibration and distance. I dont know how to compute it and connect it to blynk widget on phone app.
To mention, i can connect to blynk app without any problems.

#include <SimpleDHT.h>

// for DHT22, 
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2
const int trigPin = D5;
const int echoPin = D6;
long duration;
int distance_cm;
int distance_in;
int vibr_Pin = D8;
int pinDHT22 = D2;
SimpleDHT22 dht22;

void setup() {
  pinMode(vibr_Pin, INPUT);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input

void loop() {
  // start working...
  Serial.println("TEMPERATURE & HUMIDITY");

  // read without samples.
  // @remark We use read2 to get a float data, such as 10.1*C
  //    if user doesn't care about the accurate data, use read to get a byte data, such as 10*C.
  float temperature = 0;
  float humidity = 0;
 int err = SimpleDHTErrSuccess;
       if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
         Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
          return; }

  Serial.print("Temperature & Humidity: ");
  Serial.print((float)temperature); Serial.print(" *C, ");
  Serial.print((float)humidity); Serial.println(" RH%");

  // DHT22 sampling rate is 0.5HZ.
  long measurement =TP_init();
  Serial.print("measurment = ");
// Clears the trigPin
  digitalWrite(trigPin, LOW);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
  /* Reads the echoPin, returns the sound wave 
 travel time in microseconds */
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance_cm = duration / 58;
  distance_in = duration / 148;
  /* Prints the distance on the Serial Monitor
 Serial.print("Distance: ");
 Serial.println(" inches"); */
  Serial.print("Distance: ");
  Serial.println(" centimeters");
  /* uncomment the 3 Serial.print lines
 to display measure in inches */                                                                              

  long TP_init(){
  long measurement=pulseIn (vibr_Pin, HIGH);  //wait for the pin to get HIGH and returns measurement
  return measurement;


so, in the serial monitor of Arduino IDE, we will see the values displayed for our 3 sensors. I would really appreciate if somebody can help me to integrate this code to blynk platform.
also, my coding skills are basic…

Hello, we help you learn about Blynk and how it works, but we do not code it for you or, aside from tips and tricks, teach you how to code.

You will learn best by trying the examples, searching and seeing how others do similar things and spending some effort learning some coding basics.

i looked on several examples, tutorials and forums before posting here. i can build an app to read the valuea from my DHT22 sensor but im unable/unskilled to read the other 2 sensors at the same time

Understandable… however you are still not likely to find many that will do it for you… particularly if you are unwilling to try first.

Search this forum for similar sensors, read through all the documentation, look into using BlynkTimer, etc.

Start working on what you can as you learn, then others will chip in and help out, provide pointers, ideas, etc.

ok, i will give it a try. im reading forums and examples for days already…i need to finish this project for my bachelors degree diploma project in 2 days…ouch :frowning:

I know… Skool is sooo hard… they expect one to actually learn stuffs :stuck_out_tongue:

a high schooler who can’t work this out? yeah, maybe…

but for a bachelor’s degree? nah…

i tried to ask for help but nobody wanted to help me haha. and i will integrate this sensor part to a more complex project. it’s not only this blynk app

I did help… gave you some suggestions, showed you some examples for timers (HINT)… called your school and gave you a good reference :stuck_out_tongue:


Hey! Thanks a lot for you help and your effort. I managed to code everything and get all the sensors to be displayed on my phone blynk app. It wasnt so hard once i understood how blynk codes work.

Once again, a big thanks!!!


2 posts were merged into an existing topic: Blynk Problem