#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Replace with your Blynk authentication token
char auth[] = "your_blynk_auth_token";
// Replace with your WiFi credentials
char ssid[] = "your_wifi_ssid";
char pass[] = "your_wifi_password";
// DHT sensor setup
#define DHTPIN D4 // Pin where the DHT11 is connected
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// Soil moisture sensor setup
#define SOIL_MOISTURE_PIN A0
// Relay module setup
#define RELAY_PIN D1
int relayState = LOW;
// Virtual Pins for Blynk app
#define MANUAL_MODE_PIN V0
#define SOIL_MOISTURE_PIN_V1 V1
#define TEMPERATURE_PIN_V2 V2
#define HUMIDITY_PIN_V3 V3
BlynkTimer timer;
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
dht.begin();
// Set relay pin as output
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, relayState);
// Setup a function to be called every 10 seconds
timer.setInterval(10000L, sendSensorData);
}
void loop() {
Blynk.run();
timer.run();
}
void sendSensorData() {
// Read soil moisture value
int soilMoisture = analogRead(SOIL_MOISTURE_PIN);
// Read temperature and humidity from DHT sensor
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Print sensor data to Serial Monitor
Serial.print("Soil Moisture: ");
Serial.print(soilMoisture);
Serial.print(", Temperature: ");
Serial.print(temperature);
Serial.print(", Humidity: ");
Serial.println(humidity);
// Send data to Blynk app
Blynk.virtualWrite(SOIL_MOISTURE_PIN_V1, soilMoisture);
Blynk.virtualWrite(TEMPERATURE_PIN_V2, temperature);
Blynk.virtualWrite(HUMIDITY_PIN_V3, humidity);
// Check soil moisture and control relay
if (soilMoisture < 500) { // Adjust the threshold based on your sensor
// Soil is dry, turn on the relay (watering)
controlRelay(LOW);
} else {
// Soil is wet, turn off the relay
controlRelay(HIGH);
}
}
void controlRelay(int state) {
if (state != relayState) {
digitalWrite(RELAY_PIN, state);
relayState = state;
Blynk.virtualWrite(MANUAL_MODE_PIN, relayState);
}
}
BLYNK_WRITE(MANUAL_MODE_PIN) {
int manualMode = param.asInt();
controlRelay(manualMode);
}
Can anyone please help me out and tell me why my soil moisture sensor is showing values of 700 in air while it shows 589 or somewhat like that in water.
I am using NODEMCU, DHT SENSOR, RESISTIVE SOIL MOISTURE SENSOR, AND 5V RELAY MODULE, programmed in aruduino ide
@P-p12 Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Copy and paste these if you can’t find the correct symbol on your keyboard.
It would probably help if you provided a link to the actual sensor you are using, along with details of how it’s powered and connected to your NodeMCU.
Okay, I’m not sure what you’re expecting from this Blynk community forum, but clearly you’re not going to get assistance with this issue unless you share far more information than you currently are.
Personally, If I have to go through a “20 questions” type of process each time you post something then I tend to disengage from the conversation because it’s too tedious.
Well, I saw the same sensor, the capacitive one, being used to collect data like 700 in water and 300 in air in other’s project. but mine didn’t do that, and moreover I am confused where to put in the map function in the first code I provided to inverse the values. Please help me just with that.