86Views0Replies

Author Options:

How to send a value from Blynk to Arduino? Answered

Hi All,
I am doing my project by using blynk and arduino mega. This code is to control Relay by measuring temperature and humidity through dht11. Now I programmed that Relay is off when the humidity is over 60 which is the fixed value. However, I want to add slider or other input switch to set the humidity value on the app. And then the set value is sent from Blynk to Arudino. Therefore, Relay will be on or off, depending on the set value. I’ve been trying it but failed. Please anybody can help me? Thank you.

#define BLYNK_PRINT

SwSerial

#include SoftwareSerial SwSerial(10, 11); // RX, TX

#include

#include char auth[] = “*****************************”;

#define DHTPIN A1

#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);

BlynkTimer timer;

void sendSensor() {

int h = dht.readHumidity();

int t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

Blynk.virtualWrite(V5, h);

Blynk.virtualWrite(V6, t);

if(h<60){

digitalWrite(52,HIGH);

}

else{

digitalWrite(52,LOW);

}

}

void setup()

{ // Debug console

SwSerial.begin(9600);

pinMode(52,OUTPUT);

// Blynk will work through Serial // Do not read or write this serial manually in your sketch

Serial.begin(9600);

Blynk.begin(Serial, auth);

dht.begin();

// Setup a function to be called every second

timer.setInterval(1000L, sendSensor);

}

void loop()

{

Blynk.run();

timer.run();

}

Discussions