It is called the state of being autonomous when electronic systems make a decision based on the data they collect and perform the given task automatically. The components that enable electronic systems to collect data from their environment are called sensors. Many data such as the level of light in the environment, how many degrees the air temperature is, how many lt/min water flow rate, how loud the sound is, are collected by the sensors and transmitted to PicoBricks as electrical signals, that is data. There are many sensors in Picobricks. Knowing how to get data from sensors and how to interpret and use that data will improve project ideas like reading a book improves vocabulary.
In this project, with PicoBricks, we will enable the LED to turn on when the amount of light decreases in order to understand the working systems of the systems where the lighting is turned on automatically when it gets dark.
Details and Algorithm
Sensors are electronic components that detect data in external environments and send data to microcontrollers. The LDR sensor also detects the amount of light in the environment and sends analog values. In our project, we will first check the incoming data when the environment is light and dark by reading the LDR sensor values, then we will set a limit according to these data, and if the amount of light is below this limit, we will turn off the RGB LED of Picobricks, if not, we will turn off the LED.
Components
1X PicoBricks
Wiring Diagram
You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.
MicroBlocks Codes of the PicoBricks
You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button
MicroPython Codes of the PicoBricks
import time
from machine import Pin, ADC
from picobricks import WS2812
#define the library
ldr = ADC(Pin(27))
ws = WS2812(6, brightness=0.4)
#define the input and output pins
#define colors
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
COLORS = (RED, GREEN, BLUE)
#RGB color Code
while True:#while loop
print(ldr.read_u16()) #print the value of the LDR sensor to the screen.
if(ldr.read_u16()>10000):#let's check the ldr sensor
for color in COLORS:
#turn on the LDR
ws.pixels_fill(color)
ws.pixels_show()
else:
ws.pixels_fill((0,0,0)) #turn off the RGB
ws.pixels_show()
Arduino C Codes of the PicoBricks
#include
#define PIN 6
#define NUMLEDS 1
#define LIGHT_SENSOR_PIN 27
Adafruit_NeoPixel leds = Adafruit_NeoPixel(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
//define the libraries
int delayval = 250; // delay for half a second
void setup()
{
leds.begin();
}
void loop()
{
int analogValue = analogRead(LIGHT_SENSOR_PIN);
for(int i=0;i < NUMLEDS;i++)
{
if (analogValue > 200) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
leds.setPixelColor(i, leds.Color(255,255,255));
leds.show(); // This sends the updated pixel color to the hardware.
delay(delayval);
}
else {
leds.setPixelColor(i, leds.Color(0,0,0)); //white color code.
leds.show(); // This sends the updated pixel color to the hardware.
}
}
delay(10);
}
Project Image
Project Video
Project Proposal 💡
In this project, we turned on the LED on the LDR sensor data on Picobricks if the environment was dark, and turned off the LED if it was bright. By processing the LDR sensor data, you can code a nightlight or table lamp in your home to turn on automatically in the dark. You can use the relay on Picobricks for this.
2 Comments
I am trying to figure out, why there is NEO_GRB in the 6. line of code, but in the 23. linte we can use RGB values to define colors.
And if you switch to NEO_RGB you then input GRB colors to the line 23. Does it have something to do with how the Adafruit_Neopixel.h is written ? I am just a bit confused because i am trying to learn C with this nice procejt but it feels like not all the things are explained properly.
Yes, it has to do with writing Adafruit_Neopixel.h. We call the color variable from the NEO_GRB class in the Adafruit_NeoPixel library and light the color value we want with the RGB LED.
We’ve kept the comment lines short to fit the page, but we’d like to assist you in the process. You can report your questions by leaving a comment.
Thanks…