In today’s era of rapid technological development, unified control of intelligent devices via mobile phones has gradually gained people’s favor. This method uses a microcontroller to establish a connection between a mobile phone and an intelligent device through a WiFi module and the Internet network to achieve remote control of the intelligent device.
In this project, we will focus on the WiFi infrastructure of ESP32 and control the smart farm system via WiFi web page.
kidsIOT Mainboard×1 |
Water Level Sensor×1 |
Soil Moisture Sensor×1 |
Passive Buzzer×1 |
White LED Module×1 |
Photoresistor×1 |
Temperature and Humidity Sensor×1 |
Motor×1 |
Water Pump×1 |
GPIO Shield×1 |
Relay Module×1 |
Fan×1 |
F-F DuPont Wires |
Sink×2 |
Battery Holder×1 |
M-F DuPont Wire×1 |
Water Pipe×1 |
AA Battery(Not provide)×6 |
Slotted Screwdriver×1 |
Wire×7 |
Just put the structural shapes assembled in Project 02, Project 06 and Project 07 together .
Module |
GPIO Shield |
kidsIOT Mainboard |
---|---|---|
Water Level Sensor |
G→G,V→V,S→S4 |
No.4 port(control pin of S4 is io39) |
Soil Moisture Sensor |
G/V/io33 port(G→G,V→V,S→io33) |
|
Photoresistor |
No.6 port(control pin is io36) |
|
Temperature and Humidity Sensor |
No.8 port(control pin is io5) |
|
White LED Module |
No.7 port(control pin is io16) |
|
Passive Buzzer |
No.2 port(control pin is io2) |
|
Motor |
No.9 port(IN+control pin is io18,IN-control pin is io19) |
|
Relay Module |
No.3 port(control pin is io26) |
Connect the kidsIOT mainboard to your computer via USB cable, connect the external power supply and turn the DIP switch on the mainboard to ON end.
The Wi-Fi library supports configuring and monitoring ESP32 Wi-Fi networking functions. Supported configurations:
station mode (STA mode or Wi-Fi client mode), at this time the ESP32 is connected to the access point (AP).
AP mode (Soft-AP mode or Access Point mode), at this time the base station is connected to the ESP32.
station/AP coexistence mode (ESP32 is both an access point and a base station connected to another access point).
Various security modes for the above mentioned modes (WPA, WPA2, WPA3, etc.).
Scan access points (including active scanning and passive scanning).
Monitor IEEE802.11 Wi-Fi packets using promiscuous mode.
For details about wifi, tap it:https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html
Espressif official website:https://www.espressif.com.cn/en/home
Tap , click the “communication” module in the “Extension” , then select “Web Page Editing PRO” and click to return to the programming interface.
Enter the WiFi name and password to connect to the WiFi hotspot.
Read the WiFi IP address.
Set up a card on the web page, and its card label, card unit and card type correspond one to one.
Add a button card to the web page.
① Change the WiFi name and password in the code to your own WiFi name and password, and connect to the WiFi hotspot.
② Display the WiFi IP address on the OLED.
③ Set a card on the web page, the card label is “Temperature”, the card type is “Temperature”, the card unit is “℃”, the card ID is 1, and the temperature value is 30.
④Set up a card on the web page. The card label is “Air humidity”, the card type is “Humidity”, the card unit is “%RH”, the card ID is 2, and the temperature value is 60.
⑤ Complete Program
Click to upload the above complete code to the kidsIOT mainboard and power on. Once connected to WiFi, the OLED on the board will display the corresponding IP address (Here we take the IP address: 192.168.0.48 as an example ).
Note: When the PC, mobile phone and kidsIOT mainboard are connected to the same network, this webpage can be opened on the PC and mobile phone at the same time. Here is the IP address displayed on the OLED on your own kidsIOT board
You can enter “http://[IP address displayed on the OLED display]” in the browser to view the web page . In this way, you will create a simple web page that displays a fixed temperature information and a fixed humidity information:
PC:
Mobile phone:
Tap , click “Actuator” and find “esp32 Passive buzzer” and “DC Motor for esp32” . Click “Sensor” and find “DHT sensor for ESP32” .
Click the “communication” , then select “Web Page Editing PRO” and click to return to the programming interface.
① Change the WiFi name and password in the code to your own WiFi name and password, and connect to the WiFi hotspot.
② Display the WiFi IP address on the OLED.
③ Initialize pin IO5 of the temperature and humidity sensor, and select the mode dht11.
④ Initialize the pin IO33 of the soil moisture sensor, the pin IO39 of the water level sensor, and the pin IO36 of the photoresistor, and set them to “Input” mode.
⑤ Initialize the pin IO16 of the LED module, the pin IO26 of the relay module and the pin IO2 of the passive buzzer, and set them to “Output” mode.
⑥ Define four global variables, namely “Val1”, “Val2”, “Val3” and “Val4”.
⑦ Set up multiple cards of the web page, namely Temperature,Air humidity,Soil humidity,Water level and Brightness.
⑧ Set the button card to control LED on and off.
⑨ Set the button card to control the fan on and off.
⑩ Set a button card to control the relay’s on and off, thereby controlling whether the water pump pumps water.
⑪ Set the button card for playing music.
⑫ Complete Program
Click to upload the above complete code to the kidsIOT mainboard and power on. Once connected to WiFi, the OLED on the board will display the corresponding IP address. You can enter “http://[IP address displayed on the OLED]” in the browser to view the web page . The sensor data can be viewed on the web page, and LEDs and fans can also be controlled.
PC:
Mobile phone:
Sensor data |
Control |
---|---|
Ambient temperature(℃) |
LED on/off |
Ambient humidity(%RH) |
Fan on/off |
Soil moisture |
Water pump on/off |
water level of sink |
Play music |
Light(0~4095) |
A: Please move the kidsIOT board to the vicinity of the router, press the reset button on the board to restart kidsIOT, and wait patiently for the connection. If you still can’t connect, please check whether the WiFi name and password are filled in correctly.
When multiple people are connecting it, the router’s CPU resources are insufficient. Restart the router and reconnect to the network.
The router system has been used for too long. Restart the router.
When wireless interference occurs and the wireless signal is unstable, please do not use it through the wall.