Introduction: Interface Moisture Sensor With NodeMCU
Hey, Makers!
In this Instructables, you will learn how to set up the Moisture sensor on your NodeMCU. And learn about how the sensor works based on the moisture level, and how to check output readings from the Serial monitor.
Step 1: List of Components
Here is the list of components required to get started with the Instructable,
Hardware Components
- NodeMCU
- Moisture sensor
- Breadboard
- Jumper Wires
- Micro USB Cable
Software Components
- Arduino IDE (installed with esp8266)
Step 2: Description
This Moisture Sensor can be used for detecting the moisture of soil or judge if there is water around the sensor, let the plant in your garden able to reach out for human’s help when they are thirsty.
This sensor is very easy to use, you can just simply insert in into the soil and read the data. With this sensor, you can make a small project that can let the plant send a message to you like ” I am thirsty now, please feed me some water.”
Step 3: How to Setup Moisture Sensor to NodeMCU
Wiring the Moisture sensor to the NodeMCU is really easy.
The wiring connections are made as follows:
Connect the two pins of the moisture sensor to the two pins on the Amplifier circuit using jumper wires.
Connect the Vcc from the Amplifier to the 3.3V pin on the NodeMCU.
Connect the GND pin to the ground (GND) pin on the NodeMCU.
Connect the Analog pin to the A0 pin on the NodeMCU.
Connect NodeMCU to PC via a USB cable.
After your completed with wiring connections, then insert the sensor into the soil or place it in anywhere you want.
(In this Instructable I have used water for the Demonstration)
Step 4: Preparing the Arduino IDE
After downloading the Arduino IDE navigate to
- File tab and then click on Preferences.
- In the additional Boards, Manager URLs add the following link (http://arduino.esp8266.com/stable/package_esp8266com_index.json)
- Click OK and then navigate to
- Tools - Boards - Boards Manager
In the search field type esp8266 > click the esp8266 by ESP8266 Community - Click Install
Now you have setup the Arduino IDE to work along with the NodeMCU.
Step 5: Save * Compile * Upload
- Goto Tools
- Board > NodeMCU 1.0 (ESP - 12E Module)
- Port ( Choose the right Port )
**Make sure you have your NodeMCU model selected and the correct serial port ticked (see pics). Then just click the Upload button**
Ready To GO
Step 6: Coding Time
int WET= 16; // Wet Indicator at Digital pin D0 int DRY= 2; // Dry Indicator at Digital pin D4
int sense_Pin = 0; // sensor input at Analog pin A0 int value = 0;
void setup() { Serial.begin(9600); pinMode(WET, OUTPUT); pinMode(DRY, OUTPUT); delay(2000); }
void loop() { Serial.print("MOISTURE LEVEL : "); value= analogRead(sense_Pin); value= value/10; Serial.println(value); if(value<50) { digitalWrite(WET, HIGH); } else { digitalWrite(DRY,HIGH); } delay(1000); digitalWrite(WET,LOW); digitalWrite(DRY, LOW); }
Upload this program to the NodeMCU by downloading the attached code "Moisture_NodeMCU.ino" below and check the output in the serial monitor.
Attachments
Step 7: OUTPUT
You can see the serial monitor for the output reference. And I have interfaced LEDs to make the Instructable more attractive. You can also interface with any thing to make your project become AWESOME.
That's all makers!
I hope you found this instructable most useful.
You can contact me by leaving a comment. If you like this instructable probably you might like my next ones.
Thank You.

Participated in the
Makerspace Contest 2017
7 Comments
Question 3 years ago on Step 6
why are you dividing by 10?
5 years ago
Similar as to.my comment on your Arduino - moisture project, if you use the analogue output of the module there is no need to use the module at all as it has no function. Just connect the sensor to the analogue pin of thenodemcu
5 years ago on Step 7
what if we want to send the data to remote server how to do then,please help
5 years ago
can the system above apply to blynk apps? becoz when i "tried" connect it to the blynk apps, n of coz will need connect to GPIO as well, in the end the value i get from the blynk apps didnt stable. Is there any possible coding to edit into the coding that shown above?
TQ
6 years ago
I get an error after uploading the sketch on the serial monitor:
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
I connected the board to my laptop. I googled the error msg and saw that it is most likely a power issue. It is recommended to use a powerful power source. But since the project uses the serial monitor how can I use an external power source?
Do you know any other reason why I get this error?
ps: I tried with multiple nodemcus on multiple computers including desktops. Boards functions as they should if I don't use an output pin.
Reply 5 years ago
Check that you're using the exact same pin as in the instructions. I had a similar problem and that was the cause.
6 years ago
I Like it.