color_sensor_preparation

Color sensor device

Build your own color detection device using the APDS-9960 sensor connected to the micro:bit! This module allows for color recognition, light intensity measurement, and gesture detection. Learn the basics of programming, electronics, and working with optical sensors in a fun way - ideal for teaching physics, computer science, or for home experiments with automation, object recognition, and interactive systems.

Description

The color sensor device is a project that serves as a practical demonstration of color and light recognition using a sensor. APDS-9960The module can detect basic colors, measure ambient light intensity, and recognize simple gestures. The micro:bit then responds to these stimuli – it can display a color on the display, trigger a sound signal, or activate a light response.

This device is ideal for school lessons and home experiments and does not require any advanced knowledge. It will allow children and adults to learn the principles of optics, sensors and microcontroller programming in a fun way.

Connection

The color sensor is connected using six wires. On the sensor we find the VCC (power), C, D, GND (ground), LED and INT pins. We connect the VCC pin to the white power rail on the board, which supplies 3,3V. We connect the C pin to the SCL pin, D to the SDA pin. LED to the white power rail and finally we ground it by connecting GND and INT to the black ground rail. For more information, see the assembly instructions.

Recommendation

When connecting, the expansion board must be turned off and the micro:bit disconnected from the power supply.

Program

Basic program

This program contains a library for working with the color sensor. It does not perform any function and is intended for creating your own program.

RGB color detection

This program detects whether the object in front of the sensor has one of these three colors: red (R), green (G), blue (B). It displays the detected color on the LED strip.

It starts by initializing the color sensor. It then assigns the function of controlling the LED strip to pin P1.

In the main loop, the program waits (executes an empty statement) until it receives a signal from the color sensor that the value has been read. It then stores the values of the red, green, and blue components, as well as the ambient light intensity, into variables. If the sensor measures a low light value, it does not turn on the LED strip. Otherwise, it determines which component has the highest measured value. It finally displays this on the LED strip.

If the LED strip lights up even without the measured object, increase the minimum ambient light value.

Reading RGB values using an OLED display

The program starts by setting up the color sensor together with the OLED display at startup. Then, the condition is repeated again and again, which says the following. If the color sensor is ready to measure, it sets up several variables. In the last step, the variables are displayed on the OLED display.

We will be shown information about the amount of red, green and blue. But the amount of surrounding area is also important information. And using the A and B buttons on the microbit we are able to turn on additional LEDs that will brighten the measured object.

Tasks

Task 1: Color Measurement

Connect an OLED display to the fixture and use the APDS-9960 sensor module to output the color values you measure in the surrounding environment. Try measuring different surfaces and observe the differences in the R, G, and B components.

Task 2: Custom Colors (Advanced)

Measure the values of selected colors, e.g. red, blue or green areas. Save the corresponding RGB values and create conditions for their recognition. When approaching a similar color, let the LED strip display the corresponding color. Set the tolerance in the program so that the measurement works reliably even in different lighting conditions.