Hi everyone, I’m working on a Blynk project to display data from a light sensor. I’m having problems with the line:
“Blynk.begin(auth, ssid, pass);”
- Without this line, data is still sent correctly
- When this line is present, the read data is 0
Please help me, thank you very much everyone
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6sdJ9hSeN"
#define BLYNK_TEMPLATE_NAME "cbAS"
#define BLYNK_AUTH_TOKEN "zf3QDM1Olsp8pjXh15FFM1GsL85z84T6"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <string.h>
#define Sensor 25 //Cảm biến nối chân số 25 ESP
int value;
#define LED 27
WidgetLED LED_ON_APP(V1);
int button;
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Giang90";
char pass[] = "08081990";
void setup()
{
Serial.begin(115200);
// Debug console
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW); //Mặc định đèn tắt
pinMode(Sensor, INPUT); //Cảm biến nhận tín hiệu
Blynk.begin(auth, ssid, pass);
}
/*BLYNK_WRITE(V2) {
button = param.asInt();
if(button == 1) {
digitalWrite(LED, HIGH);
LED_ON_APP.on();
} else {
digitalWrite(LED, LOW);
LED_ON_APP.off();
}
}*/
void lightSensor(void){
value = analogRead(Sensor); //Đọc giá trị analog của cảm biến và gán vào biến giatri
if (0 < value && value < 1000) //Nếu giá trị quang trở lớn hơn 1000
{
// digitalWrite(den, HIGH); //Đèn sáng
analogWrite(LED,0);
}
else if(1000< value && value<2000){
analogWrite(LED,60);
}
else if(2000<value && value<3000){
analogWrite(LED,120);
}
else //Ngược lại
{
// digitalWrite(den, LOW); //Đèn tắt
analogWrite(LED,255);
}
Serial.print("Giá trị cảm biến: ");
Serial.println(value);
delay(200);
}
void loop()
{
Blynk.run();
lightSensor();
Blynk.virtualWrite(V0, value);
}