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

How to send a value from Blynk to Arduino?

arduino

#1

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.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
    
#include <BlynkSimpleStream.h>
#include <DHT.h>
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
  /*if (isnan(h) || isnan(t)) {
    SwSerial.println("Failed to read from DHT sensor!");
    return;
  }*/
  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();
}

#2

Please repost code, properly formatted as instructed, thanks. - Moderator

Blynk - FTFC


#3

I don’t see any attempts in your code?


#4

I tried but didnt posted it here


#5

Well, try adding in a BLYNK_WRITE() function using a slider to change a global variable used instead of the value of 60


#6

And even more straightforward:

https://examples.blynk.cc/?board=Arduino%20Uno&shield=ESP8266%20WiFi%20Shield&example=GettingStarted%2FGetData