Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Light detector and beeper.

Status
Not open for further replies.

mramos1

Active Member
I need to design a circuit that will detect if a light is turned on, if so make a sound (beep) every 30 second. I have my version done, but looking for a simpler, less expensive way to do it if someone has a better idea.

My version, is a photo cell (when the photocell is down to 1K it is the activate the beep), to an op-amp, to a microcontroller. Th microcontroller sees a high from op-amp and in software every 30 seconds I pulse a piezo (via a transistor). When the op-amp is 0 (photocell over 1K; no light on) the microcontroller just loops.

It will run on a 9VDC battery. Anyone have a nifty 555 version, and with the battery, it would be nice to have it not draw a lot of current when the light is off.

Maybe I will have the photocell power the uC.. Anyway, any ideas?
 
Last edited:
What circuit would you using to tie to the input of the uC. The photocell goes from 200K (dark) down to 500ohms (bright light), at 1K it is pretty bright, that that would be a good value to turn it on. Also, it will be on a 9volt.

My first attempt on the breadboard was a bust. It was an attempt to power up the uC at the 1K mark, rather than it always be running.
 
Check my Joystick PIC tutorial, this uses a simple capacitor charging technique to read a variable resistor - it's simple (and common practice) to read an LDR using this technique. Only hardware required is the LDR, one capacitor and (optionally) one resistor.


To drastically reduce (the already low) current consumption, put the PIC into sleep mode, and use the watchdog timer to wake it up periodically - the WDT isn't accurate, but doesn't need to be for this use.
 
Nigel Goodwin said:
Check my Joystick PIC tutorial, this uses a simple capacitor charging technique to read a variable resistor - it's simple (and common practice) to read an LDR using this technique. Only hardware required is the LDR, one capacitor and (optionally) one resistor.

I clicked on the joystick tutorial and there was PIC code. Is there are diagram of the LDR and cap configuration. I really like the watchdog idea, wake up every 60 seconds or so and check it, and beep if required. Just not sure how to get the LDR to the pin and get the 1/0 toggle I need.

Thanks for the info, and if there is a link to the tutorial, that would be great.
I was after really low power.
 
mramos1 said:
I clicked on the joystick tutorial and there was PIC code. Is there are diagram of the LDR and cap configuration. I really like the watchdog idea, wake up every 60 seconds or so and check it, and beep if required. Just not sure how to get the LDR to the pin and get the 1/0 toggle I need.

Thanks for the info, and if there is a link to the tutorial, that would be great.
I was after really low power.

The diagram for the joystick interface is under the hardware section, you simply replace the joystick variable resistor with the LDR. Depending on relative resistances you may have to alter the capacitor value and the counter timing in the software.
 
Found it. I will map this pins on the joystick and find one of the pot parts and take a look. I did not look at the code, but will the result be a 1/0 on the pin or ADC type use? I see caps to ground. Are the LDR and cap configured like a voltage divider? Will read your post two back and get that name of the circuit and look for that as well.
 
an alternate approach (and close to what you asked for) uses no microcontroller - use the LDR for a voltage divider input into a comparator, trimpot for the other input (to adjust light level). use this to drive a 555 with a 30 sec cycle which in turn drives another 555 which drives the piezo at the resonant frequencies. You might need a transistor to drive the piezo if it's draw is above the 555's spec. You could use a dual timer (556) to cut the part count. maybe $2 worth of parts.
 
philba said:
an alternate approach (and close to what you asked for) uses no microcontroller - use the LDR for a voltage divider input into a comparator, trimpot for the other input (to adjust light level). use this to drive a 555 with a 30 sec cycle which in turn drives another 555 which drives the piezo at the resonant frequencies. You might need a transistor to drive the piezo if it's draw is above the 555's spec. You could use a dual timer (556) to cut the part count. maybe $2 worth of parts.

I like Nigel's idea on the LDR and cap right to the uC pin, just not sure how yet. Just have to figure out how to hook it up without the op-amp.

The 339 and 556 would add cost, were the uC at $.56 is low cost and can be altered easy (since I have programmers and compiler already). Now to find time to breadboard it.
 
mramos1 said:
I like Nigel's idea on the LDR and cap right to the uC pin, just not sure how yet. Just have to figure out how to hook it up without the op-amp.

You simply place the LDR where the variable resistor in the joystick goes, from 5V to either of the two 2.2K resistors (depending which half of the joystick you're replacing).

It works in the same way as a PC joystick port, timing how long the capacitor takes to charge. Basically like this:

1) Discharge capacitor - make I/O pin an OUTPUT, and set HIGH.

2) Let capacitor charge - make I/O pin an INPUT.

3) Increment counter until I/O pin goes HIGH.

4) Counter now contains a value representing the value of the charging resistor.
 
Think I am with you. I did not realize you were talking using the pin as both in and out. But a great idea.

So LDR to 5V and to IO_pin, cap from IO_pin to ground. Put 5V on for a second by making IO_pin an output and setting it high, then flip to input and count until the pin goes high. Lower counter number the light in on (as the LDR will pull it to 5V via its 1K ohm pull when the lights are on).

I can also blink an LED to let me know the count as I have no display and will need to debug it. Blink 100's, 10's and 1's on the LED.

If I am always running in a loop watching the LDR/CAP, the battery will not last long will it? Maybe I should have a second LDR and resistor to a FET to power the uC on? Or wake the uC up?
 
Last edited:
akg said:
Nigel's idea is good - if u want to 'measure' the resistance change

I can't claim that it's MY idea, it's a standard technique, and been used for many, many years - but often, these days in particular, people tend to not know of it (basically because they are used to having internal A2D to use).
 
Nigel Goodwin said:
I can't claim that it's MY idea, it's a standard technique, and been used for many, many years - but often, these days in particular, people tend to not know of it (basically because they are used to having internal A2D to use).
Yes i know..because ..i have seen this in the Tips 'n Tricks @ microchip
 
Nigel Goodwin said:
You simply place the LDR where the variable resistor in the joystick goes, from 5V to either of the two 2.2K resistors (depending which half of the joystick you're replacing).

It works in the same way as a PC joystick port, timing how long the capacitor takes to charge. Basically like this:

1) Discharge capacitor - make I/O pin an OUTPUT, and set HIGH.

2) Let capacitor charge - make I/O pin an INPUT.

3) Increment counter until I/O pin goes HIGH.

4) Counter now contains a value representing the value of the charging resistor.

I have LDR to 5V and uC in/out pin. I have cap from io/out pin to ground.

I set pin to HIGH for 500msec, then read it back 256 times, and it is always HIGH. Should I have made it LOW rather than make it HIGH, then watch it charge?

I just tried it and on the scope, it goes high with a time constant. Will try another CAP value, little larger as I plan to run it as 32K later (at 1mhz right now and all I see it HIGH).


Just
 
Last edited:
Woohoo.. She works.

Nigel, I caught the HIGH that should be a low (I thought don't I want the LDR to discharge the cap and it is tied to 5V). But since you are generally right on the money, did not question it. Until I hook up the scope. Fixed that.

FYI, your joystick tutorial has a .2uF and I went with .1uf since I had one laying on the bench. It was not a good count difference with the light changes.. I dropped another .1uF in parallel (like your tutorial has .2uF) and it is absolutly perfect.

Now to get the peizo going, then move code to Tiny11 and drop from 1Mhz to 32Khz. So I see that big a bigger cap in my future.

Thanks for the trick.
 
mramos1 said:
Woohoo.. She works.

Nigel, I caught the HIGH that should be a low (I thought don't I want the LDR to discharge the cap and it is tied to 5V). But since you are generally right on the money, did not question it. Until I hook up the scope. Fixed that.

Sorry, a little typo :)
 
Status
Not open for further replies.

Latest threads

Back
Top