Introduction: Automatic Irrigation on Thingspeak With NodeMCU12E and Electromagnetic Valve, FC-28, DHT11, One Channel Relay.


Hi everyone, I would like to share my last little project. It is an automatic irrigation system with NodeMCU12E, electromagnetic valve, soil moisture sensor, temperature and humidity information. Measured values are displayed on with their API key.

Program steps: -Measurement of humidity value of soil connected to analog input A0. If it exceeds a certain value range, the Digital output D5 will activate a relay that triggers the opening of the electromagnetic valve. If it does not go out of range, the valve remains closed. After this, the valve open state information will be uploaded to thing speak field one. 0 - Valve close 1 - Valve open

-After opening or closing the valve, the program reads the value of the next sensor every 30 seconds and sends it to thing speak fields.

The components I used in the project:
- NodeMCU12E
- 2x DHT11 Temperature and Humidity sensor
- FC-28 Soil Moisture sensor
- 3.3V One channel relay
- LM2596 DC-DC Step down voltage converter
- 12V Solenoid valve
- 12V 2A DC adapter

Step 1: Schematic

Step 2: Add to Code

const char* ssid = "_______"; //Write the SSID name of your network.

const char* password = “________"; //Write your password.

unsigned long myChannelNumber = ______; // Copy the channel number from thing speak.

const char * myWriteAPIKey = "________"; // Copy the API key from thing speak channel.

const int valueOpen = 850; // when the measured value is greater than 850, the relay (D5 LOW) will open the solenoid valve

const int valueClose = 750; // when the measured value is less than 750, the relay (D5 HIGH) will close the solenoid valve

if (sensorValue > valueOpen){

digitalWrite(Ventil, LOW);

ThingSpeak.writeField(myChannelNumber, 1, 1, myWriteAPIKey);

Serial.println("Ventil otvoren.");

delay(60000); // Set time how open it valve will be

digitalWrite(Ventil, HIGH);

Step 3: Code

Step 4: