Using a NodeMCU ESP8266 development board, a moisture sensor, a Nokia 5110 LED display (with PCD8544 CMOS LCD controller/driver and Lua - we will build a moisture sensor which will:
- Upon startup or reset execute the below only once
- Show welcome screen for three seconds
- average moisture reading using 10 sample reads over 5 seconds while showing the user a "please wait message"
- output average moisture for two minutes
- turn display off
- NodeMCU ESP8266 compatible development board
- Display with PCD8544 controller - e.g. Nokia 5110
- NodeMCU firmware with the following modules included: adc, file, gpio, i2c, net, node, spi, tmr, u8g2, uart
- u8g2 configuration - ensure you include your fonts. For the example here we will need the 6x10_tf and 5x8_tf font
- Moisture sensor with
- 3.3V VCC
- GND
- Analog Output with value output representing moisture
- Breadboards and jumper wires
For simplicity, you can download a suitable firmware here.
The firmware was created using the online service nodemcu-build.com
Restrictions- This tip is focused on Lua and ESP8266
- The pin connections are guaranteed to work with
- our Nokia 5110 displays. Other similar displays might have a different pin layout and you will need to adapt to your specific module.
- our moisture sensor
- The tip uses SPI, hence there might be conflicts if you are using other SPI modules.
- Using a single breadboard might be a bit restrictive due to the width of the NodeMCU. We have used two of our expandable breadboards and connected them together.
We connect the display and moisture sensor to the NodeMCU. See our other tip for more details - click here. There is a small change (for VCC) - see below.
Rather than feeding VCC for display and sensor straight from the 3.3V PIN on the NodeMCU, we will connect those to individual GPIOs.
This will allow us to turn them on and off as needed in preparation of:
- Power saving
- Using more than one analog sensor on the single A0 PIN on the NodeMCU
To read ADC0 (A0), we will need to make sure that the firmware has the ADC module include.
Keep in mind that - after the display and sensor is turned off, the NodeMCU board is still "running" and consuming power.
To get a reading either reconnect the board or - if already connected - hit the reset button - for this to work, you need to ensure that code is uploaded as init.lua.
You will also notice in the picture that we have merged two breadboards together to one to get more width. We did this to make the wiring easier.
Wiring
Display
PCD8544/LCD -> ESP8266
Pin 1 - RST -> D0/GPIO16Pin 2 - CE (CS) -> D8/GPIO15 - pull down with 10k resistor to GNDPin 3 - DC -> D4/GPIO2Pin 4 - DIN -> D7/HMOSI (fixed - you can't use a different pin)Pin 5 - CLK -> D5/HSCLK (fixed - you can't use a different pin)Pin 6 - VCC -> D1/GPIO5Pin 7 - BL -> Not used in this examplePin 8 - GND -> GND - from Development board
Moisture Sensor
Sensor -> ESP8266
VCC -> D2 /GPIO4GND -> GND - from Development boardDO -> Not usedAO -> A0/ADC0
Comments