Light Detector

by aarondubbers in Circuits > Arduino

1553 Views, 18 Favorites, 0 Comments

Light Detector

Printboard screenshot.png

In this instructable ill show you how to make a device that detects the amount of light in a room.

Supplies

Arduino Uno + usb adapter

Computer with Arduino IDE

Breadboard

10 jumper cables (for breadboard prototype)

2 LED's

2 220 ohm resistors

1 photoresistor

1 10K ohm resistor

Piezo speaker

Soldering Iron

Tin

Perfboard

6 jumper cables (for perfboard version)

2 LED's

2 220 ohm resistors

1 photoresistor

1 10K ohm resistor

piezo speaker

Optional stuff for building a chassis:

Carboard

glue gun

tape

powerbank

Breadboard Prototype

Breadboard screenshot.png
breadboard photo.jpeg
Breadboard video

This is a prototype version of the project, it works exactly the same as the permanent version but it's a little bit less structually stabile.


Start by copying the layout of the breadboard from the first image seen above.

Once you've copied the layout it should look something like the second image. Next you have to plug plug your arduino into your computer and copy this bit of code into the arduino IDE and upload it to your arduino.

const int buzzerPin = 8;
const int lightSensorPin = A0;
const int redLedPin = 9;
const int greenLedPin = 10;


void setup() {
  pinMode(buzzerPin, OUTPUT);
  pinMode(redLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  pinMode(lightSensorPin, INPUT);
}


void loop() {
  int lightLevel = analogRead(lightSensorPin);

 
  int numLightsToFlicker = map(lightLevel, 0, 1023, 1, 3);

 
  digitalWrite(buzzerPin, HIGH);

 
  flickerLights(numLightsToFlicker);

 
  digitalWrite(buzzerPin, LOW);
  digitalWrite(redLedPin, LOW);
  digitalWrite(greenLedPin, LOW);
 

 
  int delayTime = map(lightLevel, 0, 1023, 1000, 100);
  delay(delayTime);
}

void flickerLights(int numLights) {
 

 
  digitalWrite(redLedPin, LOW);
  digitalWrite(greenLedPin, LOW);
 

 
  for (int i = 0; i < numLights; i++) {
    digitalWrite(redLedPin + i, HIGH);
  }

 
  int flickerDelay = map(numLights, 1, 3, 400, 100);
  delay(flickerDelay);

 
  digitalWrite(redLedPin, LOW);
  digitalWrite(greenLedPin, LOW);
 
}

If everything is connected properly on your bread board your prototype should behave like mine does in the youtube video. The photoresistor detects the amount of light in the room and causes the lights and buzzer to flicker and beep accordingly. With low light only the first LED will flicker, it will flicker slowly and the buzzer also beeps slowly. Medium light causes both lights to flicker more frequently and the buzzer beeps quicker as well. With a lot of light both lights will flicker super fast and the buzzer will be constantly beeping. You can test the diffirent stages by holding a finger over the photoresistor or by shining a bright light into it.

Perfboard Version

Printboard screenshot.png
Printboard front.jpeg
Printboard back.jpeg
Perfboard video

Now you'll be making the soldered version of what you've just made, soldering is a little tougher to fix so ill be giving more detailed instructions.

Start of by soldering the two LED's into the board according to the first picture. Place the 220 resistors one pinhole away from the LED's negative pole (the shorter leg). Solder one of the legs of both the resistors to the negative poles of the LED's.

place the photoresistor a few spaces beneath the LED's. Place the 10K resistor one pinhole away from the top leg of the photoresistor and solder the leg of the 10K resistor to it.

place the Piezo speaker below the photoresistor. Solder it to the board. Solder a wire to the top leg of the speaker, this wil be connected to the 8th pin on the arduino.

Solder a wire to the negative pole of the photoresistor, it should be the same leg you soldered the 10k resistor to. This wire will be for the A0 pin.

Solder another wire to the positive pole of the photoresitor, if youve followed the picture and the instuctions up until this point this pole should have nothing soldered onto it. This wire you've solderen to the positive pole will be connected to the 5V pin on the arduino.

Solder a wire to the positive(longer) poles on your LED's, these wires will be for the 9th (bottom LED) and 10th (top LED) pins on your arduino.

Now for a tricky part. Solder a wire into a pin above all of the components, preferably on the side closest to the LED's. Now you have to solder all of the parts resistors and the negative pole of the speaker together, i recommend bending the unused legs of all the resistors to the next component in line and soldering them together. Once youve created one long line connecting the resistors and the bottom pin on the speaker together you have to connect this long line to the wire you soldered above the LED's, this wire is going to the GND pin on the arduino.

If youve followed the instructions and the picture correctly you're soldering and components should look similar to the second and third picture. Connect all of your wires to their corresponding pins on the arduino and make sure you've got the exact same code used for the breadboard prototype uploaded onto the arduino. If everything went well your project should work exactly like it does in the video shown above.

(Optional) Making a Chassis

final product
bomb front.jpeg
bomb side.jpeg
bomb top.jpeg
chassis 1.jpeg
chassis 2.jpeg
in chassis.jpeg
paint.jpeg

This is optional but if you want you can build a little chassis for your creation.

Start of by finding a powerbank, i recommend one large enough to stick your electronics onto. Use some tape to stick your electronics to the powerbank, be careful not to bend any connections on your perfboard into eachother because that could cause them to malfuntion. Next measure out some cardboard to make the chassis out of, make sure to either make plenty of room to cram the power adapter into the chassis or cut out two holes to pass the cable outside of the chassis and into the powerbank and arduino. I used a large piece of cardboard with folds in it to save tape because then i wouldn't have to stick it together but you can cut out each part of the chassis and stick them together if you want

next you need to take the top piece of the carboard and cut a hole into it so that you can see the LED's and photoresistor, you need a hole that allows light to pass through otherwise it won't work, if you can use a bit of clear plastic to make a little window for the hole so that you wont have to worry about stuff falling into the box.

If you want you can also paint your cardboard, i spraypainted mine matt black. Stick your chassis together but leave one side open for electronics. Stick the powerbank and electronics inside of the chassis and make sure that everything works well before you close it up.

Chances are that your chassis will look nothing like the one in the video, but that's why this is an optional step. Let your creativity run wild while making the chassis, maybe you can make it look like a geiger counter?