İçeriğe Geç

Projeler

#3 Color Cards Project With micro:bit

Tarafından PicoBricks Team 21 Apr 2025

In these days, sensors that perceive the color of passing objects are commonly used in factories to alleviate workforce. For instance, different products moving on a production line can be directed to the correct conveyor belt thanks to color-sensing sensors. Many sectors employ more advanced versions of these sensors in their factories due to this feature. With the gesture module (color and motion sensor) we will use in this project, we can detect the colours of objects around PicoBricks.

The gesture module produces three numerical outputs as R (RED), G (Green), and B (BLUE) while detecting the colors of the object in front of it. When we use these outputs as the values of the RGB LED, a single colour value is formed, and this colour is the colour of the object in front of the gesture sensor.

NOTE: The environment light level, distance to the object, and the object's opacity can affect the value detected by the gesture module. The recommended distance should be around 5 cm on average.

Connection Diagram:

You can prepare this project without making any cable connections.

Project Images

In this project, we will enable the gesture module to detect the colors of color cards we create by cutting colored cardboard, colored A4 paper, etc. This way, we will ensure that all 3 RGB LEDs in the RGB LED module light up in the same color. To do this, let's hold these colored papers in front of the gesture module.

MakeCode Code of The Project

If you have completed the PicoBricks - MakeCode connection and plugin installation steps, you can follow the steps below for our first project.

Python Code of The Project:

#Color Cards Project
from microbit import *
from picobricks import *
import neopixel
import gc

RGB_Pin = pin8  # Pin connected to the NeoPixel strip
Num_Leds = 3    # Number of LEDs in the strip

# Initialize the APDS9960 color sensor
apds = APDS9960()
apds.init_color_sensor()
gc.collect()  # Collect garbage to free up memory

# Initialize the NeoPixel strip
np = neopixel.NeoPixel(RGB_Pin, Num_Leds)

while True:
    # Read the RGB values from the color sensor
    r_color = apds.color_value("red") or 0
    sleep(100)
    g_color = apds.color_value("green") or 0
    sleep(100)
    b_color = apds.color_value("blue") or 0
    sleep(100)
    
    print("red")
    print(r_color)
    print("green")
    print(g_color)
    print("blue")
    print(b_color)
    
    r=round(round( r_color - 0 ) * ( 255 - 0 ) / ( 1023 - 0 ) + 0)
    g=round(round( g_color - 0 ) * ( 255 - 0 ) / ( 1023 - 0 ) + 0)
    b=round(round( b_color - 0 ) * ( 255 - 0 ) / ( 1023 - 0 ) + 0)

    # Set the color of the NeoPixels
    np[0] = (r, g, b)
    np[1] = (r, g, b)
    np[2] = (r, g, b)
    np.show()  # Update the NeoPixels to show the new colors
    sleep(100)  # Wait for half a second before the next update

MicroBlocks Code of The Project

Önceki Gönderi
Sıradaki Gönderi

Abone olduğun için teşekkürler!

Bu e-posta kaydedildi!

Görünümü satın alın
Seçenekleri Seçin

Seçeneği Düzenle

Stok Bildirimi

Karşılaştır

Ürün Stok KoduDeğerlendirmeAçıklama Kategori Uygunluk Ürün Tipi Diğer Detaylar
this is just a warning
Giriş Yap
Alışveriş Sepeti
0 Ürünler
Same Day Shipping No Extra Costs
Easy Returns Guarantee Return with Ease
Secure Checkout Secure Payment