Two way communication is failed between Blynk App. and Arduino

Hi? I’m very novice user for Blynk.
Now I’m trying to receive data from Arduino and to control Arduino using Blynk via Ethernet.

Currently, receiving data from Arduino is a OK. (The value from the sensor(CDS) is displayed on Value Display well). Unfortunately, adding a button to the Blynk App and turning on/off the LED via pushing button doesn’t work. LED is connected on Digital Pin and Button is also mapped on Digital Pin. I couldn’t understand that why two-way communicate is failed, what can I check first? Any clues are very helpful for me.


/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example shows how to configure static IP with Ethernet.
  Be sure to check ordinary Ethernet example first!!!

  NOTE: Pins 10, 11, 12 and 13 are reserved for Ethernet module.
        DON'T use them in your sketch directly!

  WARNING: If you have an SD card, you may need to disable it
        by setting pin 4 to HIGH. Read more here:
        https://www.arduino.cc/en/Main/ArduinoEthernetShield

  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

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

IPAddress server_ip (10, 0, 0, 10);

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { ////////// };

IPAddress arduino_ip ( /// );
IPAddress dns_ip     ( /// );
IPAddress gateway_ip ( /// );
IPAddress subnet_mask(255, 255, 255,   0);

#define W5100_CS  10
#define SDCARD_CS 4

int CDS=0;

void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  //Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  // Or like this:
  Blynk.begin(auth, "blynk-cloud.com", 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
}

void loop()
{
  Blynk.run();
  CDS = analogRead(A1);
  //Serial.println(CDS);
  Blynk.virtualWrite(V1, CDS);
}


You shouldn’t have virtual write commands in the void loop() trying to run running thousands of times a second.

Recommended reading…

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/how-to-control-anything-with-blynk-app

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/how-to-display-any-sensor-data-in-blynk-app

And basically all the other documentation made available

Thank you very much for your help.
First, I try to clean the code in the loop by using the Timer.
and I added BLYNK_WRITE code as below, but BLYNK_WRITE does not seem to be tiggered.
It is very difficult for me to find out what is the problem.

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example shows how to configure static IP with Ethernet.
  Be sure to check ordinary Ethernet example first!!!

  NOTE: Pins 10, 11, 12 and 13 are reserved for Ethernet module.
        DON'T use them in your sketch directly!

  WARNING: If you have an SD card, you may need to disable it
        by setting pin 4 to HIGH. Read more here:
        https://www.arduino.cc/en/Main/ArduinoEthernetShield

  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

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

IPAddress server_ip (10, 0, 0, 10);

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { /// };

IPAddress arduino_ip ( ///);
IPAddress dns_ip     ( ///);
IPAddress gateway_ip ( ///);
IPAddress subnet_mask(255, 255, 255,   0);

#define W5100_CS  10
#define SDCARD_CS 4

int CDS=0;
BlynkTimer timer; // Announcing the timer

BLYNK_CONNECTED() {
  Blynk.syncVirtual(V9);
  Serial.println("CONNEDTED");
}

BLYNK_WRITE(V9) {
Serial.println("BLYNK_WRITE"); // never go into here (except firt connection)

  int buttonState = param.asInt();
  digitalWrite(8, buttonState);
  Serial.println(buttonState);
}


void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  //Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  // Or like this:
  Blynk.begin(auth, "blynk-cloud.com", 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  pinMode(8, OUTPUT);
  timer.setInterval(1000L, sensorDataSend); //timer will run every sec 
}

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

void sensorDataSend()
{
  CDS = analogRead(A1);
  Blynk.virtualWrite(V1, CDS);
  Serial.println(CDS);
}


Are you at least getting the expected value on the serial print? If not look in the analog read direction, if so what are you seeing on whatever widget you have on V1… and is it set to PUSH?

I deleted the device information that was tested at the beginning, except only one Arduino(Ethernet) , and tested it with the same code, and everything works well.

  • Continuously display data received from the sensor on Blynk App
  • Turn on / off the LED of Arduino via pushing button on Blynk App

But it still is not clear what the cause was.
Anyway, it was very helpful to share your insight and information.