[SOLVED]Can't push data

Hello everyone ,I build my simple projects but it error
I upload sample code to uno (connect to internet via usb) and add button for control digital pin13 for on and off and add button(virtual pin) more for control it’s work too but when i use dht 22 in loop when i press button nothing happen but work only dht22 how i do fix this.

The best way to get it fixed is to show us your sketch together with any error messages. If you don’t know how to add your sketch to the forum in a clearly legible form, ask.

Here this is my 1st code
i use virtual pin like a toggle swicth and add BLYNK_READ (show in value ) it’s work fine
so i can turn on and off insatanly when i press button
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "f48bf0ad60cf4f469a00f9bc0fb04f28";

int led = 13;
void setup()
{
 
  pinMode(led,OUTPUT);
  Serial.begin(9600);
  Blynk.begin(auth);

  while (Blynk.connect() == false) {
    // Wait until connected
  }
}

BLYNK_READ(V0) {
    Blynk.virtualWrite(V0, millis() / 1000);
}

BLYNK_READ(V1) {
    Blynk.virtualWrite(V1, millis());
}

void loop()
{
  Blynk.run();
  
}

BLYNK_WRITE(V3) //Button Widget is writing to pin V1
{
  int pinData = param.asInt(); 
  if(pinData==1){
    
    digitalWrite(led,HIGH);
    }

    else if(pinData==0)
    {
      digitalWrite(led,LOW);
      }
}

but when i add dht to the sketch like this

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>


#include "DHT.h"
DHT dht;


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "f48bf0ad60cf4f469a00f9bc0fb04f28";

int led = 13;
void setup()
{
  dht.setup(7);
  pinMode(led,OUTPUT);
  Serial.begin(9600);
  Blynk.begin(auth);

  while (Blynk.connect() == false) {
    // Wait until connected
  }
}

BLYNK_READ(V0) {
    Blynk.virtualWrite(V0, millis() / 1000);
}

BLYNK_READ(V1) {
    Blynk.virtualWrite(V1, millis());
}

void loop()
{
  Blynk.run();
  float humidity = dht.getHumidity(); // ดึงค่าความชื้น
  float temperature = dht.getTemperature(); // ดึงค่าอุณหภูมิ
  Blynk.virtualWrite(10,temperature);
  Blynk.virtualWrite(11,humidity);
}

BLYNK_WRITE(V3) //Button Widget is writing to pin V1
{
  int pinData = param.asInt(); 
  if(pinData==1){
    
    digitalWrite(led,HIGH);
    }

    else if(pinData==0)
    {
      digitalWrite(led,LOW);
      }
}

it’s work only temp and humid that show in my project
and when press button(virtual pin) nothing happen or sometime it’s on but don’t turn when i press button again. i’m dont good at english but hope youn understand .Thank you

You are flooding server in loop()

Hi conkerkh ,how to fix this?

Well you cant virtualWrite on every loop iteration. Use periodic calls instead. You can acomplish this either by SimpleTimer od better Ticker if you use ESP

Thank you very much conkerkh :slight_smile: , I use SimpleTimer to fix my project.

1 Like