Binsite for kidsuno

1. Code

DOWNLOAD

Download and unzip these files. Here all codes are in folder 1.Code_kidsuno.

For convenience, we move the codes into: D:\Code\1.Code_kidsuno. You can also choose to move it into any disks at will.


2. Development Environment Configuration

2.1 KidsBlock Download

2101

  1. KidsBlock Download

  2. Installation

  3. Driver Installation


2.2 KidsBlock Tutorial

  1. Make sure the board is connected to computer. Open KidsBlock and choose a device.

2201

Choose kidsuno

2202

Click Connect

2203

Go to Editor

2204

Click 2216: shift realtime mode into upload mode.

2215

2217

line1

  1. Build code blocks and upload.

Method ①: Directly drag blocks to the editing area.

2207

After building your blocks, save it to your computer: File –> Save to your computer

2208

Click 2210 to upload the code.

line4

Method ②: Load code from your computer.

Download code in 1. Code to your computer. For convenience, here we save it to D:\Code\1.Code_kidsuno.

File –> Load from your computer and choose code to open.

2209

After loading code, connect to the corresponding port.

2211

2203

After that, click 2210 to upload code.

line1

Main Interface

2205

2206


3. Modules

Please move the codes to a convenient path as your needs, for instance, path: D:\Code\1.Code_kidsuno.

Kidsuno Ports View

During experiments, modules can only be connected to ports in the same color.

KD2075

3.1 White LED Module

1top

KD2078

LED (Light-Emitting Diode)

LED is a commonly used light emitting device that converts electrical energy into light energy. Usually, it is used as an indicator in circuits and instruments, or as part of texts or numeric display.

It generally includes gallium(Ga), arsenic(As), phosphorus(P), nitrogen(N) and so on.

LED components

Emitting light colors

gallium arsenide diode

red

gallium phosphide diode

green

silicon carbide diode

yellow

gallium nitride diode

blue

1bottom

Parameters

2topOperating voltage: DC 3.3 ~ 5 V

Operating current: 1.5 mA (Peak: 2.3mA)

Maximum power: 0.07 W

Control signal: digital signal

Dimensions: 24 x 48 x 18 mm (without housing)

Positioning holes: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

Modules with blue housing are digital ones, so we should connect to digital io pins of the mainboard (ports with blue).

3112

In this experiment, we connect the white LED module to port 1. According to the board ports view, the digital io pin at port 1 is digital pin D5.

When we set the pin to high(1), the LED lights up in white; if we set to low(0), it will be off.

3bottom

Wiring Diagram

3101

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 3.1Light_on.sb3.

3102

Click 3209 to connect to COM port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

setout

Control

forever

Control

wait

line5

Conceive

  1. Initialization

    Set pin mode.

3103


Build blocks:

① Drag begin and setmode to the editing area.

② Click the triangle to choose pin 5.

3105

③ Modify the mode into output .

Three pin mode:

  • input

  • output

  • input-pullup

6top

Q :Why output?

A :The code is written for the mainboard. For the board, pin D5 is outputting power levels (high or low) to the connected module.

6bottom

line3

  1. Main Code

    Loop: LED lights on for 1s and goes off for 1s, in a loop.

    3104


    Build blocks:

    ① Drag forever.This is a loop code, in which codes will run forever.

    ② Drag setout into “forever”.

    There are two power level to output:

    • high

    • low

    Choose pin to 5 and output high.

    ③ Drag wait into “forever”. This is a delay code.

    6top

    Q :Why delay 1s?

    A :If you output a high level to LED, it will be always on. Yet, we add a delay of 1s, so it lights up for only 1s. Delay time is the ON/OFF time of LED.

    6bottom

    Pin outputs high for 1s:

    3106

    ④ Right-click the code and choose “Duplicate”.

    3107

    As follows:

    3108

    Set the output to low. Pin 5 outputs low for 1s.

    3109

    LED will lights on for 1s and goes off for 1s, in a loop.

5bottom

Test Result

4top

After uploading code, the LED module will flash with an interval of 1s (on for 1s and off for 1s).

3110

4bottom


3.2 3V Relay Module

1top

KD2089

Relay module is seen as an automatic switch which controls large current via small one. In circuits, it plays the role of automatic regulator, safety protector and converter.

1bottom

Parameters

2top

Driving voltage: DC 3.3 ~ 5V

Driving current: 75 mA(5V) ~ 125 mA(3.3V)

Contact capacity: 250 VAC/3A, 30 VDC/3A

Rated power dissipation: 0.15 W

Input signal: digital signal

Shock current: less than 3 A

Operating temperature: -10°C ~ +50°C

Control signal: digital signal

Dimensions: 24 x 48 x 18 mm (without housing)

Positioning hole: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

Internal structure:

3203

The coil inside the relay is wound around the iron core to form an electromagnet, which generates electromagnetic force after powering on.

A relay usually contains a moving contact and two static contacts.

3201

When there is no current in the coil, the electromagnet is not magnetic and is not attractive to the armature, so the moving contact B is in contact with the static contact A. Therefore, A now becomes the normally closed contact (NC). And the moving contact B is also called the common contact (COM).

NC (normally-close): The coil is closed without power.

3202

When a current flows through the coil, the electromagnet is magnetic so that it will attract the armature. At this time, B and the static contact C will be connected. Static contact C is called normally open contact (NO).

NO (normal open): The coil is opened without power.

3201

The 3V relay module is also a digital device so it need to be connected to digital io pins of the board.

In this experiment, we connect the module to port 2, which is pin D6. When we set the pin to high(1), the relay will work; if we set it to low(0), the relay will out of work.

3bottom

Wiring Diagram

3204

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 3.2Relay.sb3

3205

Click 3209 to connect to COM port and click 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

setout

Control

forever

Control

wait

line5

Conceive:

Code framework in this section is same as the last one.

  1. Initialization

    Set pin mode.

    3206

line3

  1. Main Code

    Loop: pin D6 outputs high for 1s to the relay module so then the module is conducted. Immediately, the pin outputs low for 1s to the relay and it turns off.

    3207

5bottom

Test Result

4top

After uploading code, the relay will work and stop working with an interval of 1s.

When the relay is conducted, B and C is connected and you will hear a tick-tack, and the red LED on the module will light up. When the relay is opened, A and B is connected with also a tick-tack, and the on-board LED goes off.

3208

4bottom


3.3 Button Module

1top

KD2082

Button module mainly integrates a touch switch and a yellow button cap. In the previous sections, we have learned how to output power levels. Herein, we will introduce you how to read power levels by programming.

1bottom

Parameters

2top

Operating voltage+: DC 3.3 ~ 5V

Operating current: 1.1 mA

Maximum power: 0.0055 W

Operating temperature: -10°C ~ +50°C

Control signal: digital signal

Dimensions: 24 x 48 x 18 mm (without housing)

Positioning hole: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

Button is a digital module so it should be connected to digital io pins on the board.

We connect the module to port 3 which is digital pin D3. When the button is pressed, the io pin outputs low; when the button is released, the pin outputs high.

3bottom

Wiring Diagram

3301

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 3.3Button.sb3

3302

Click 3209 and connect to port, and click 2210 to upload code.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

readdigital

Serial

serialbegin

Serial

serialprint

Operators

=

Control

forever

Control

ifelse

Control

wait

line5

Conceive

  1. Initialization

    Set pin mode and initialize the serial port.

    3303


    Build blocks:

    ① Drag begin and setmode to editing area and set pin to 3 and mode to input.

    ② Drag serialbegin to editing area. Place it under the last code block and set the baud rate to 9600.

line3

  1. Main Code

    Loop: If the digital level output by the module is low(0), the serial monitor will display The button is pressed ! If it is high(1), the monitor will show The button is not pressed !

    The result will be refreshed every 0.1s.

    3310


    Build blocks:

    ① Add a forever.

    ② Put ifelse in “forever”. This block determines whether the condition after “if” is true. If yes, run “then”; If not, run “else”.

    ③ Put = in the condition. If the values equal each other, the condition is TRUE.

    3304

    ④ Place readdigital into the left of = and set pin to 3, modify the number in the right of = into 0.

    So the condition is as follows:

    3305

    ⑤ Put serialprint into “if” and print The button is pressed !

    Put serialprint into “else” and print The button is not pressed !

    3306

    The program will determine whether the value read by pin D3 is 0.

    • If yes, print The button is pressed !

    • If no, print The button is not pressed !

    ⑥ Drag wait into “forever” and set delay to 0.1s. It controls the printing duration. Serial prints fast, so we add delay to better observe the results.

5bottom

Test Result

4top

Before uploading code, set baud rate first to avoid garbled words.

Click 3309 and set Buadrate to 9600.

3308

Upload code and press the button, and the serial monitor will show The button is pressed!. When you release the button, it prints The button is not pressed !

3307

4bottom


3.4 Active Buzzer

1top

KD2081

Buzzer is an electronic sound device with integrated structure. It is powered by DC voltage and is widely used in computer, printer, copier, alarm, electronic toys, automotive electronic equipment, telephone and timer.

According to the drive mode, it can be divided into active buzzer (internal drive circuits) and passive buzzer (external driver). The difference of the two types is the presence or absence of excitation source.

Active buzzer includes an internal vibration source, so can be triggered to make sound with a fixed frequency. It can be controlled through simple program but with high sound pressure.

However, passive buzzer excludes a vibration source. If the direct current signal is transmitted to a passive buzzer, it will not work. Generally, we drive through square waves with different frequency to achieve different sound effects.

To sum up, The active buzzer contains a vibration source, and its sound frequency is fixed. Yet there is no vibration source inside the passive one, so it must be driven by square waves whose frequency can be changed to control sounds.

1bottom

Parameters

2top

Operating voltage: DC 3.3 ~ 5V

Operating current: 22.5 mA

Maximum power: 0.12 W

Frequency: 2300 Hz

Operating temperature: -10°C ~ +50°C

Input signal: digital signal

Dimensions: 24 x 48 x 18 mm (without housing)

Positioning hole: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

Active buzzer is a digital module so it should be connected to digital io pins on the board.

We connect the module to port 4 which is digital pin D2. When the io pin outputs high(1), the buzzer emits sound; when the pin outputs low(0), the buzzer stops alarming.

3bottom

Wiring Diagram

3401

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno and open 3.4Active_buzzer.sb3

3402

Click 3209 to connect to port and then 2210.

Explanation

5top

Code block

Blocks

Code block

Events

begin

P

setmode

P

setout

Control

forever

Control

wait

line5

Conceive:

Structure of codes in this section is same as 3.1.

  1. Initialization

    set pin mode.

    3403

line3

  1. Main Code

    Loop: the pin outputs high for 1 to make the buzzer emit sound, and then it output low for 1s to stop the buzzer to alarming.

    3404

5bottom

Test Result

4top

After uploading code, the buzzer will alarm and stop alarming with an interval of 1s.

4bottom


3.5 Obstacle Avoidance Sensor

1top

KD2091

There are many types of infrared obstacle avoidance sensors, but most of them are the same in principle. They consist of a pair of infrared light emitting tube, infrared light receiving tube and sensor circuits. The transmitting tube emits infrared light, and the receiving tube receives infrared light. When the returned infrared light is not received, the signal pin outputs high; when it is received, the pin outputs low.

1bottom

Parameters

2top

Operating voltage: DC 5V

Operating current: 6.8 mA

Maximum Power: 0.034 W

Maximum detection distance: 173 mm

Operating temperature: -10°C ~ +50°C

Output signal: digital signal

Detection range: 2 ~ 40 cm

Dimensions: 24 x 48 x 18 mm (without housing)

Positioning hole: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

Infrared transmitter TX emits infrared signals with a certain frequency, and the infrared signal will gradually decay with the increase of transmission distance. If they encountered obstacles, they will reflect.

When the signal reflected back by the receiving tube RX is weak, the pin outputs a high level, indicating that the obstacle is far away.

When the reflected signal is relatively strong, the pin outputs low, indicating that the obstacle is relatively close, and the indicator is on.

We can adjust the effective distance via two potentiometers: one adjusts the transmitting power, the other adjusts the receiving frequency.

3501

The obstacle avoidance sensor is a digital module so it should be connected to digital io pins on the board.

We connect the module to port 6 which is digital pin D4. When the sensor detects obstacles, the io pin outputs low. When it detects nothing or the obstacle is far away from the sensor, the pin outputs high.

3bottom

Wiring Diagram

3502

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

In D:\Code\1.Code_kidsuno, open file 3.5Obstacle_avoidance.sb3

3503

Click 3209 to connect to port and then 2210 the code.

After uploading code, we need to rotate the two potentiometers for calibration. Otherwise the sensor cannot detect correctly.

NOTE: When adjusting the sensor, ensure there is no obstacles block it. Otherwise, the detection distance will be inaccurate.

3501

Firstly, adjust the transmitting power, turn the potentiometer clockwise to the end. And then turn it back slowly counterclockwise.

When the SLED light is on, rotate the potentiometer clockwise till the SLED is just OFF.

3509

Then, adjust the receiving frequency, turn the potentiometer clockwise to the end. And then turn it back slowly counterclockwise.

When the SLED light is on, rotate the potentiometer clockwise till the SLED is just OFF. At this time, the detection distance is the farthest.

3510

After adjustment, now it’s ready to use!

3511

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

readdigital

Serial

serialbegin

Serial

serialprint

Operators

=

Control

forever

Control

ifelse

Control

wait

line5

Conceive

Structure of codes in this section is same as 3.3.

  1. Initialization

    Set pin mode and baud rate.

    3504

line3

  1. Main Code

    Loop: print the digital power level read by pin D4. If the it outputs 0, the serial monitor will print the value and two space + Obstruction ahead! ; If it is 1, the monitor shows the value and two space + All going well!. The output results will be refreshed every 0.1s.

    3505

    6top

    Q :Why two space?

    If there is no space, the status result will be close to “Obstruction ahead!”, as follows:

    3506

    With space:

    3507

    A :To separately print power level value and statement.

    6bottom

5bottom

Test Result

4top

Before uploading code, set baud rate first to avoid garbled words.

Click 3309 to set Buadrate to 9600.

3308

After uploading code, when the sensor detects obstacles, the sensor outputs low and the status value is 0, the SLED lights up, and Shell prints Obstruction ahead!

When the sensor detects nothing, the sensor outputs high and the value is 1, the SLED goes off, and Shell displays All going well!

3508

4bottom


3.6 Photoresistor

1top

The sensors we have learned before are all digital modules. For instance, button module: when the button is released, we read a high level (5V), and when the it is pressed, we read low (0V).

However, the voltage between 0 ~ 5V cannot be read by the digital IO port. So we adopt analog modules that can read the intermediate voltage value through the ADC analog port on the board.

KD2104

A photoresistor is an analog sensor, which is mainly composed of a photoresistor element. The resistance changes with the light intensity, so we can take advantage of the sensor to design circuit that converts resistance change to voltage change.

For applications, the photoresistor is able to simulate people’s judgment of the intensity of the ambient light.

1bottom

Parameters

2top

Operating voltage: DC 3.3 ~ 5V

Current: 0.2 mA

Maximum power: 0.001 W

Operating temperature: -10°C ~ +50°C

Output signal: analog signal

Dimensions: 24 x 48 x 18 mm (without housing)

Positioning hole: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

The photoresistor is based on the internal photoelectric effect. The stronger the light is, the lower the resistance will be.

3601

The light intensity changes, and the resistance also changes, and the voltage detected by the analog port also changes (among 0 ~ 5V). This voltage change is a continuously analog value(any value within 0 ~ 5V).

The board can not directly process analog signals which needs to be converted into digital signals, so the analog value should take an ADC(Analog to Digital Converter) acquisition.

peg

line3

What is ADC?

ADC(Analog to Digital Converter) converts analog values to digital ones. The board has integrated ADC acquisition, which can be used directly.

ADC Technical Parameters

  1. Reference voltage: 5V

  2. Resolution: 10 bit

    An n-bit ADC means that the ADC has 2ⁿ scales. A 10-bit ADC contains a total of \(2^{10}=1024\) scales, which outputs a total of 1024 digits (0~1023) with each scale of \(\frac{5}{1023}≈0.00489(V)\).

  3. General ADC input voltage calculation:

    \( Vin=\frac {AVDD_{ADC}}{2^{Resolution Bits}-1}*ReadData\)

    \(AVDD_{ADC}\): Reference voltage

line3

This is an analog module, which need to be connected to the analog io pins (analog port is in red on the board).

3613

We connect the module to port 7 which is A0. When light shines on the photoresistor, it outputs the converted digital signal value.

3bottom

Wiring Diagram

3602

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

In D:\Code\1.Code_kidsuno, open 3.6Photoresistor.sb3

3603

Click 3209 to connect to port, and then 2210 the code.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

readanalog

Vari

variablename

Vari

setvariable

Vari

variable

Serial

serialbegin

Serial

serialprint

Operators

divide

Operators

multiply

Control

forever

Control

wait

line5

Conceive:

  1. Initialization

    Set pin mode and baud rate.

    3604

    Build blocks:

    ① Drag begin, setmode and serialbegin to the editing area, set pin A0 to input and baud rate to 9600.

    ② Add a variable variablename. Modify variable type to float and name it to value, assign an initial value of 0. It is used to store the analog value of the photoresistor.

line3

  1. Main Code

    Loop: print the analog value and voltage value converted from the pin analog value. The results will be refreshed every 0.1s.

    3605


    Build code:

    forever. Add setvariable in it and input variable name value, which is used to perform an assignment. Put a readanalog to set pin to A0.

    As follows: read the analog value of pin A0 and assign it to variable value.

    3606

    ② Put serialprint into “forever” and print ADC Value:, and modify to no-warp output.

    ③ Drag serialprint into “forever” and modify to no-warp output. Put variable into the print content and modify the variable to value.

    3607

    The serial monitor will print the analog value read by pin A0.

    ④ Drag serialprint into “forever” and print two space + Voltage:, and modify to no-warp output.

    ⑤ Find multiply and divide.

    multiply: The two values will be multiplied.

    divide: In this operation block, the left value is Numerator and the right one is Denominator.

    In working principle, we have learned how to calculate voltage. So:

    actual voltage = read analog value * referance voltage 5V / 1023

    3608

    ⑥ Find serialprint and put it in “forever”. Put the actual voltage in the printing box. Serial monitor prints the voltage value converted from the analog value of pin A0.

    3609

    ⑦ Put wait into “forever” and set delay to 0.1s. It controls the printing duration. Serial prints fast, so we add delay to better observe the results.

    3610

5bottom

Test Result

4top

Before uploading code, set baud rate first to avoid garbled words.

Click3309 to set Buadrate to 9600.

3308

After uploading code, Shell prints the ADC value received by the photoresistor and the converted voltage. The stronger the light is, the larger the ADC and voltage value will be.

3612

4bottom


3.7 Potentiometer

1top

KD2096

Potentiometer is an analog module which mainly consists of rotary resistor, knob and connector. When we rotate the knob, the connector will be linked to different built-in resistors, so that the output resistance/voltage changes.

In circuits, potentiometers are widely used for device adjustment, volume control and frequency control.

1bottom

Parameters

2top

Operating voltage: DC 3.3 ~ 5V

Operating current: 0.55 mA

Operating power: 0.00275 W

Operating temperature: -10°C ~ +50°C

Output signal: analog signal

Dimensions: 24 x 48 x 28.6 mm (without housing)

Positioning hole: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

The potentiometer is an analog module so it should be connected to analog io pins on the board.

We rotate the knob to change resistance, so that the current/voltage changes.

peg

line3

Resistor

Resistor is a current-limiting element. Generally, we connect its two pins into the circuit to limit the amount of current passing through it.

Resistance of fixed resistors are constant, while that of variable ones can be changed according to conditions.

Here are some types of resistors.

3701

Potentiometer

Potentiometer is a resistance element with three leading terminals, whose resistance can be adjusted according to a certain law. It is usually composed of a resistor and a movable brush, so it belongs to variable resistor.

The principle of the potentiometer: Constant voltage is applied to its terminals (terminal ① and terminal ③), and we rotate the reed to change the output of the resistance.

3702

line3

We connect the module to port 8 which is A7. When we rotate the knob, the digital value converted from resistance will be output.

3bottom

Wiring Diagram

3703

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 3.7Rotary_potentiometer.sb3

3704

Click 3209 to connect to the port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

readanalog

Vari

variablename

Vari

setvariable

Vari

variable

Serial

serialbegin

Serial

serialprint

Operators

divide

Operators

multiply

Control

forever

Control

wait

line5

Build blocks:

Codes in this section is similar to the last experiment.

  1. Initialization

    Set pin mode and baud rate.

    3705

line3

  1. Main Code

    Loop: print the analog value read by pin A7 and the converted voltage value. The results will be refreshed every 0.1s.

    3706

5bottom

Test Result

4top

Before uploading code, set baud rate first to avoid garbled words.

Click 3309 and set Buadrate to 9600.

3308

After uploading code, rotate the potentiometer, and the serial monitor prints the current ADC value and the converted voltage value.

3707

4bottom


3.8 Joystick

1top

KD2093

This module adopts PS2 joystick potentiometer, which includes (X, Y) axis analog output, (Z) axis button digital output. These X, Y, Z values may achieve specific functions.

1bottom

Parameters

2top

Operating voltage: DC 3.3 ~ 5V

Current: 12 mA

Maximum power: 0.06 W

Operating temperature:-10°C ~ +50°C

Dimensions: 24 x 48 x 33.4 mm (without housing)

Positioning hole: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

3801

peg

line3

I2C Interface

I2C/IIC/I2C bus (Inter-Integrated Circuit) is a two-wire serial bus developed by PHILIPS for MCU, which is suitable for the interface connection between MCU and peripheral devices.

IIC communicates over two lines: Clock channel (SCL) and Data Channel (SDA).

Both terminals must be connected to kidsIOT’s specific pins: SCL is connected to pin A5; SDA is connected to pin A4.

line3

IIC module(in green housing) needs to connect it to IIC ports. All digital IIC ports are with green sticker on the board.

3811

We need to import ROCKER library first, so then the values of the X, Y, and Z axes can be read.

3bottom

Wiring Diagram

3802

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

In D:\Code\1.Code_kidsuno, open 3.8Rocker.sb3

Click 3209 to connect to port and then click 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

Serial

serialbegin

Serial

serialprint

JS

readjs

Control

forever

Control

wait

line5

Build blocks:

Codes in this section is same as the last experiment.

  1. Initialization

    Set pin mode and baud rate.

    3804

line3

  1. Main Code

    Loop: print values in x, y, z axes every 0.1s.

    3805


    Build blocks:

    ① Enter add and choose Sensor, add joystick module.

    3807

    After being loaded, click Back.

    3808

    And you will see the joystick module.

    3810

    forever

    ③ Add six serialprint blocks and three readjs blocks into “forever”, as follows:

    3809

    There are two spaces before “Y:” and “B:” to separate values and statements to facilitate viewing of printed values.

    ④ Add a wait into “forever” and set delay to 0.1. It controls the printing duration. Serial prints fast, so we add delay to better observe the results.

5bottom

Test Result

4top

Before uploading code, set baud rate first to avoid garbled words.

Click 3309 to set Buadrate to 9600

3308

After uploading code, the serial monitor displays the values in X, Y, Z axis.

Value on X-axis increases from 0 to 1023 in the direction of the arrow. Value on Y-axis increases from 0 to 1023 in the direction of the arrow. Press the joystick and the value on z-axis is 1; release it and the value on z-axis is 0.

3806

4bottom


3.9 SC7A20 3-Axis Acceleration Sensor

1top

KD2116

This sensor is used to measure the acceleration of an object in three axes (X, Y and Z). It features small size and light weight, and can fully and accurately reflect the motion properties of the object. In application, it is widely used in aerospace, robotics, automotive and medical fields.

SC7A20 is a high-precision 12-bit digital three-axis acceleration sensor chip with multiple functions, low power consumption, small size and accurate measurement.

1bottom

Parameters

2top

Operating voltage: DC 3.3 ~ 5V

Operating current: 30 uA

Operating power: 0.000015 W

Operating temperature: -10°C ~ +50°C

Output signal: analog signal

Dimensions: 24 x 48 x 18 mm (without housing)

Positioning hole: diameter of 4.8 mm

Interface: telephone socket

2bottom

Principle

3top

The sensor measures spatial acceleration(the speed of the object in space). The three-axis acceleration is mainly to decompose in X, Y, and Z three axes.

3901

Acceleration sensor is mainly divided into piezoelectric, capacitive and thermal response.

According to the number of input axes, there are single axis, two axis and three axis accelerometers.

According to the different output signals, there are analog and digital(the analog output value is voltage, digital output value is digital signal). Analog sensors also need to add digital-to-analog converter (ADC), but the analog one has integrated ADC circuit, so can be directly transmit data through the communication interface(SPI, I2C, etc.).

The SC7A20 acceleration sensor is also an IIC module so needs to be connected to IIC port.

We need to import the SC7A20 library to read the acceleration values on the X, Y and Z axes.

3bottom

Wiring Diagram

3902

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsunoto open 3.9Triaxial_acceleration.sb3

3903

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

Serial

serialbegin

Serial

serialprint

SC7A20

readsc7a20

Control

forever

Control

wait

line5

Conceive:

Codes in this section is same as the last experiment.

  1. Initialization

    Set pin mode and baud rate.

    3804

line3

  1. Main Code

    Loop: print values in x, y, z axes every 0.1s.

    3904


    Build blocks:

    ① Click add to select Sensor and add the acceleration sensor.

    3905

    Click Back.

    3906

    And you will see the module is loaded:

    3907

    forever

    ③ Add six serialprint blocks and three readsc7a20blocks in “forever” as follows:

    3908

    Note there are two space before “Y:” and “B:” for better viewing.

    ④ Add a wait and set delay to 0.1s. It controls the printing duration. Serial prints fast, so we add delay to better observe the results.

5bottom

Test Result

4top

Before uploading code, set baud rate first to avoid garbled words.

Click3309 to set Buadrate to 9600.

3308

After uploading code, shake the SC7A20 acceleration sensor, and the Shell prints the acceleration sensor on X, Y, Z axis.

3909

4bottom


3.10 Servo

1top

67820072

Generally, servo exports three wires in three colors: brown, red and orange. Brown is the grounded, red is the positive, and orange is signal. The wire colors may vary from brands.

31001

1bottom

Parameters

2top

Operating voltage: DC 3.3 ~ 5V

Rated voltage: 4.8V

Rated current: 200 mA

Angular speed: 60°/0.12s

Operating temperature: -10°C ~ +50°C

Length: Five Lego hole units 8x5 = 40 mm

Width: Two Lego width units 8x2 = 16 mm

Height: Three Lego height units 3.2x3 = 9.6 mm

Base hole position: diameter of 4.8

Interface: 3pin interface with a spacing of 2.54 mm

2bottom

Principle

3top

Servo is generally controlled by PWM (pulse width modulation). Herein, this 270°(-45° ~ 225°) servo is compatible with LEGO.

31014

Rotation range of 270° servo: -45° ~ 225°, which is 270° in total, rather than rotating to 270°.

Before using it, we need to import its library first.

3bottom

Wiring Diagram

The connection terminal of 270° servo is a 3-pin headers with a 2.54mm pitch, which needs to be connected to the pin interfaces.

We connect servo to pin 13.

44_15

31004

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 3.10Servo.sb3

31005

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

servo270

setdegree

Control

forever

Control

wait

line5

Conceive

  1. Initialization

    Click add to add library Servo 270.

    310013

    Loop: servo rotates to -45°, 45°, 135°, 225° in order with a stop of 1s for each rotation.

    Rotation range of 270° servo: -45° ~ 225°, which is 270° in total, rather than rotating to 270°.

    31006


    Build blocks:

    forever

    ② Put setdegree into “forever” and set pin to 13, degree to -45.

    ③ Add wait and set the delay to 0.1s. It controls the stop duration. If the delay is not set, the servo will rotate to the set Angle without stopping, so we can not see the change in the rotation Angle.

    Duplicate the block:

    31007

    As follows:

    31008

    Duplicate 3 times in total. Set the degree value to 45, 135, 225 respectively.

    31009

5bottom

Test Result

4top

After uploading code, servo rotates to -45° and stop 1s; then it rotates to 45° and stop 1s; then it rotates to 135° and stop 1s; at last it rotates to 225° and stop 1s.

After these steps, it will back to -45°, in a circulation.

4bottom


4. Comprehension

4.1 Manual Lighting

In this experiment, we will apply both LED module and button module to form a lighting device.

Flow

4101

Assembly

line1

Required:

41_00

line1

Step 1

41_01

line1

Step 2

41_02

41_03

line1

Step 3

41_04

line1

Step 4

41_05

line1

Step 5

41_06

line1

Step 6

41_07

line1

Step 7

41_08

line1

Step 8

41_09

line1

Completed!

41_10

line1

Wiring Diagram

4102

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 4.1Manual_lighting.sb3

4103

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

setout

P

readdigital

Operators

=

Control

forever

Control

ifelse

line5

Conceive:

  1. Initialization

    Set the pins of white LED module and button module, initialize the serial monitor.

    4104

line3

  1. Main Code

    Loop: Determine whether the button is pressed. If it is, the button outputs 0. If not, the button outputs 1.

    • Press the button (pin reads value 0), and LED will light up (pin outputs high to LED module).

    • Release the button (pin reads value 1), and LED will go off (pin IO23 outputs low to LED module).

    4105

5bottom

Test Result

4top

After uploading code, press the button, and LED lights up. When you release the button, LED is off.

4106

4bottom


4.2 Automatic Lighting

Herein, we combine the photoresistor and LED module to design an automatic lighting system.

Flow

4201

Assembly

line1

Required:

42_00

line1

Step 1

42_01

line1

Step 2

42_02

line1

Step 3

42_03

line1

Step 4

42_04

line1

Step 5

42_05

line1

Step 6

42_06

line1

Step 7

42_07

line1

Step 8

42_08

line1

Step9

42_09

line1

Completed!

42_10

line1

Wiring Diagram

4202

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 4.2Automatic_lighting.sb3

4203

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

readanalog

P

setout

Serial

serialbegin

Serial

serialprint

Operators

![less than](media/less than.png)

Control

forever

Control

ifelse

Control

wait

line5

Conceive:

  1. Initialization

    Set the pins of white LED module and the photoresistor; Initialize the serial monitor.

    4204

line3

  1. Main Code

    Loop:

    ① Print the value read by the photoresistor.

    ② Determine whether the photoresistor value is less than 500 every 0.1s.

    • value < 500 (weak light): LED lights up.

    • value ≥ 500 (adequate light): LED goes off.

    4205

5bottom

Test Result

4top

Upload code and the photoresistor starts to detect the ambient light intensity.

In room, when the light is sufficient (the value is greater than 500), the LED is off.

When the ambient light is weak (the value is less than 500), the LED is on.

In the code, the threshold value 500 can be modified according to your needs.

4206

4bottom


4.3 Light Adjustment

In this experiment, we will introduce how to adjust the brightness of LED module via a potentiometer.

Flow

4301

Assembly

line1

Required:

43_00

line1

Step 1

43_01

line1

Step 2

43_02

line1

Step 3

43_03

line1

Step 4

43_04

line1

Step 5

43_05

line1

Step 6

43_06

line1

Step 7

43_07

line1

Completed!

43_08

line1

Wiring Diagram

4302

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 4.3Brightness_adjustment.sb3

4303

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

setpwm

P

readanalog

Control

forever

Data

map

line5

Conceive:

  1. Initialization

    Set the pin of the white LED and the potentiometer module, initialize the serial monitor.

    4304

line3

  1. Main Code

    Loop: Read the value output by the potentiometer, and set the value as the duty cycle of the LED module to control its brightness.

    4305


    Build blocks:

    forever

    ② Drag setpwm into “forever” and set pin to 5

    ③ Add a map(map block).

    peg

    line3

    6top

    Q :The brightness value of LED is 0 ~ 255, while the output analog value of potentiometer is 0 ~ 1023. So how to control the brightness via the potentiometer?

    A : We use map block to map the output range to the brightness range.


    Q :What is MAP?

    A :In mathematics, MAP is the term for a relationship between two sets of elements that “correspond” to each other.

    Set: a whole consisting of one or more defined elements.

    There is a correspondence between Set A and B. For every Element a in Set A, there is always a unique element b corresponding to it in Set B, which is called map A to B.

    The concept of mapping is not only used in mathematics, but in computer science. In a computer program, mapping is a way to map each element in one set to a unique element in another.

    We assume that the output analog values of the potentiometer is A, and the brightness range is B. We map values in A to B, so the output value will correspond to a unique brightness value. This kind of one-to-one mapping enables the potentiometer to directly adjust the brightness.

    6bottom

    line3

    Five values need to be set in this map block:

    ​ (1): the value to be mapped;

    ​ (2 & 3): the range of the value to be mapped;

    ​ (4 & 5): the range after mapping.

    Set the mapped value as the analog value read by A7: Drag readanalogto the first box and set pin to A7.

    4306

    Set the range of the value to be mapped: here is the output range of the potentiometer(0 ~ 1023), so we set the second and third value to 0 and 1023 respectively.

    4307

    Set the range after mapping: here is the brightness value range of LED(0 ~ 255), so we set the forth and fifth value to 0 and 255 respectively.

    4308

    ④ Put the map block into the PWM output as the duty cycle of the white LED module, so that we can control the brightness via the potentiometer.

    4309

5bottom

Test Result

4top

Upload code and rotate the potentiometer, and the LED brightness will change accordingly. The greater the ADC is, the brighter the LED will be.

4310

4bottom


4.4 Smart Trash Can (Manual Mode)

In this project, we use a joystick and a servo to control the trash can lid.

Flow

4401

Assembly

line1

Required:

44_00

line1

组装步骤1

44_01

line1

Step 2

44_02

line1

Step 3

44_03

line1

Step 4

44_04

① Hold the lid still to make it align with the hole.

② Insert the rod.

ATTENTION: Keep the lid flatwise.

44_14

line1

Step 5

44_05

line1

Step 6

44_06

line1

Step 7

44_07

line1

Step 8

44_08

line1

Step 9

44_09

line1

Step 10

44_10

The servo need to be calibrated before using. Connect the servo to pin 13 on the board and link the board to computer via USB cable.

44_15

Open KidsBlock and click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open Servo_Calibration.sb3

44_16

Click 3209 and connect to port, and then 2210 code.

After calibration, disconnect the board to computer and continue to mount.

ATTENTION: During mounting, please hold and keep the lid flatwise.

44_11

line1

Step 11

44_12

line1

Step 12

44_13

line1

Completed!

44_17

line1

Wiring Diagram

4402

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

In D:\Code\1.Code_kidsuno, choose to open 4.4Smart bin_Manual mode.sb3

4403

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

JS

readjs

servo270

setdegree

Serial

serialbegin

Serial

serialprint

Operators

![less than](media/less than.png)

Control

forever

Control

ifelse

Control

wait

line5

Conceive:

  1. Initialization

    Set the servo pin and baud rate.

    4404

line3

  1. Main Code

    Loop: read the value of joystick in y-axis and refresh it every 0.1 seconds, and print it on serial monitor.

    If the value in y-axis is less than 490, set the servo to 45°. If not, set the servo to 180° so then the lid will be closed.

    4405


    Conceive:

    ① Build blocks as follows: Read the value of joystick in y-axis and refresh it every 0.1 seconds.

    4406

    ② Put the following code blocks in “forever”.

    4407

    Determine whether the value in y-axis is less than 490.

    • If yes: set the servo to 45° to open the lid.

    • If not: set the servo to 180° to close the lid.

5bottom

Test Result

4top

Upload code and push the joystick as follows, and the lid will open. If you release the joystick, the lid will close. Now you can control the trash can manually!

4408

4bottom


4.5 Smart Trash Can (Automatic Mode)

We will construct an automatic trash can with obstacle avoidance sensor, active buzzer and servo.

Flow

4501

Assembly

line1

Required:

44_00

line1

Step 1 to 10 are the same as those in 4.4, so you can directly use the form in 4.4 here.

① Remove the joystick.

② mount from step 11.

Yet if you have not assemble the building blocks in 4.4, please start from step 1.

line1

Step 1

44_01

line1

Step 2

44_02

line1

Step 3

44_03

line1

Step 4

44_04

① Hold with your fingers.

② Insert the rod.

ATTENTION: keep the lid flatwise.

44_14

line1

Step 5

44_05

line1

Step 6

44_06

line1

Step 7

44_07

line1

Step 8

44_08

line1

Step 9

44_09

line1

Step 10

44_10

The servo need to be calibrated before using. Connect the servo to pin 13 on the board and link the board to computer via USB cable.

44_15

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open Servo_Calibration.sb3

44_16

Click 3209 to connect to port and then 2210.

After calibration, disconnect the board to computer and continue to mount.

ATTENTION: During mounting, please hold and keep the lid flatwise.

44_11

line1

Step 11

45_12

line1

Step 12

45_13

line1

Step 13

45_14

line1

Step 14

45_15

line1

Completed!

45_16

line1

Wiring Diagram

4502

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 4.5Smart bin_Automatic mode.sb3

4503

Click 3209 to connect to port and 2210 the code.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

readdigital

P

setout

servo270

setdegree

Operators

=

Control

forever

Control

ifelse

Control

wait

line5

Conceive:

  1. Initialization

    Set the pins of obstacle avoidance sensor, buzzer and servo.

    4504

line3

  1. Main Code

    Loop: Determine whether the read value equals 0.

    • If it is 0, i.e., the sensor detects obstacles, the buzzer will receive a high level so then emit sound. At this time, the servo rotates to 45° to open the lid.

    • If it is not 0, i.e., the sensor detects nothing, the buzzer will not alarm. At this time, the servo rotates to 180° to close the lid.

    4505

    6top

    Q :Function of the DELAY block?

    When the obstacle is leaving the sensing range, the lid will immediately close without delay. Thus, we add a delay time to maintain the state of the lid.

    A :Delay is used to maintain the state of the lid, which can be modified according to your needs.

    6bottom

5bottom

Test Result

4top

After uploading code, we first need to adjust the obstacle avoidance sensor (please see chapter 3.5 for details).

After adjusting, place something in the sensing range in front of the obstacle avoidance sensor.

When the obstacle avoidance sensor detects it, the buzzer makes a sound, and the servo rotates to open the lid; When the thing leaves the sensing range, the sensor detects nothing, and the buzzer stops alarming, and the servo rotates to close the lid.

4506

4bottom


4.6 Smart Trash Can (Drop Alarm)

In this experiment, we will add a drop alarm system to the trash can with an SC7A20TR three-axis acceleration sensor and an active buzzer.

Flow

4601

Assembly

line1

Required:

46_00

line1

The block appearance is similar to that in chapter 4.4 and 4.5. If you’ve already built one of them, you don’t have to dismantle it all and reassemble it, just follow these steps.

The blocks in 4.4:

① Remove the servo and the lid

② Assemble from step 4

The blocks in 4.5

① Remove the servo and the lid

② Assemble from step 5

Yet if you have not assemble the building blocks, please start from step 1.

line1

Step 1

46_01

line1

Step 2

46_02

line1

Step 3

46_03

line1

Step 4

46_04

line1

Step 5

46_05

line1

Step 6

46_06

line1

Step7

46_07

line1

Completed!

46_08

line1

Wiring Diagram

4602

Test Code

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open 4.6Smart bin_Drop alarm.sb3

4603

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

setout

Serial

serialbegin

Operators

=

SC7A20

tumble

Control

forever

Control

ifelse

Control

wait

line5

Build blocks:

  1. Initialization

    Set pin mode and initialize the serial port.

    4604

line3

  1. Main Code

    Loop: determine whether there is a fall, and print the result on serial monitor.

    4605

    tumble is a fall detection code block. When the SC7A20 acceleration sensor is detected in a non-horizontal position (fall), the output value is 1; When the sensor is detected in a horizontal position (none falling), the output value is 0.

5bottom

Test Result

4top

Place the bin flat-wise and upload the code.

When the bin is in a non-horizontal position (fall), the buzzer will alarm.

4606

When the bin is in a horizontal position, the buzzer stays quiet.

4607

4bottom