X
Home > Blog > STEM for Arduino > Let's Make a WiFi Web Page Controls Smart Farm System!
Let's Make a WiFi Web Page Controls Smart Farm System!
By r September 6th, 2024 46 views
Note: Do not allow water to overflow from sinks and soil troughs when using the device. Sprinkling water on other sensors will cause a short circuit and device failure. Sprinkling water on batteries will cause heating and explosion. Please be careful when using the device, especially when used by young children, it must be under the supervision of parents. To ensure safe operation of the device, please follow relevant usage guidelines and safety regulations.
Img

1. Description

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.

2. Components

Img

Img

Img

Img

kidsIOT Mainboard×1

Water Level Sensor×1

Soil Moisture Sensor×1

Passive Buzzer×1

Img

Img

Img

Img

White LED Module×1

Photoresistor×1

Temperature and Humidity Sensor×1

Motor×1

Img

Img

Img

Img

Water Pump×1

GPIO Shield×1

Relay Module×1

Fan×1

Img

Img

Img

Img

F-F DuPont Wires

Sink×2

Battery Holder×1

M-F DuPont Wire×1

Img

Img

Img

Img

Water Pipe×1

AA Battery(Not provide)×6

Slotted Screwdriver×1

Wire×7

3. Assembly Steps

Just put the structural shapes assembled in Project 02, Project 06 and Project 07 together .



Img

4. Wiring Diagram

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)


Note:You need to use a slotted screwdriver to loosen the screws at the NO port and COM port of the relay module. Use a m-f DuPont wire to connect the COM port on the module to V on the GPIO shield, and connect the red wire of the water pump to the NO port of the relay module, the black wire of the water pump and the f--f Dupont wire are connected to G of the GPIO shield. After connecting the wires, use the screwdriver to tighten the screws at the NO port and COM port.

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.

Img

5. WiFi Web Page Display

Img

(1). Knowledge

Img

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

(2). Programming Steps
Step 1:Add the “Web Page Editing PRO” library

Tap Img, click the “communication” module in the “Extension” , then select “Web Page Editing PRO” and click Imgto return to the programming interface.

Img

Img

Img

Step 2:Description of the Building Block

Img

Enter the WiFi name and password to connect to the WiFi hotspot.

Img

Read the WiFi IP address.

Img

Set up a card on the web page, and its card label, card unit and card type correspond one to one.

Img

Add a button card to the web page.

Step 3:Write the Program

① Change the WiFi name and password in the code to your own WiFi name and password, and connect to the WiFi hotspot.

Img

② Display the WiFi IP address on the OLED.

Img

③ 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.

Img

Img

④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.

Img

Img

⑤ Complete Program

Img

(3). Test Result

ClickImg 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 ).

Img

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:

Img

Mobile phone:

Img

6. WiFi Web Page Controls Smart Farm System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Add “Passive Buzzer”, “DC Motor”, “Temperature and Humidity Sensor” and “Web Page Editing PRO” libraries

Tap Img, 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 Imgto return to the programming interface.

Img

Img

Img

Img

Img

Step 3:Write the Program

① Change the WiFi name and password in the code to your own WiFi name and password, and connect to the WiFi hotspot.

Img

② Display the WiFi IP address on the OLED.

Img

③ Initialize pin IO5 of the temperature and humidity sensor, and select the mode dht11.

Img

④ 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.

Img

⑤ 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.

Img

⑥ Define four global variables, namely “Val1”, “Val2”, “Val3” and “Val4”.

Img

⑦ Set up multiple cards of the web page, namely Temperature,Air humidity,Soil humidity,Water level and Brightness.

Img

⑧ Set the button card to control LED on and off.

Img

⑨ Set the button card to control the fan on and off.

Img

⑩ Set a button card to control the relay’s on and off, thereby controlling whether the water pump pumps water.

Img

⑪ Set the button card for playing music.

Img

⑫ Complete Program

Img

(2). Test Result

ClickImg 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.

Img

PC:

Img

Mobile phone:

Img

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)

7. Common Problems
Q1:You can’t connect the WiFi?

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.

Q2:When remotely operating other sensors on the web page, the response is very slow?
A: Reasons:
  • 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.

For router related knowledge, please search on google yourself.
HOW to Make an Automatic Irrigation System with KidsIOT
Previous
HOW to Make an Automatic Irrigation System with KidsIOT
Read More
HOW to Simulate Rainwater Detection with KidsIOT
Next
HOW to Simulate Rainwater Detection with KidsIOT
Read More
Message Us