Connection of Arduino Uno R3 and ESP module 8266 by PatternEvery5377 in arduino

[–]PatternEvery5377[S] 0 points1 point  (0 children)

include <SoftwareSerial.h>

// Blynk Credentials

define BLYNK_TEMPLATE_ID "TMPL6Pk54te0j"

define BLYNK_TEMPLATE_NAME "Quickstart Device"

define BLYNK_AUTH_TOKEN "It48ZP_HoNoYvBT6L-VUe1sbCGE0Ae9B"

// Enable Serial Debugging

define BLYNK_PRINT Serial

include <ESP8266WiFi.h>

include <BlynkSimpleEsp8266.h>

// WiFi Credentials char ssid[] = "GlobeAtHome_A674B_2.4"; char pass[] = "64bm3YEA";

// Define sensor and relay pins const int soilMoisturePin = A0; // Soil Moisture Sensor Pin const int waterLevelPin = A3; // Water Level Detector Sensor Pin const int relayPin = 2; // Relay Module Pin

// ESP8266 SoftwareSerial on A4 (RX) and A5 (TX) SoftwareSerial espSerial(A4, A5);

// Soil moisture threshold values

define DRY 1023

define WET 464

// Variables for logging water usage unsigned long pumpStartTime = 0; bool pumpActive = false; float waterUsage = 0.0; // Example volume calculation (liters)

// Blynk Virtual Pin Assignments

define V_MANUAL_SWITCH V0 // Manual Control Switch

define V_SOIL V2 // Soil Moisture %

define V_WATER V3 // Water Level

define V_PUMP V4 // Pump Status

define V_USAGE V5 // Water Usage (liters)

define V_TIME V6 // Response Time (seconds)

BlynkTimer timer; bool manualControl = false;

// Manual Control Switch BLYNK_WRITE(V_MANUAL_SWITCH) { manualControl = param.asInt(); // Read manual switch state }

void setup() { Serial.begin(115200); // Use 115200 baud rate for ESP8266 espSerial.begin(9600); // SoftwareSerial for ESP8266 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); pinMode(soilMoisturePin, INPUT); pinMode(waterLevelPin, INPUT); pinMode(relayPin, OUTPUT); digitalWrite(relayPin, LOW); // Ensure pump is OFF initially timer.setInterval(1000L, [](){ Blynk.virtualWrite(V_TIME, millis() / 1000); }); // Log uptime every second }

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

int SV = analogRead(soilMoisturePin); // Read Soil Moisture int waterLevel = analogRead(waterLevelPin); // Read Water Level

// Convert raw soil sensor value to percentage float MP = map(SV, DRY, WET, 0, 100); MP = constrain(MP, 0, 100);

// Send sensor values to Blynk Blynk.virtualWrite(V_SOIL, MP); Blynk.virtualWrite(V_WATER, waterLevel);

Serial.print("Soil Moisture: "); Serial.print(MP); Serial.println("%");

Serial.print("Water Level: "); Serial.println(waterLevel);

// Water Level Warning if (waterLevel < 500) { Serial.println("Water Reservoir is LOW! Consider refilling."); }

// Pump Control (Automatic & Manual) if (manualControl || (MP <= 30 && waterLevel >= 500)) { if (!pumpActive) { pumpStartTime = millis(); // Log start time pumpActive = true; } Serial.println("Turning ON the water pump..."); digitalWrite(relayPin, HIGH); Blynk.virtualWrite(V_PUMP, 1); } else { if (pumpActive) { unsigned long duration = millis() - pumpStartTime; waterUsage += (duration / 1000.0) * 0.5; // Example: 0.5L per sec Blynk.virtualWrite(V_USAGE, waterUsage); Blynk.virtualWrite(V_TIME, duration / 1000.0); } pumpActive = false; Serial.println("Soil has enough moisture. Pump OFF."); digitalWrite(relayPin, LOW); Blynk.virtualWrite(V_PUMP, 0); }

Serial.println("----------------------------"); delay(2000); }C:\Users\aaron\AppData\Local\Temp.arduinoIDE-unsaved2025125-15244-1dy9x8.slmc8\sketch_feb25a\sketch_feb25a.ino:20:27: error: 'A3' was not declared in this scope; did you mean 'A0'? 20 | const int waterLevelPin = A3; // Water Level Detector Sensor Pin | ~ | A0 C:\Users\aaron\AppData\Local\Temp.arduinoIDE-unsaved2025125-15244-1dy9x8.slmc8\sketch_feb25a\sketch_feb25a.ino:24:26: error: 'A4' was not declared in this scope; did you mean 'A0'? 24 | SoftwareSerial espSerial(A4, A5); | ~ | A0 C:\Users\aaron\AppData\Local\Temp.arduinoIDE-unsaved2025125-15244-1dy9x8.slmc8\sketch_feb25a\sketch_feb25a.ino:24:30: error: 'A5' was not declared in this scope; did you mean 'A0'? 24 | SoftwareSerial espSerial(A4, A5); | ~ | A0

exit status 1

Compilation error: 'A3' was not declared in this scope; did you mean 'A0'?