case 07 Smart Car Light
6. case 07 Smart Car Light#
6.1. Our Goal#
Make smart car light with the light sensor and LED on robit.
6.2. Material Needed#
1 x Robit
1 x Mbot Car
6.3. Background Knowledge#
Light sensor generally refers to a device that senses the energy of light from ultraviolet light to infrared light and converts the light energy into an electrical signal. It is mainly composed of photosensitive elements, and is mainly divided into four types: ambient light sensor, infrared light sensor, solar light sensor and ultraviolet light sensor. It is mainly used in the fields of car body changing electronic applications and intelligent lighting systems.
The light sensor on Robit is an ambient light sensor，which indicates the strength of ambient light by numbers.
6.4. Hardware Connection#
The light sensor onboard is connected to P10 port on micro:bit.
Two rainbow LED onboard are connected to P12 port on micro:bit.
Click Advanced in the code drawer of Makecode to see more options.
To program for robit, we have to add a package. Find Add Package in the bottom of the code drawer and click on it. This will pop up a dialogue box. Search for “Robit” and then click it to download this package.
Note: If you get a hint that some packages will be deleted due to the problem of incompatibility, you can either follow the prompts, or create a new project in the project menue.
Create a forever loop. Read P10(i.e. pin of light sensor) in analog way. Assign the light strength value read to variable item.
If variable item(i.e. light strength) is under 700, then LED light is white and delay time for 300ms.
If item is beyond 700, then turn off LED light.
Note: The picture below gives a detailed code explain to LED.
You can see the whole program from the link here: https://makecode.microbit.org/_Dyu4j2A4F23c
Or you can download it from the page below.
When the ambient light is strong, turn off the LED light; while the ambient light is dim, then turn on the LED light.