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…