BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

ESP8266 with 3 sensors and blynk

esp8266

#1

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() {
  Serial.begin(9600);
  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("=================================");
  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.
  delay(2500);
  Serial.println("=================================");
  Serial.println("VIBRATION");
  long measurement =TP_init();
  delay(50);
  Serial.print("measurment = ");
  Serial.println(measurement);
Serial.println("=================================");
Serial.println("DISTANCE");
// Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(500);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(500);
  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.print(distance_in);
 Serial.println(" inches"); */
  Serial.print("Distance: ");
  Serial.print(distance_cm);
  Serial.println(" centimeters");
  /* uncomment the 3 Serial.print lines
 to display measure in inches */                                                                              


  }
  long TP_init(){
  delay(10);
  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…


#2

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.

https://www.arduino.cc/reference/en/


#3

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


#4

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.


#5

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:


#6

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


#7

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

but for a bachelor’s degree? nah…


#8

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


Blynk + Email (Arduino UNO with Adafruit WINC1500 WiFi Shield)
#9

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:


#10

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!!!


#12

2 posts were merged into an existing topic: Blynk Problem


Blynk + Email (Arduino UNO with Adafruit WINC1500 WiFi Shield)