BLYNK_READ(V5) //Blynk app has something on V5
{
sensorData = analogRead(A0); //reading the sensor on A0
Blynk.virtualWrite(V5, sensorData); //sending to Blynk
}
in the code I receive error while verify - ‘sensorData’ was not declared in this scope.
What I have to do, how the code should look like? Thanks.
BLYNK_READ(V5) //Blynk app has something on V5
{
int sensorData = analogRead(A0); //reading the sensor on A0
Blynk.virtualWrite(V5, sensorData); //sending to Blynk
}
or for Global Use
int sensorData;
BLYNK_READ(V5) //Blynk app has something on V5
{
sensorData = analogRead(A0); //reading the sensor on A0
Blynk.virtualWrite(V5, sensorData); //sending to Blynk
}
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "748236878788410da51e93e7******"
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "****";
char pass[] = "*******";
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
sensors.begin();
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}
void sendTemps()
{
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.println(temp);
Blynk.virtualWrite(V1, temp);
}
int sensorData
BLYNK_READ(V5) //Blynk app has something on V5
{
sensorData = analogRead(A0); //reading the sensor on A0
Blynk.virtualWrite(V5, sensorData); //sending to Blynk
void loop()
{
Blynk.run();
sendTemps();
}
There is the error message:
WARNING: Spurious .github folder in 'Adafruit NeoPixel' library
In file included from C:\Users\Ralica\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkApi.h:18:0,
from C:\Users\Ralica\Documents\Arduino\libraries\Blynk\src/BlynkApiArduino.h:14,
from C:\Users\Ralica\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp8266.h:18,
from C:\Users\Ralica\Desktop\NodeMCUmode\NodeMCUmode.ino:42:
C:\Users\Ralica\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkHandlers.h:158:5: error: expected initializer before 'void'
void BlynkWidgetRead ## pin (BlynkReq BLYNK_UNUSED &request)
^
C:\Users\Ralica\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkHandlers.h:164:31: note: in expansion of macro 'BLYNK_READ_2'
#define BLYNK_READ(pin) BLYNK_READ_2(pin)
^
C:\Users\Ralica\Desktop\NodeMCUmode\NodeMCUmode.ino:87:1: note: in expansion of macro 'BLYNK_READ'
BLYNK_READ(V5) //Blynk app has something on V5
^
exit status 1
Error compiling for board NodeMCU 0.9 (ESP-12 Module).
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
You’re missing a closing curly bracket “}” at the end of your BLYNK_READ (V5) function and a semicolon “;” from the end of your sensorData variable declaration.
It’s also normal practice to declare your global variables at the top of your code (before void setup in your case).
I’m not sure that the fixed code will meet your design requirements though. You should be using a timer to take readings from your sensors and send them to Blynk. You should also include a pinmode declaration for your analogue pin to use it as an input pin.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "748236878788410da51e93e7*******";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****";
char pass[] = "******";
BlynkTimer timer;
int sensorData;
void sendTemps()
{
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.println(temp);
Blynk.virtualWrite(V1, temp);
}
void sendAnalog()
{
sensorData = analogRead(A0); //reading the sensor on A0
Blynk.virtualWrite(V5, sensorData); //sending to Blynk
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
sensors.begin();
timer.setInterval(1000L, sendTemps);
timer.setInterval(1003L, sendAnalog);
}
void loop()
{
Blynk.run();
timer.run(); // running timer every second
}
The difference being in the display widget settings. The first example would need the frequency set to some interval, say 3 seconds like in the example on the link you posted.
For this code the frequency would be set to push, and the interval would be set by the timer. In this case approx. every 1 second.
This is all explained in the link you posted. I suggest you re-read it any try to get a better understanding of what it is saying.
Nirvana at last!! Thank you Toro_Blanco! The last sketch is the thing I was searching for. I just flash it on the board. However it seems that I am the idiot who is not expaining what exactly need to do😁.
So I needed to insert some basic signals in the board with a simple voltage divider.
Then to set events with
the different values appearing on the virtual pin. And then swiching digital pins on and off both form the blynk app on the smartphone and with a hardware button. And if you push a hardware button the changed condition of the digital pin will appear on the smartphone app, you will receive a feedback.
That’s it. I will use it for some home automation such as central heating schedule and temperature adjust, swiching on and off mostly common used electrical appliances and other. If someone is interested I can share the hardware and the wiring needed.
If that’s your aim then I’d use a different sensor. The BME280 is my preferrred sensor, it’s digital and has the advantage of also providing Humidity and if needed Atmospheric Pressure data.
I’d also provide some sort of display that allows users to see the current and target temperature settings, and change them without having to use the app. I use a Nextion touch screen, but a small OLED display would also be an option.
You should also build-in some hysteresis code into your project, to desensitise the thermostat and prevent the heating switching on and off rapidly when the current temperature is hovering around the target temperature.