Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
| × | 1 | ||||
![]() |
| × | 3 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
![]() |
| |||||
Hand tools and fabrication machines | ||||||
![]() |
|
I think the LDR (light dependent resistor) is underrated and in my opinion it's a great thing, So basically what I've made is like a tin in which you keep your item and whenever someone picks it up, boom lights turn red and blue noises, Sound fun! Right?, Lets get into how it works...
The Big ConceptThe ideas that the LDR picks up the amount light that is emitted through a RGB LED, which travels in a diagonal way and makes it's way to the LDR, but when it is obstructed with an object, the light cannot reach, so the LDR picks up low emissions, and then we program it so that if x amt. of light is emitted then something something happens else is y amt. is emitted and so on.
tin
Im using a Pokemon tin but you may use any and stick some mirror or aluminium foil in the trajectory of the light bulb's light diagonally
Resistors
Was kinda lazy stuck in the resistors like this, all of them are 330 ohms resisitors, all of them are connected to RGB led (refer to schematic)
Mini breadboard
i used a mini breadboard with a buzzer and the ldr on it, the resistor you see being used with the LDR is a 100k ohm resistor refer to schematic
Trajectory of light
like this, try to bounce the light on the mirror and foil, i used the tin because it had a metal which reflected light

#define LDRpin A0 // defining LDR pin
int LDRValue = 0;
int gpin = 3;// green pin in RGB LED
int rpin = 4;//red pin
int bpin = 5;//blue pin
const int buz = 11;
int toggle = 0;
boolean replay = true;
void setup() {
pinMode(gpin, OUTPUT);
pinMode(rpin, OUTPUT);
pinMode(bpin, OUTPUT);
Serial.begin(9600);
}
void loop() {
//========================== C H E C K U P==========================
if (replay == true) { // will trigger at starting
digitalWrite(bpin, HIGH); //initial checkup, this creates white which has most light and easy to measure unlike blue, red or green
digitalWrite(gpin, HIGH);
digitalWrite(rpin, HIGH);
delay(1000);
}
//====================================================================
LDRValue = analogRead(LDRpin);
Serial.println(LDRValue);
//=========================BEEP PHASE 2==============================
if (toggle == 1) { // we made this because after first initiative the replay is false so it wont trigger checkup the color will be blue whoose light is a bit low so we will have to change the requirements (it will scan blue)
if (LDRValue > 940) {// lowest brightness value of blue when an object is not placed and lght flows as the directed.
digitalWrite(bpin, LOW);
digitalWrite(gpin, LOW);
digitalWrite(rpin, HIGH);
tone(buz, 1000);
delay(250);
tone(buz, 2000);
digitalWrite(rpin, LOW);
digitalWrite(gpin, LOW);
digitalWrite(bpin, HIGH);
delay(250);
replay = false;
}
}
//===============================B E E P phase 1=========================
if (LDRValue > 978) { //lowest brightness value of white when an object is not placed and lght flows as the directed.
digitalWrite(bpin, LOW);
digitalWrite(gpin, LOW);
digitalWrite(rpin, HIGH);
tone(buz, 1000);
delay(250);
tone(buz, 2000);
digitalWrite(rpin, LOW);
digitalWrite(gpin, LOW);
digitalWrite(bpin, HIGH);
delay(250);
toggle = 1; // now goes to line 27
Serial.println(toggle);
replay = false; // wont trigger the initial checkup so it doesnt trgger the checkup to interupt our beep with a white color
//=============RESETTING THE BEEP after light level adjusted===========
}
else if (LDRValue < 940) {// max value of blue when obstructed by a object
toggle = 0;
noTone(buz);
replay = true;
}
}
//===================================================================
Getting to know your led color brightness
C/C++Just un-comment the color you wanna test because you can have different brightness and you may have to enter different one from mine, juts note down the points i have labelled in the code.
#define LDRpin A0 // defining LDR pin
int LDRValue = 0;
int gpin = 3;// green pin in RGB LED
int rpin = 4;//red pin
int bpin = 5;//blue pin
void setup() {
pinMode(gpin, OUTPUT);
pinMode(rpin, OUTPUT);
pinMode(bpin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// digitalWrite(bpin, HIGH);
// digitalWrite(gpin, HIGH);//uncomment the one you want to test
// digitalWrite(rpin, HIGH);
LDRValue = analogRead(LDRpin);
Serial.println(LDRValue);
}
Comments