Hi, my name is Ajinkya, and I’m excited to share my project, the Magic Sensor, for this show and tell. I’ve always been fascinated by how sensors can react to the world around us, so I decided to use the micro:bit’s built-in light sensor to create something colorful and interactive.
The Magic Sensor works by constantly checking the light level in the room. I set up three variables for the red, green, and blue pins of my RGB LED lamp, and another variable to store the current light reading. In my code, I used a while loop so the program would keep running and updating the LED color in real time.
Depending on the light level, the Magic Sensor changes the color of the LED. If the room is dim and the light level is below 50, nothing happens. If the light level is above 50, the LED glows red. As it gets brighter, the colors change: green for over 75, blue for over 120, yellow for over 140, purple for over 150, and cyan for over 200. If the light level is almost at the maximum, all the colors turn on, making a dazzling display!
I used if, elif, and else statements to decide which color to show, and digital write commands to control the LEDs. I also learned about using variables to store pin numbers and sensor values, and how to use sleep to give the program a short break between updates.
Building the Magic Sensor taught me a lot about coding, sensors, and how to make electronics react to the environment. I’m proud of how it turned out, and I’m excited to keep experimenting with more sensor-based projects in the future!