You have always wanted to turn the lamps on and off by clapping while lying in your bed. In this project, we will learn how to turn the lights on and off with clapping, and how it works. We used Raspberry Pi Kit in the project.
Most of us have seen lamps flashing magically or doors opening and closing with the sound of clapping in movies. There are set assistants who close these doors and turn off the lamps in the shootings. What if we did this automatically? There are sensors that convert the sound intensity change that we expect to occur in the environment into an electrical signal. These are called sound sensors.
MicroPython Codes of the PicoBricks
from machine import Pin #to access the hardware on the pico
sensor=Pin(1,Pin.IN) #initialize digital pin 1as an INPUTfor Sensor
led=Pin(7,Pin.OUT)#initialize digital pin 7as an OUTPUTforLEDwhile True:
#When sensor value is '0', the relay will be '1'print(sensor.value())if sensor.value()==1:
led.value(1)else:
led.value(0)
Arduino C Codes of the PicoBricks
void setup() {
// put your setup code here, to run once:
pinMode(1,INPUT);
pinMode(7,OUTPUT);
//define the input and output pins
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(digitalRead(1));
if(digitalRead(1)==1){
digitalWrite(7,HIGH);
delay(3000);
}
else{
digitalWrite(7,LOW);
delay(1000);
}
}
GitHub Project Page
Tags: