X
Home > Blog > STEM for Arduino > HOW to Build A Light Controlled System with KidsIOT
HOW to Build A Light Controlled System with KidsIOT
By r August 27th, 2024 42 views
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.
HOW to Design a Lighting System with KidsIOT
Previous
HOW to Design a Lighting System with KidsIOT
Read More
HOW to Make A Fan with Temperature Detection Function by Kidsuno
Next
HOW to Make A Fan with Temperature Detection Function by Kidsuno
Read More
Message Us