kidsIOT Mainboard×1 |
Photoresistor×1 |
White LED Module×1 |
Wire×2 |
USB Cable×1 |
Light Controlled System LEGO Pieces×1 |
Process 1:
Process 2:
Process 3:
Process 4:
Process 5:
Complete
(Note: Do not dismantle it, it will still be used in project 10.)
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.
It is used to read the analog signal value of the specified pin.
① Set the baud rate to 15200.
② Set the pin IO39 connected to the photoresistor ( control pin io39) to the “input” mode.
③ Define a “Photosensor” variable to store the value of the photoresistor.
④ Store the read value of the photoresistor in the “Photosensor” variable.
⑤ Complete Program
Click to upload the above complete code to the kidsIOT motherboard. After powering up via the USB cable, click 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.
① 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”.
② 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.
③ Complete Program
Click 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.
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.