D3 was not declared in this scope Node MCU esp8266

Hi I want to create a code for smart irrigation using esp8266 and soil moisture sensor. I am having a hard time with the code as it is showing the error D3 was not declared in this scope

`#include <Blynk.h>

//Include the library files
#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

//Initialize the LCD display
LiquidCrystal_I2C lcd(0x27, 16, 2);

char auth[] = "";//Enter your Auth token
char ssid[] = "";//Enter your WIFI name
char pass[] = "";//Enter your WIFI password

BlynkTimer timer;
bool Relay = 0;

//Define component pins
#define sensor A0
#define waterPump D3

void setup() {
Serial.begin(9600);
pinMode(waterPump, OUTPUT);
digitalWrite(waterPump, HIGH);
lcd.init();
lcd.backlight();

Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

lcd.setCursor(1, 0);
lcd.print("System Loading");
for (int a = 0; a <= 15; a++) {
lcd.setCursor(a, 1);
lcd.print(".");
delay(500);
}
lcd.clear();

//Call the function
timer.setInterval(100L, soilMoistureSensor);
}

//Get the button value
BLYNK_WRITE(V1) {
Relay = param.asInt();

if (Relay == 1) {
digitalWrite(waterPump, LOW);
lcd.setCursor(0, 1);
lcd.print("Motor is ON ");
} else {
digitalWrite(waterPump, HIGH);
lcd.setCursor(0, 1);
lcd.print("Motor is OFF");
}
}

//Get the soil moisture values
void soilMoistureSensor() {
int value = analogRead(sensor);
value = map(value, 0, 1024, 0, 100);
value = (value - 100) * -1;

Blynk.virtualWrite(V0, value);
lcd.setCursor(0, 0);
lcd.print("Moisture :");
lcd.print(value);
lcd.print(" ");

}

void loop() {
Blynk.run();//Run the Blynk library
timer.run();//Run the Blynk timer
}

Just use the GPIO number.

#define waterPump 3

1 Like

…and your post is missing one IMPORTANT thing !

Please be more specific. What board?

I think pin names like "D3" are defined for some types of esp8266 boards (like Wemos mini or NodeMCU) but not all.

As mentioned, please fix those code tags!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.