The code seems to be uploaded to the ESP8266 board, but it doesn’t show up because it’s online on Blynk, but it keeps showing up offline. I’d appreciate it if you could tell me how to fix it.
// Viral Science www.viralsciencecreativity.com www.youtube.com/c/viralscience
// Blynk IOT Smart Plant Monitoring System
/* Connections
Relay. D3
Btn. D7
Soil. A0
PIR. D5
SDA. D2
SCL. D1
Temp. D4
*/
//Include the library files
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
//Initialize the LCD display
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define BLYNK_TEMPLATE_ID "TMPL6Ij_6RXDT"
#define BLYNK_TEMPLATE_NAME "Smart Plant"
#define BLYNK_AUTH_TOKEN "YUtxpnVK3aQ6dnUs8-x21-hb-2C02sI6"
char auth[] = "YUtxpnVK3aQ6dnUs8-x21-hb-2C02sI6"; //Enter your Blynk Auth token
char ssid[] = "Multi_2G"; //Enter your WIFI SSID
char pass[] = "12345678"; //Enter your WIFI Password
DHT dht(D4, DHT11);//(DHT sensor pin,sensor type) D4 DHT11 Temperature Sensor
BlynkTimer timer;
//Define component pins
#define soil A0 //A0 Soil Moisture Sensor
#define PIR D5 //D5 PIR Motion Sensor
int PIR_ToggleValue;
void checkPhysicalButton();
int relay1State = LOW;
int pushButton1State = HIGH;
#define RELAY_PIN_1 D3 //D3 Relay
#define PUSH_BUTTON_1 D7 //D7 Button
#define VPIN_BUTTON_1 V12
//Create three variables for pressure
double T, P;
char status;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.backlight();
pinMode(PIR, INPUT);
pinMode(RELAY_PIN_1, OUTPUT);
digitalWrite(RELAY_PIN_1, LOW);
pinMode(PUSH_BUTTON_1, INPUT_PULLUP);
digitalWrite(RELAY_PIN_1, relay1State);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
dht.begin();
lcd.setCursor(0, 0);
lcd.print(" Initializing ");
for (int a = 5; a <= 10; a++) {
lcd.setCursor(a, 1);
lcd.print(".");
delay(500);
}
lcd.clear();
lcd.setCursor(11, 1);
lcd.print("W:OFF");
//Call the function
timer.setInterval(100L, soilMoistureSensor);
timer.setInterval(100L, DHT11sensor);
timer.setInterval(500L, checkPhysicalButton);
}
//Get the DHT11 sensor values
void DHT11sensor() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.print(t);
lcd.setCursor(8, 0);
lcd.print("H:");
lcd.print(h);
}
//Get the soil moisture values
void soilMoistureSensor() {
int value = analogRead(soil);
value = map(value, 0, 1024, 0, 100);
value = (value - 100) * -1;
Blynk.virtualWrite(V3, value);
lcd.setCursor(0, 1);
lcd.print("S:");
lcd.print(value);
lcd.print(" ");
}
//Get the PIR sensor values
void PIRsensor() {
bool value = digitalRead(PIR);
if (value) {
Blynk.logEvent("pirmotion","WARNNG! Motion Detected!"); //Enter your Event Name
WidgetLED LED(V5);
LED.on();
} else {
WidgetLED LED(V5);
LED.off();
}
}
BLYNK_WRITE(V6)
{
PIR_ToggleValue = param.asInt();
}
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(VPIN_BUTTON_1);
}
BLYNK_WRITE(VPIN_BUTTON_1) {
relay1State = param.asInt();
digitalWrite(RELAY_PIN_1, relay1State);
}
void checkPhysicalButton()
{
if (digitalRead(PUSH_BUTTON_1) == LOW) {
// pushButton1State is used to avoid sequential toggles
if (pushButton1State != LOW) {
// Toggle Relay state
relay1State = !relay1State;
digitalWrite(RELAY_PIN_1, relay1State);
// Update Button Widget
Blynk.virtualWrite(VPIN_BUTTON_1, relay1State);
}
pushButton1State = LOW;
} else {
pushButton1State = HIGH;
}
}
void loop() {
if (PIR_ToggleValue == 1)
{
lcd.setCursor(5, 1);
lcd.print("M:ON ");
PIRsensor();
}
else
{
lcd.setCursor(5, 1);
lcd.print("M:OFF");
WidgetLED LED(V5);
LED.off();
}
if (relay1State == HIGH)
{
lcd.setCursor(11, 1);
lcd.print("W:ON ");
}
else if (relay1State == LOW)
{
lcd.setCursor(11, 1);
lcd.print("W:OFF");
}
Blynk.run();//Run the Blynk library
timer.run();//Run the Blynk timer
}
Terminal log
. Variables and constants in RAM (global, static), used 31092 / 80192 bytes (38%)
║ SEGMENT BYTES DESCRIPTION
╠══ DATA 1560 initialized variables
╠══ RODATA 2540 constants
╚══ BSS 26992 zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 61279 / 65536 bytes (93%)
║ SEGMENT BYTES DESCRIPTION
╠══ ICACHE 32768 reserved space for flash instruction cache
╚══ IRAM 28511 code in IRAM
. Code in flash (default, ICACHE_FLASH_ATTR), used 257604 / 1048576 bytes (24%)
║ SEGMENT BYTES DESCRIPTION
╚══ IROM 257604 code in flash
esptool.py v3.0
Serial port COM3
Connecting….
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 08:f9:e0:5f:9f:a5
Uploading stub…
Running stub…
Stub running…
Changing baud rate to 460800
Changed.
Configuring flash size…
Auto-detected Flash size: 4MB
Flash params set to 0x0241
Compressed 294368 bytes to 214979…
Writing at 0x00000000… (7 %)
Writing at 0x00004000… (14 %)
Writing at 0x00008000… (21 %)
Writing at 0x0000c000… (28 %)
Writing at 0x00010000… (35 %)
Writing at 0x00014000… (42 %)
Writing at 0x00018000… (50 %)
Writing at 0x0001c000… (57 %)
Writing at 0x00020000… (64 %)
Writing at 0x00024000… (71 %)
Writing at 0x00028000… (78 %)
Writing at 0x0002c000… (85 %)
Writing at 0x00030000… (92 %)
Writing at 0x00034000… (100 %)
Wrote 294368 bytes (214979 compressed) at 0x00000000 in 5.2 seconds (effective 451.1 kbit/s)…
Hash of data verified.
Leaving…
Hard resetting via RTS pin…
이진호 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.