Note:The sensors, modules and the 270° servo in each project are shared.

Project 01:Traffic Lights

Img

1. Introduction

I met a big traffic jam on my way to school today. The red light at the intersection where I waited lasted very long and the green light flashed a few times and then changed to yellow. It seems that there’s something wrong with the traffic light’s digital signal.

Can we use a traffic light module to simulate the working principle of traffic lights?

Let’s take a look at the tools first.

2. Components

Img

Img

Img

Kidsuno Mainboard×1

Traffic Light Module×1

Connection Wire×1

Img

Img

USB Cable×1

Traffic Lights×1

Img

3. Component Knowledge

(1)Traffic lights are signal lights that command the traffic operation, which are generally composed of a red light, a green light and a yellow light. The red light means impassable, the green light means passable, and the yellow light means a warning.

(2)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

4.Traffic Lights Assemble

Download the PDF follow the link:Traffic Lights Assembly

Or you can Watch the assemble video :

5. Function: Light Up the Traffic Lights

Img

6. Wiring Diagram

Connect the kidsuno mainboard and computer via a USB cable, and connect the traffic light module to the No.1 interface of the mainboard.

Img

7. Description of the Building Blocks

Img

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.

Img

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.

8. Write the Program

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

Img

② Drag the instruction blockImg in the Pins module to the script area and copy it twice. Since the interface of the traffic light module is connected to port 1 on the mainboard (the red light is connected to D3, the yellow light is connected to D5, and the green light is connected to D6), then change the number 0 to 3, 5 and 6 and input to output respectively.

Img

③ Drag the instruction blockImg in the Pins module to the script area and copy it twice. Then change the number 0 to 3, 5, and 6 respectively.

Img

④ Complete Program

Img

9. Test Result

Click Img to upload the complete program to the kidsuno mainboard and power up, then the lights on the traffic light module will be on. It seems pretty amazing, right?

Img

10. Function: Make the Traffic Lights On and Off

Img

11. Description of the the Building Blocks

Img

This is a delay block, and change the number 1 to the delayed time

12. Write the Program

① Write the program according to the knowledge learned before and refer to the last program code.

Img

② Drag the instruction blockImg in the Control module to the script area. The number 1 can be changed to other numbers. Here, the number 1 is taken as an example.

Img

③ Copy the code stringImg once and change high to low.

Img

④ Complete Program

Img

13:Test Result

Click Img to upload the complete program to the kidsuno mainboard and power up, then the lights on the traffic light module will go on and then off.

Img

Img

14. Function of Traffic Lights

Img

15. Flow Chart

First set the three LED lights to off, then the red light will be on for 5 s then go off, then the yellow light will flash for 3 times then go off, then the green light will be on for 5 s then go off.

Img

16. Description of the the Building Blocks

Img

This is a loop statement: do a same thing over and over again.

Img

This is a conditional loop control statement and it will exit the loop when the number of loops is met. For example, 10 means 10 cycles, and the number 10 can be changed to other numbers.

17. Write the Program

① Find the instruction blocks

(1)Img

(2)Img

(3)Img

② Complete Program

Img

18.Test Result

Click Img to upload the complete program to the kidsuno mainboard and power up, then the red light will be on for 5 s then go off, then the yellow light will flash for 3 times then go off, then the green light will be on for 5 s then go off and continue the cycle.

Img

19. Extended Project

Img

The extended sample code is below:

Img