KidsBlock Tutorial

1. Mainboard_Introduction:

Refer to the link:http://kd2076-kidsbits-stem-electronic-building-block-programming.readthedocs.io/

2. KidsBlock Development Environment Configuration:

Please refer to the link to install and use the KidsBlock software: https://kidsblocksite.readthedocs.io/en/latest/


Note: The control board used in this kit is the kidsIOT board. For importing the kidsIOT board, libraries and sample codes, please refer to the following content.



1. ClickImg to enter the main page, and select the control board needed. In this project, we select the kidsIOT mainboard and click Connect, then it is connected. Click Go to Editor to return the code editor. IconImg will change into Img and Img will change into Img. This means the kidsIOT mainboard and ports(COM)are connected.

5

6

7

image8

2. If the kidsIOT mainboard is connected , but iconImg doesn’t change into Img. You need to click to connect the COM port. ClickImg. Then you will find a page pop up, showing Connected.

image

8

9

To disconnect the port, just clickImg and Disconnect.

10

Note:If you want to update libraries of KidsBlock, click then Clear cache and restart.

12

3. Imgstands for extension libraries of sensors and modules. Click Imgto enter the page of extension libraries, click a sensor or module to add. For example, if click the esp32 passive buzzer module,Not loaded will change into Loaded. Then the passive buzzerImg is added.
img

image

image

ClickImg to return to the code editor. Then you can view the passive buzzer in the blocks area.

image

If you want to delete the passive buzzer, clickImg to select the “esp32 Passive buzzerImg. Then Loaded will change into Not loaded. Then the passive buzzer is deleted.

image

image

The way of deleting other sensors or modules is as same as the passive buzzer.

4. How to open SB3 type files:

The first method: Double-click SB3 type files to open them. For instance, openImg, then we need to double-click it.

image

The second method: Open Kidsblock,click file and Load from your computer,then select the SB3 type file on the computer.(for exampleImg)

image

image

image

3. Projects:

Project 01: Lighting System

Img

1. Description

As an introductory project for smart farms, lighting up LED is one of the most basic KidsBlock (based on Scratch) practical projects. It is designed to let beginners understand the hardware and software programming of kidsIOT board (based on ESP32) and master basic circuit and programming knowledge.

In this project, you will learn the basic connections and settings of the kidsIOT board in the KidsBlock graphical programming environment, as well as control the digital pin to output level to control the state of LEDs, LED breathing lights, and button control of LEDs, and you can also apply them in your home or lounge.

2. Components

Img

Img

Img

kidsIOT Mainboard×1

White LED Module×1

Button Module×1

Img

Img

Img

USB Cable×1

Wire×2

Lighting System LEGO Pieces×1

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2: Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Process 5:

Img

Process 6:

Img

Process 7:

Img

Complete

Img

4. Wiring Diagram

Module

kidsIOT Mainboard

White LED Module

No.2 port(control pin is io2)

Button Module

No.4 port(control pin is io27)

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. State of LED

Img

(1). Knowledge

(1)To keep the light on, the electricity is needed. When we say that there is electricity, we mean that there is current flowing through an electrical appliance like a light. Current comes to our home from the power station via wires. And the generator of a power station is the power supply, which enables to provide voltage and current. The battery we usually use is also the power supply. Wires can be used to conduct electricity, which connect a path for the current to flow. This path is called a circuit. If we want to make a lamp emit light, both a power supply and a complete circuit are needed.

img

(2). Programming Steps
Step 1:Description of the Building Blocks

Img

This block indicates that when the kidsIOT board is started, the code will be run.

image

Set input or output to the specified pin. input means input mode,output means output mode. Select input-pullup can set the input mode for the pin and make it become high level.

image

Set high or low to the specified pin. Select high means to set high level for the pin. If there is voltage and current, the LED will be on. Select low means to set low level for the pin. If there is no voltage and current, the LED will be off.

image

This is a delay block. The number 1 can be changed to whatever number of seconds it is delayed.

image

It will do one thing forever.

Step 2:Write the Program

① Open the KidsBlock(based on Scratch)software to select the kidsIOT board and port(COMx).

Img

② Drag the instruction block Imgin the Events module to the script area.

Img

③ Drag the instruction block Img in the “Pin” module to the script area. Since the white LED module is connected to the No. 2 interface on the mainboard (The control pin is io2) and it is in output mode, so change “input” to “output”.

Img

④ Drag the block Img in the “Control” module to the script area.

Img

⑤ Drag the block Img in the “Pin” module to Img.

Img

⑥ Drag the block Img in the “Control” module to Img and set to delay 1 second.

Img

⑦ Copy the code block Img into Img, and change “High” to “Low”.

Img

(3). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, the white LED will be on and off for 1s.

We can also realize breathing light effect, flowing water light effect and police light effect via LEDs.

Level

Function

high

LED lights up

low

LED lights off

6. LED Breathing LED

Img

(1). Knowledge

The IO port on the kidsIOT mainboard outputs digital signals, which can only output high level and low level. For example, in the lighting up LEDs project, the digital output of the ESP32 is used, which has only two levels: high (3.3V) and low (0V).

Assuming that the high level of the kidsIOT board is 3.3V and the low level is 0V, then if you want to output a voltage between 0 and 3.3V, you need to use PWM (Pulse Width Modulation). PWM can output different voltage values, like a progress bar, which is analog output.

Img

PWM uses digital control to generate square waves with different duty cycles (a signal that constantly switches between high level and low level) to control the analog output.

Img

PWM has three elements: frequency (Hz), period (s) and duty cycle (%)

  • PWM frequency (f): It refers to the number of PWM cycles in one second.

  • PWM period (T): Period=1/frequency (T=1/f, where 1 is 1 second), for example: the frequency is 50Hz, which means that one period is 20ms, then one second is 50 PWM cycles.

  • PWM duty cycle: It refers to the ratio of high level time to the entire cycle time within a pulse cycle. For example: the cycle time is 10ms, the pulse width time is 8ms, then the low level time is 2ms, and the total duty cycle is 8/(8+2)= 80%.

Img

PWM can change the effective output voltage by changing the duty cycle in one cycle under the appropriate signal frequency. Among the levels output by the IO port at the specified time, the more high levels, the greater the PWM value and the brighter the LED.

Img

(2). Programming Steps
Step 1:Description of the Building Blocks

The following are “Variable” command blocks.

Img

This block is used to create “Variable”. You can declare “global” or “local”, or set the type, name and value of the variable, item is the variable name.

Img

Get variable item.

Img

Set the value of variable item.

Img

Set the variable item mode to increase item by 1 or decrease item by 1 every time the loop is executed.

image

Set the string variable item.

Img

Img

This block is used to set the PWM. You need to set the corresponding pin via the channel (a total of 16 channels (0~15)) and the output value, so that the PWM value can be output.

Img

This is a conditional loop control statement that exit the loop when the number of loops is met. For example: 10 means that the loop is executed 10 times. The number 10 can be changed to other numbers.

Step 2:Write the Program

① Drag the instruction block Imgin the Events module to the script area.

Img

② Drag the instruction block Img in the “Pin” module to the script area, change “input” to “output”.

Img

③ Drag the block Img in the “Variable Type” module to the script area.

Img

④ Drag blocks Img and Img in the “Control” module to the script area.

Img

⑤ Drag the instruction blockImgin the “Pin” module to the script area.

Img

⑥ Drag the blockImgin the “Variable Type” module to the script area.

Img

⑦ Drag the blockImgin the “Variable Type” module to the script area,“++” means that each time the loop is executed, item will be increased by 1.

Img

⑧ Drag the block Img in the “Control” module to the script area and set the delay to 0.01 second, the repeat 10 to 255, for the corresponding PWM code block outputs 0~255. In this way, the LED light will slowly turn from dark to bright.

Img

⑨ Copy the code block Img,change “++” to “”, then LED will slowly turn from bright to dark.

Img

⑩ Complete Program

Img

(3). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, the LED will gradually brighten and then dim, like breathing.

7. Read the value of the button module

Img

(1). Knowledge

The principle of the button module is based on the switch circuit.

When the button is pressed, the switch closes, allowing current to pass through the button to GND, then the digital input pin of the kidsIOT motherboard detects a low level signal.

When not pressed, the switch is in the off state, the pin is pulled high by the pull-up resistor, and the digital input pin detects a high-level signal.

(2). Programming Steps
Step 1:Description of the Building Blocks

Img

The block is used to set serial baud rate(generally, the baud rate 9600 is taken as an example)

Img

This block is used to set print mode for the serial port. warp means line feed printing, no-warp means no line feed printing, HEX means hexadecimal printing.

Img

It is used to read the digital signal value of the specified pin(0 or 1).

Step 2:Write the Program

① Drag the instruction block Imgin the Events module to the script area.

Img

② Drag the instruction blockimage in the Serial module to the script area and take the baud rate 15200 as an example.

Img

③ Drag the block Img in the “Pin” module to the script area. Since the button module is connected to No. 4 port ( the control pin is io27) , so change pin IO2 to IO27.

Img

④ Drag the block Img in the “Variable Type” module to the script area, then change item to “Button”.

Img

⑤ Drag the block Img in the “Control” module to the script area.

Img

⑥ Drag the block Img in the “Variable Type” module to the script area, then change item to “Button”.

Img

⑦ Drag the block Img in the “Pin” module to the script area, then change pin IO2 to IO27.

Img

⑧ Drag the instruction blockimage in the Serial module to the script area.

Img

⑨ Drag the block Img in the “Variable Type” module to the script area, then change item to “Button”.

Img

⑩Drag the block Img in the “Control” module to the script area and set the delay to 0.1 second.

Img

⑪ Complete Program

Img

(3). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200. When the button is not pressed, the serial monitor prints the digital signal 1, when pressed, the digital signal 0 is printed.

Img

8. Self-locking button function

Img

(1). Knowledge

Self-locking button: It locks when pressed and will not automatically pop up. It will pop up only when pressed again, which is very similar to a switch. The switch can be turned on and off using self-locking buttons. If it is controlled by the kidsIOT mainboard, this operation can also be achieved via software.

(2). Programming Steps
Step 1:Description of the Building Blocks

Img

It is a conditional statement code executing if-then function: If the logical judgment statement in Img is satisfied, the code statement below then is executed.

Img

It is a conditional statement: If the logical judgment statement in imageis satisfied, the loop will be executed continuously. If not, the loop will be terminated.

Img

It is a conditional statement code executing if-then-else function: If the logical judgment statement in Img is satisfied, the code statement below then is executed, otherwise, the code below else is executed.

Step 2:Write the Program

① First define a Value to get the button status, and then define a Button. At the same time, select the serial baud rate to 15200 and the control button pin IO27 to “input” mode.

Img

②Assign the read button value to “Value”.

Img

③ Determine whether the button is pressed. When pressed, change the value of “Button” and print it.

Img

Description

Img

The delay of 0.01 seconds is the button anti-shake function. After detecting that the button is closed, a delay program is executed, with a delay of 5ms ~ 10ms (depending on the mechanical characteristics). After the jitter disappears, the button status is detected again. If the closed state level is still maintained, then a button is pressed.

When it is released, a delay of 5ms ~ 10ms is also required. Only after the jitter disappears can the button processing program be transferred. When the button is pressed once, the button becomes 1, when pressed again, it becomes 0.

④ Complete Program

Img

(3). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200. When the button is pressed, the serial monitor prints the number 1, and when pressed again, the monitor prints the number 0, so as to achieve the self-locking function of buttons.

Img

9. Lighting control system

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Write the Program

① Based on the code of the self-locking button above, add the relevant blocks for turning the LED on and off.

Img

② Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard, then power up via the USB cable. When the button is pressed for the first time, the LED is turned on. When pressed for the second time, the LED is turned off. When pressed for the third time, the LED is turned on again…, which is consistent with the LED switch in real life.

Img

10. Common Problems

Q1: There are errors in kidsIOT board programming program

A: Please check whether the board type is correct.

Please check whether the USB port number is selected correctly.

Q2: The LED does not light up after burning the code

A: Please confirm whether the pins in the code are consistent with the actual wiring. If there is an error, please wire correctly according to the pins in the code.

Q3: Are the buttons insensitive? Sometimes it can be detected, sometimes not?

A: Modify the button delay time and set it to an appropriate delay.

Img

Project 02: Light Controlled System

Img

1. Description

This light controlled system is composed of a photoresisitor, a LED and a kidsIOT mainboard, which can realize intelligent lighting control, saving energy and improving usage efficiency.

It empowers to automatically detect day and night as well as light intensity, making the entire system more intelligent and energy-saving.

When the ambient brightness is lower than the set value, the photoresisitor will detect a signal and automatically turn on the LED; when higher than the set value, it will send another signal to turn off the LED.

2. Components

Img

Img

Img

kidsIOT Mainboard×1

Photoresistor×1

White LED Module×1

Img

Img

Img

Wire×2

USB Cable×1

Light Controlled System LEGO Pieces×1

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2:Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Process 5:

Img

Complete

Img

(Note: Do not dismantle it, it will still be used in project 10.)

4. Wiring Diagram

Module

kidsIOT Mainboard

White LED Module

No.2 port(control pin is io2)

Photoresistor

No.4 port(control pin is io39)

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. Read the value of the photoresistor

Img

(1). Programming Steps
Step 1:Description of the Building Blocks

Img

It is used to read the analog signal value of the specified pin.

Step 2:Write the Program

① Set the baud rate to 15200.

Img

② Set the pin IO39 connected to the photoresistor ( control pin io39) to the “input” mode.

Img

③ Define a “Photosensor” variable to store the value of the photoresistor.

Img

④ Store the read value of the photoresistor in the “Photosensor” variable.

Img

⑤ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200. Then the serial monitor will print the value read by the photoresistor. When the light detected by the photoresistor is brighter, the monitor prints a larger value, otherwise, the monitor prints a smaller value.

Img

6. Light Controlled System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Write the Program

① Delete the “Wait 0.5 seconds” block in the complete program above, and then drag “Set pin IO2 mode input” block from the “Pin” module to the script area. Change “input” to “output”.

Img

② Determine the value read by the photoresistor. When the value is less than or equal to 700, the LED will turn on, otherwise, the LED will turn off.

Img

③ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard, then power up via the USB cable. When the light is strong during the day and the value of the photoresistor is greater than 700, the LED will turn off. After dark, when the value is less than or equal to 700, the LED will automatically turn on.

Img

7. Common Problems

Q1: The value detected by the photoresistor cannot be 0?

A: Because in actual operation, even if all the lights are turned off and the room is very dark, the value is only close to 0.

Q2: After burning the sample code, why can’t the LED light up even when the lights are turned off in the room?

A: You can set the value read by the photoresistor to be larger. The value in the sample code is 700, which can be adjusted to 1000 or even larger.

Project 03: Automatic Feeding System

Img

1. Description

The automatic feeding system is composed of a kidsIOT main board, an ultrasonic sensor and a servo. The ultrasonic sensor is used to detect the distance of pets in the feeding area. When the pet approaches the food bowl, the sensor detects that the distance is getting closer. After triggering the signal, it controls the servo to open the feed box and automatically feed the animals.

2. Components

Img

Img

Img

Img

kidsIOT Mainboard×1

Ultrasonic Adapter Board×1

Ultrasonic Sensor×1

Servo×1

Img

Img

Img

Wire×1

USB Cable×1

Automatic Feeding System LEGO Pieces×1

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2:Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Process 5:

Img

Process 6:

Img

Process 7:

Img

Process 8:

Img

Process 9:

Img

Process 10:

Img

Process 11:

Img

Process 12:

Img

Process 13:

Img

Process 14:

Img

Process 15:

Img

Process 16:Initialize the servo angle

Wiring of servo Img

First write the following code in KidsBlock software and upload the code to the kidsIOT mainboard, then the servo will rotate 190° . (Note: If the servo can not rotate, you can press the RESET button on the kidsIOT board.)

Img

Process 17:

Img

Process 18:

Img

Process 19:

(Note: Do not twist the servo)

Img

Process 20:

Img

Process 21:

Img

Complete

Img

4. Wiring Diagram

Module

kidsIOT Mainboard

Ultrasonic Adapter Board

No.9 port(Trig–io18,Echo–io19)

Servo

G/V/io33 port(Brown→G,Red→V,Orange→io33)


Ultrasonic Sensor

Ultrasonic Adapter Board

Vcc

VCC

Trig

Trig

Echo

Echo

Gnd

GND

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. Servo rotation

Img

(1). Programming Steps
Step 1:Description of the Building Block

Img

Set the servo’s channel and output (rotation) angle to the specified PWM pin.

Step 2:Write the Program

① Set the pin IO33 (control pinio33) connected to the servo to “Output” mode.

Img

② Initialize the control channel of the servo to CH2 (LT1) and the initial angle to 190°, with a delay of 0.5 seconds.

Img

③ The servo rotates from 190° to 120° and then to 60° every 0.5 seconds.

Img

④ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard, then power up via the USB cable, then servo will rotate.

6. Read the Value of Ultrasonic Sensor

Img

(1). Programming Steps
Step 1:Add the Ultrasonic Sensor

Tap the “Sensor” module in the “Extension” , then select “Ultrasonic Sensor” and click Imgto return to the programming interface.

Img

Img

Img

Step 2:Description of the Building Block

Img

This block is used to measure distance to the specified pin, and the distance unit can be cm or inch.

Step 3:Write the Program

① Set the baud rate to 15200.

Img

② Set the Trig pin of the ultrasonic sensor IO18 to “output” mode, and the Echo pin IO19 to “input” mode.

Img

③ Set Trig to IO18 and Echo to IO19, and the serial port prints the distance value detected by the ultrasonic sensor at 0.1 second intervals.

Img

④ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200. Move your hand in front of the ultrasonic sensor. When you are close to it, the displayed distance value becomes smaller. When you move away from it, the value becomes larger.

Img

7. Automatic Feeding System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Programming Steps

① Set the baud rate to 15200, the Trig pin of the ultrasonic sensor IO18 to “output” mode, and the Echo pin IO19 to “input” mode.

Img

② Set the pin IO33 connected to the servo to “Output” mode, initialize the control channel of the servo to CH2 (LT1) and the initial angle to 190°, delay 0.5 seconds.

Img

③ Define a “Distance” global variable to store the distance value detected by the ultrasonic sensor.

Img

④ Set the Trig pin and Echo pin of the ultrasonic sensor, and print the read distance value of the ultrasonic sensor on the serial port.

Img

⑤ Determine the distance detected by the ultrasonic sensor. If 2cm < distance value < 7cm, the feed box will be opened; otherwise, it will be closed.

Img

⑥ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200. If an animal is detected within 2cm-9cm, the feed box will be opened to feed the animal.

Img

8. Common Problems

Q1: Why doesn’t the servo work?

A: It may be stuck. Before assembling the servo, use the code to adjust it to 80°.

Q2: Why is the detection distance inaccurate when using the ultrasonic sensor?

A: Measurement should be started from the transmitting head of the ultrasonic sensor. This module is not a high-precision ultrasonic distance detection module and may exist errors.

Img

Project 04: Anti-theft Alarm System

Img

1. Description

The anti-theft alarm system is composed of a PIR motion sensor, a buzzer, a LED and a kidsIOT mainboard. When programming via the KidsBlock, you are able to judge whether someone is moving by reading the digital signal detected by the PIR motion sensor. If someone is moving, the buzzer will sound an alarm and the LED will flash to alert the user that someone has entered the area. Thus, a low-cost anti-theft alarm system can be realized, which is suitable for homes or offices.

2. Components

Img

Img

Img

Img

kidsIOT Mainboard×1

PIR Motion Sensor×1

Passive Buzzer×1

Servo×1

Img

Img

Img

Wire×2

USB Cable×1

Anti-theft Alarm System LEGO Pieces×1

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2:Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Process 5:

Img

Process 6:Initialize the servo angle

Wiring of servo(it is the same as project 03)

Img

First write the following code in KidsBlock software and upload the code to the kidsIOT mainboard, then the servo will rotate 180° . (Note: If the servo can not rotate, you can press the RESET button on the kidsIOT board.)

Img

Process 7:(Place the three Lego boxes on the same side, then assemble the four gears.)

Img

Process 8:

Img

Process 9:

Img

Process 10:

Img

Complete 1:

Img

Process 11:Share the LEGO board with project 03

Img

Complete 2:

Img

4. Wiring Diagram

Module

kidsIOT Mainboard

PIR Motion Sensor

No.4 port(control pin is io27)

Passive Buzzer

No.6 port(control pin is io23)

Servo

G/V/io33 port(Brown→G,Red→V,Orange→io33)

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. Passive buzzer makes sound

Img

Method 1
(1). Knowledge

The passive buzzer is driven by square waves. Let’s simulate the square waves below. The high and low levels of the pin can simulate a square wave: keeping the high level for 1000us and the low level for 1000us can make the buzzer sound.

Img

Changing the time of high and low level can change the sound volume of the buzzer. You can try changing it to 1500us, 2000us, 3000us…

(2). Write the Program

① Initialize the buzzer’s pin IO23 and “Output” mode.

Img

② Set the buzzer pin IO23 to “High” and “Low”. Here we take the delay of 0.001 second (1000 microseconds) as an example to make the buzzer emit sound.

Img

The delay function is a microsecond delay, which means the time delay is 1000 microseconds.

Note: The conversion relationship between seconds, milliseconds and microseconds is: 1 second = 1000 milliseconds = 1000000 microseconds.



By f=1/T, changing high and low levels in 1000us, we can know that the frequency of such a square wave is 1000Hz (that is, the number of high and low level changes per second is 1000 times).

③ Complete Program

Img

(3). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, the passive buzzer will make sound.

Method 2
(1). Knowledge

Use the “passive buzzer” code block to drive. The “passive buzzer” code block can generate a fixed-frequency PWM signal to drive the passive buzzer to sound. The sounding time length (beat) and sounding frequency can be controlled via parameters.

Img

(2). Add “passive buzzer”

Tap the “Actuator” module in the “Extension” , then select “esp32 Passive buzzer” and click Imgto return to the programming interface.

Img

Img

Img

(3). Description of the Building Block

Img

Set the frequency and beat of the passive buzzer to the specified pin.

Img Set the passive buzzer to play specific music to the specified pin.

Img

Set the passive buzzer to make no sound to the specified pin.

(4). Write the Program

① Initialize the buzzer’s pin IO23 and “Output” mode.

Img

② Set the sound pin, frequency and beat can be selected by yourself.

Img

③ Produce different tones.

Img

④ Complete Program

Img

(5). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, the passive buzzer will make sounds with different tones.

6. Passive buzzer plays music

Img

(1). Write the Program

① The buzzer pin is IO23, and then select a piece of music (we take Birthday as an example here) .

Img

② Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, the passive buzzer will play a “Happy Birthday” music.

7. Read the value of PIR Motion Sensor

Img

Step 1:Write the Program

① Set the baud rate to 15200.

Img

② Set the pin IO27 connected to the PIR motion sensor to “input” mode.

Img

③ Define a “PIR_motion_sensor” global variable to store the value of the sensor.

Img

④ Store the read value of the sensor in the “PIR_motion_sensor” variable and print it on the serial port.

Img

⑤ Complete Program

Img

Step 2:Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200.

When the sensor detects movement of a person or animal, the serial monitor window prints 1, and the red LED on the sensor will be off; otherwise, the monitor prints 0, and the red LED on the sensor will be on.

Note: The sensor does not have penetrating capabilities. When detecting human movement, please do not block it.



Img

8. Anti-theft Alarm System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Write the Program

①Set the baud rate to 15200, the IO27 pin of PIR motion sensor to “input” mode.

Img

② Set the pin IO33 connected to the servo to “Output” mode, initialize the control channel of the servo to CH2 (LT1) and the initial angle to 90°, delay 0.5 seconds.

Img

② Define a “PIR_motion_sensor” global variable to store the value of the PIR motion sensor.

Img

③ Store the read value of the sensor in the “PIR_motion_sensor” variable.

Img

④ Judge whether the sensor detects that a person or animal is moving. When someone or an animal is moving, the buzzer sounds, the servo rotates to close the door, and the serial monitor prints “Someone”; otherwise, the buzzer does not sound, the servo rotates to open the door, and the monitor prints ” No one”.

Img

⑤ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200.

When the sensor detects that someone or an animal is moving, the buzzer sounds, the servo rotates to close the door, and the serial monitor prints “Someone”; otherwise, the buzzer does not sound, the servo rotates to open the door, and the monitor prints “No one”.

Img

Img

9. Common Problems

Q1: The tone of the passive buzzer is not accurate to the actual tone?

A: The tones simulated by ordinary passive buzzers cannot meet the requirements of professional tones. If you need accurate tones, you need to use a more professional passive buzzer.

Q2: Does the PIR motion sensor make false alarms?

A: ① Non-professional PIR motion sensor.

② The requirements for the sensor to avoid false alarms are as follows: Within the detection range, avoid objects that are caused by the wind, such as curtains, clothing, flowers, etc. Avoid interference from strong light within the detection range, such as sunlight, car lights, spotlights, lighting and other light sources.

Project 05:Rainwater Control System

Note: 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

This project explains how to use a steam sensor, a passive buzzer and a kidsIOT board to make a rain detection system. When the sensor detects rain, it sends a signal to the kidsIOT mainboard to trigger various actions.

For example, the buzzer can be used to sound an alarm to alert the user that it is raining. This system is able to monitor rainfall in gardening, agriculture, and detect leaks in roofs or buildings. The sensor can be easily connected to the kidsIOT motherboard to form a simple rain detection system.

2. Components

Img

Img

Img

kidsIOT Mainboard×1

Steam Sensor×1

Passive Buzzer×1

Img

Img

Img

Wire×2

USB Cable×1

Rainwater Control System LEGO Pieces×1

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2:Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Process 5:

Img

Process 6:

Img

Process 7:

Img

Process 8:

Img

Process 9:

Img

Complete:

Img

4. Wiring Diagram

Module

kidsIOT Mainboard

Steam Sensor

No.6 port(control pin is io36)

Passive Buzzer

No.8 port(control pin is io5)

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. Read the analog value of the steam sensor

Img

Step 1:Write the Program

① Set the baud rate to 15200.

Img

② Set the pin IO36 connected to the steam sensor to “input” mode.

Img

③ Define a “Steam_sensor” global variable to store the analog value of the steam sensor.

Img

④ Store the read analog value of the sensor in the “Steam_sensor” variable and print it on the serial port.

Img

⑤ Complete Program

Img

Step 2:Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200.

Then the serial monitor will print the value(range:0~4095) read by the steam sensor. Touch the detection area on the sensor with a moistened finger, the larger the area, the greater the value!

Img

6. Rainwater Control System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Add “passive buzzer”

Img

Step 3:Write the Program

①Set the baud rate to 15200, the IO36 pin of steam sensor to “input” mode.

Img

② Define a “Steam_sensor” global variable to store the analog value of the steam sensor.

Img

③ Receive analog value of the sensor and print it on the serial port.

Img

④ Determine the received analog value of the sensor. When 800≤analog value<2000, the buzzer will sound alarm 1.

Img

⑤ Determine the received analog value of the sensor. When 2000≤analog value<4000, the buzzer will sound alarm 2.

Img

⑥ Determine the received analog value of the sensor. When analog value≥4000, the buzzer will sound alarm 3.

Img

⑦ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, when the rain value detected by the sensor is larger, the buzzer alarm sound will be louder.

Img

7. Common Problems

Q1: Is the steam sensor waterproof?

A: The detection area can be exposed to water, but when detecting water, please be careful not to use too much water.

Q2: After the sensor detects water, the alarm still sounds after a long time?

A: The passive buzzer keeps alarming because there are still water stains in the detection area of the sensor. Just clean it.

Project 06:Temperature and Humidity Control System

Img

1. Description

This project introduces how to use a kidsIOT mainboard, a temperature and humidity sensor, a fan and an OLED display to build an intelligent temperature and humidity control system.

The system can measure ambient temperature and humidity and control fans to cool down and dehumidify based on demand. When the temperature or humidity exceeds the set threshold, it will automatically turn on the fan to reduce the temperature or humidity in the environment below the set value to protect the animals and plants on the farm.

What’s more, it enables to adjust the ambient temperature and humidity and display them on the OLED display.

2. Components

Img

Img

Img

Img

Img

kidsIOT Mainboard×1

Motor×1

Temperature and Humidity Sensor×1

Wire×2

Battery Holder×1

Img

Img

Img

Img

Fan×1

USB Cable×1

Temperature and Humidity System LEGO Pieces×1

AA Battery(Not provide)×6

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2:Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Complete:

Img

4. Wiring Diagram

Module

kidsIOT Mainboard

Temperature and Humidity Sensor

No.6 port(control pin is io23)

Motor

No.9 port(IN+control pin is io18,IN-control pin is io19)

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. OLED Display

Img

(1). Programming Steps
Step 1:Description of the Building Block

Img

This block is used to initialize the OLED’s width, height and an I2C address.

Img

This is a command block for drawing a straight line from the initial position x0:0 y0:0 to the final position x1:32 y1:16. The number in the block can be changed.

Img

This is a command block that draws a recta with a width of 32 and a height of 16 from the initial position x:0 y:0, the numbers can be changed.

Img

This is a command block that draws a rectangle with a width of 32 and a height of 16 from the initial position x:0 y:0, the numbers can be changed.

Img

This is the command block that draws a circle with a radius of 8 starting from the initial position x:16 y:16.

Img

This is the command block that fills a circle with a radius of 8 starting at an initial position of x:16 y:16.

Img

This is the command block that draws a round rectangle with width 32, height 16, and radius 4 starting from an initial position of x:16 y:16.

Img

This is the command block that fills a round rectangle with width 32, height 16 and radius 4 starting from initial position x:16 y:16.

Img

This is the command block to draw a triangle from three positions x0:0 y0:0, x1:16 y1:0 and x2:8 y2:16.

Img

This is the command block that fills the triangle between the three positions x0:0 y0:0, x1:16 y1:0 and x2:8 y2:16.

Img

This is a command block for setting text size and color and background color.

Img

This is the command block that sets the cursor position.

Img

This is a command block for setting the way of printing strings on the OLED screen. “warp” means newline printing, “no-warp” means no newline printing.

Img

This is the command block to set the OLED display pattern.

Img

This is the command block to clear the OLED screen.

Img

This is the command block to refresh the OLED screen and display the next content.

Img

This is a command block that sets strings to start scrolling in a certain direction.

Img

This is the command block to set stop scrolling.

Step 2:Write the Program

① Initialize the OLED with width 128, height 64 and I2C address 0x78 (0x3c).

Img

② Set the text size displayed on the OLED to 6x8, the text color to white and the background color to black.

Img

③ OLED displays straight lines.

Img

④ The OLED displays the straight line and delays 1 second.

Img

⑤ The OLED displays rectangle and delays 1 second.

Img

⑥ The OLED displays fill rectangle and delays 1 second.

Img

⑦ The OLED displays circle and delays 1 second.

Img

⑧ The OLED displays fill circle and delays 1 second.

Img

⑨ The OLED displays round rectangle and delays 1 second.

Img

⑩ The OLED displays fill round rectangle and delays 1 second.

Img

⑪ The OLED displays triangle and delays 1 second.

Img

⑫ The OLED displays fill triangle and delays 1 second.

Img

⑬ The OLED displays smile face and delays 1 second.

Img

⑭The OLED displays angry face and delays 1 second.

Img

⑮ The OLED displays cry face and delays 1 second.

Img

⑯ The OLED displays “↑” and delays 1 second.

Img

⑰ The OLED displays “↓” and delays 1 second.

Img

⑱ The OLED displays “←” and delays 1 second.

Img

⑲ The OLED displays “→” and delays 1 second.

Img

⑳ The OLED displays “❤” and delays 1 second.

Img

㉑ Set the cursor position of the OLED to display the “Hello, KidsBlock” string at x:0 y:30 with a delay of 1 second.

Img

㉒ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the external power supply, the OLED display on the kidsIOT board displays various patterns and English letters.

6. Fan rotates

Img

(1). Programming Steps
Step 1:Add “DC Motor”

Tap Img, click the “Actuator” module in the “Extension” , then select “DC Motor for esp32” and click Imgto return to the programming interface.

Img

Img

Img

Step 2:Description of the Building Block

Img

Set the high and low level states of the motor INA pin and INB pin.

Img

Set the high and low level status of the motor INA pin and the analog output value of the INB pin in certain channels. If the INA pin is in a high-level state, the smaller the INB analog output value, the faster the fan rotates; and if the INA pin is in a low-level state, the larger the INB analog output value, the faster the fan rotates.

Step 3:Write the Program

① The pin INA of the motor module is IO18, the level is low, the INB pin is IO19, the channel is CH0 (LT0), and the analog output value is 0, then the motor does not rotate.

Img

② Set the motor pin INA to low level and the analog output value of the INB pin to different values, then the motor rotates clockwise at different speeds.

Img

③ Set the motor to stop rotating for 3 seconds.

Img

④ Set the motor pin INA to high level and the analog output value of the INB pin to different values, then the motor rotates anticlockwise at different speeds.

Img

⑤ Set the motor to stop rotating for 3 seconds.

Img

⑥ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT motherboard. After powering up via the external power supply, the motor rotates clockwise at different speeds and stops for 3 seconds, and then rotates counterclockwise at different speeds and stops for 3 seconds.

7. Read data from the temperature and humidity sensor

Img

(1). Programming Steps
Step 1:Add “temperature and humidity sensor”

Tap Img, click the “Sensor” module in the “Extension” , then select “DHT sensor for esp32” and click Imgto return to the programming interface.

Img

Img

Img

Step 2:Description of the Building Block

Img

Initialize the pin and mode of the temperature and humidity sensor (dht11, dht21 or dht22).

Img

Read the temperature and humidity from the temperature and humidity sensor.

Step 3:Write the Program

① Set the baud rate to 15200.

Img

② Initialize pin IO23 of the temperature and humidity sensor, and select the dht11 mode.

Img

③ The serial port prints the read temperature and humidity in the current environment every 1 second.

Img

④ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200. Then the serial port prints the temperature and humidity in the current environment.

Img

8. Temperature and Humidity Control System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Write the Program

①Initialize pin IO23 of the temperature and humidity sensor, and select the dht11 mode.

Img

② Initialize the width, height, I2C address, text size and color as well as background color of the OLED display.

Img

③ Set the strings “Temper:” and “Humid:” to be displayed on the OLED.

Img

④ Define variables “temperature” and “humidity”.

Img

⑤ Store the read temperature data into the “temperature” variable. The read humidity data is stored in the “humidity” variable.

Img

⑥ Display temperature data and humidity data at the corresponding position on the OLED.

Img

⑦ Determine the temperature and humidity value in the environment detected by the temperature and humidity sensor. When the temperature is greater than 29°C, or the humidity is greater than 80%RH, the fan will be turned on.

Img

⑧ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the external power, the OLED displays the temperature and humidity in the current environment.

When the temperature reaches 29°C or the humidity reaches 80%RH, the motor will turn on to dissipate heat or dehumidify (the fan simulates heat dissipation and dehumidification, and the heat dissipation and dehumidification effect is average); otherwise, the motor will turn off to achieve automatic farm temperature and humidity control effect.

Img

9. Common Problems

Q1: Is the temperature and humidity sensor waterproof?

A: The sensor detects the temperature and humidity in the air, which is not waterproof. Please do not put the module into water.

Q2: Does the rotation of the motor cause the kidsIOT mainboard to reset?

A: When the motor rotates, it requires a larger current than other sensors, which will cause voltage and current fluctuations in the circuit. Especially when the motor rotates forward and reverse, the voltage and current fluctuations are too large, causing the voltage and current of the kidsIOT mainboard to be too low, thus causing a reset.

Project 07:Soil Moisture Detection System

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

This project introduces how to use a kidsIOT mainboard, a soil moisture sensor, a passive buzzer and an OLED display to make an intelligent soil moisture detection system. The system can display the value of the soil moisture sensor in real time through the OLED display. When the soil moisture is lower than the set value, the buzzer will sound an alarm to remind you that it is time to water the land.

2. Components

Img

Img

Img

Img

Img

kidsIOT Mainboard×1

Soil Moisture Sensor×1

Passive Buzzer×1

GPIO Shield×1

Wire×2

Img

Img

Img

Img

F-F DuPont Wires

USB Cable×1

Soil Moisture/Water Level/Automatic Irrigation System LEGO Pieces×1

Sink×1

Img

3. Assembly Steps

Step 1:Components Needed

Img

Step 2:Process

Process 1:

Img

Process 2:

Img

Process 3:

Img

Process 4:

Img

Process 5:

Img

Img

Process 6:

Img

Process 7:

Img

Process 8:

Img

Process 9:

Img

Process 10:

Img

Img

Process 11:

Img

Process 12:

Img

Process 13:

Img

Process 14:

Img

Complete:

Img

4. Wiring Diagram

Module

GPIO Shield

kidsIOT Mainboard

Soil Moisture Sensor

G→G,V→V,S→S3

No.4 port(control pin of S3 is io27)

Passive Buzzer

No.8 port(control pin is io5)

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. Read the value of soil moisture sensor

Img

(1). Write the Program

① Set the baud rate to 15200.

Img

② Set the pin IO27 connected to the soil moisture sensor to “input” mode.

Img

③ Define a “Soil_humidity_sensor” global variable to store the analog value of the soil moisture sensor.

Img

④ Store the read analog value of the soil moisture sensor in the “Soil_humidity_sensor” variable and print it on the serial port.

Img

⑤ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT board. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200.

Insert the soil moisture sensor into the soil (or touch the sensor with wet hands), then the serial monitor will print the analog value of the soil moisture sensor (range: 0~4095). The greater the soil moisture (or the wetter the hand), the greater the value!

Img

6. Soil Moisture Detection System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Add “passive buzzer”

Img

Step 3:Write the Program

① Set the pin IO27 connected to the soil moisture sensor to “input” mode.

Img

② Initialize the width, height, I2C address, text size and color as well as background color of the OLED display.

Img

③ Define a “Soil_humidity_sensor” global variable to store the analog value of the soil moisture sensor.

Img

④ Store the read analog value of the soil moisture sensor in the “Soil_humidity_sensor” variable and display it on the OLED.

Img

⑤ Determine the analog value of the sensor. If it is less than 500, the buzzer will sound an alarm; otherwise, the buzzer will not sound.

Img

⑥ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, insert the soil moisture sensor into the soil (or touch the sensor with wet hands), when the sensor detects that the moisture of the soil (or the moisture of your hands) is less than the set threshold, the buzzer will sound an alarm.

Img

7. Common Problems

Q: Is the sensor waterproof?

A: The detection area of the soil moisture sensor is waterproof. Exceeding the detection area will cause a short circuit.

Project 08:Water Level Detection System

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

This project introduces how to use a kidsIOT mainboard, a water level sensor, a passive buzzer and an OLED display to make an intelligent automatic water level detection system. It is able to monitor water level changes, detect problems in time and take measures to avoid disasters, and is widely used in water conservancy projects, urban drainage as well as environment monitoring.

2. Components

Img

Img

Img

Img

Img

kidsIOT Mainboard×1

Water Level Sensor×1

Passive Buzzer×1

GPIO Shield×1

Wire×2

Img

Img

Img

Img

USB Cable×1

Soil Moisture/Water Level/Automatic Irrigation System LEGO Pieces×1

F-F DuPont Wires

Sink×1

Img

3. Assembly Steps

It shares the same structural shape with Project 07. If the assembly parts of Project 07 have finished, there is no need to assemble it again.

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)

Passive Buzzer

No.8 port(control pin is io5)

Connect the kidsIOT mainboard to your computer via USB cable.

Img

5. Read the value of water level sensor

Img

(1). Write the Program

① Set the baud rate to 15200.

Img

② Set the pin IO39 connected to the water level sensor to “input” mode.

Img

③ Define a “Water_level_sensor” global variable to store the analog value of the water level sensor.

Img

④ Store the read analog value of the water level sensor in the “Water_level_sensor” variable and print it on the serial port.

Img

⑤ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, click Img in the serial monitor and set the baud rate to 15200.

Insert the water level sensor in the water (or touch the sensor with wet hands), then the serial monitor will print the analog value of the sensor (range: 0~4095). The greater the water level, the greater the value!

Img

6. Water Level Detection System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Add “passive buzzer”

Img

Step 3:Write the Program

① Set the pin IO39 connected to the water level sensor to “input” mode.

Img

② Initialize the width, height, I2C address, text size and color as well as background color of the OLED display.

Img

③ Define a “Water_level_sensor” global variable to store the analog value of the water level sensor.

Img

④ Store the read analog value of the sensor in the“Water_level_sensor” variable and display it on the OLED.

Img

⑤ Determine the analog value of the sensor. If it is greater than 2000, the buzzer will sound an alarm; otherwise, the buzzer will not sound.

Img

⑥ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, insert the water level sensor in the water (or touch the sensor with wet hands), when the sensor detects that the water level (or the moisture of your hands) is greater than the set threshold, the buzzer will sound an alarm.

Img

7. Common Problems

Q: Is the sensor waterproof?

A: The detection area of the sensor is waterproof. Exceeding the detection area will cause a short circuit.

Project 09:Automatic Irrigation System

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

This project introduces how to use a kidsIOT mainboard, a soil moisture sensor, a water level sensor, a passive buzzer, an OLED display, a relay and a water pump to build an automatic irrigation system.

We will read the analog values of the soil moisture sensor and water level sensor by writing code to control the relay and the water pump.

When the soil is too dry, the relay will be turned on to control the water pump to irrigate the plants, when too low, the water pump will not be started and the buzzer will alarm.

At the same time, the OLED display will display the dryness of the soil and the water level, thus realizing automated plant watering and water level control, improving production efficiency while reducing the time and energy costs of manual operations.

2. Components

Img

Img

Img

Img

kidsIOT Mainboard×1

Water Level Sensor×1

Soil Moisture Sensor×1

Passive Buzzer×1

Img

Img

Img

Img

GPIO Shield×1

Relay Module×1

Water Pump×1

Wire×3

Img

Img

Img

Img

Battery Holder×1

Slotted Screwdriver×1

M-F DuPont Wires

F-F DuPont Wires

Img

Img

Img

Img

Water Pipe×1

Soil Moisture/Water Level/Automatic Irrigation System LEGO Pieces×1

AA Battery(Not provide)×6

Sink×2

Img

3. Assembly Steps

It shares the same structural shape with Project 07. If the assembly parts of Project 07 have finished, there is no need to assemble it again.

4. Wiring Diagram

Module

GPIO Shield

kidsIOT Mainboard

Soil Moisture Sensor

G→G,V→V,S→S3

No.4 port(control pin of S3 is io27)

Water Level Sensor

G→G,V→V,S→S4

No.4 port(control pin of S4 is io39)

Passive Buzzer

No.8 port(control pin is io5)

Relay Module

No.2 port(control pin is io2)


**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. Pumping System

Img

(1). Write the Program

① Set the pin IO2 connected to the relay module to “input” mode.

Img

② Set the relay module to close for 0.5 seconds and then disconnect, controlling the water pump to pump water for 0.5 seconds.

Img

③ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, the relay module will control the water pump to pump water.

6. Automatic Irrigation System

Img

(1). Programming Steps
Step 1:Flow Chart

Img

Step 2:Add “passive buzzer”

Img

Step 3:Write the Program

① Initialize pin IO27 of the soil moisture sensor and pin IO39 of the water level sensor to “input” mode.

Img

② Initialize pin IO2 of the relay module and pin IO5 of the passive buzzer to “Output” mode.

Img

③ Initialize the width, height, I2C address, text size and color as well as background color of the OLED display.

Img

④ Define a “Soil_humidity_sensor” global variable to store the analog value of the soil moisture sensor and a “Water_level_sensor” global variable to store the analog value of the water level sensor.

Img

⑤ Assign sensor data to variables.

Img

⑥Display the sensor data at the corresponding position on the OLED display.

Img

⑦ Judgment: When the water level is less than 1000, or the soil moisture is less than 500, the buzzer will sound an alarm.

Img

⑧ When the soil moisture is less than 500 and the water level in the sink is greater than 1000, the relay will drive the water pump for automatic irrigation.

Img

⑨ Complete Program

Img

(2). Test Result

ClickImg to upload the above complete code to the kidsIOT mainboard. After powering up via the USB cable, the OLED displays current soil moisture and sink water level information.

When the soil moisture is lower than the set threshold, then the soil is too dry, the buzzer will sound an alarm. At this time, the pumping system will automatically irrigate the soil. When the water level in the sink is lower than the set threshold, the pumping system will not work and the buzzer will sound an alarm to indicate that there is insufficient water in the sink.

Img

7. Common Problems

Q1: Is the sensor waterproof?

A: The relay is not waterproof.

Q2: Does the rotation of the water pump cause the kidsIOT board to reset?

A: When the water pump rotates, it requires a larger current than other sensors, which will cause voltage and current fluctuations in the circuit. Excessive voltage and current fluctuations will cause the voltage and current of the kidsIOT mainboard to be too low, causing the kidsIOT mainboard to reset.

Project 10 :WiFi Web Page Controls Smart Farm System

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.