0

Yet another ques.. digital photo detector/resistor
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Yet another ques.. digital photo detector/resistor

by rizla420 on Wed Sep 16, 2009 7:15 pm

What the best way to get a digital reading for presence of light? I want something that i can use with a shift in register, so analog wont work for me.

I've been stuck trying to determine the presence of an object. I've gone back an forth between creating a contraption that based on the weight of an object that will push a tactile button or something that can detect an object above it through some other means. I think using some sort of photo detector might be a better route. If there's light, something is on it, if there isnt its off.

Any ideas?

rizla420
 
Posts: 332
Joined: Thu Feb 05, 2009 9:03 pm

Re: Yet another ques.. digital photo detector/resistor

by zener on Wed Sep 16, 2009 8:14 pm

IR

LED

Photodiode/transistor

zener
 
Posts: 4445
Joined: Sat Feb 21, 2009 2:38 am

Re: Yet another ques.. digital photo detector/resistor

by rizla420 on Thu Sep 17, 2009 10:13 am

Zener wrote:IR

LED

Photodiode/transistor


I didnt want to have it use IR, just wanted to use it to detect the ambiant light. From what i've seen all the photodetectors/resistors output different frequencies based on the amount of light it senses. I was hoping there was some sort of sensor that outputed a digital HIGH/LOW based on light.

rizla420
 
Posts: 332
Joined: Thu Feb 05, 2009 9:03 pm

Re: Yet another ques.. digital photo detector/resistor

by hinermad on Thu Sep 17, 2009 10:45 am

If you want to detect the presence of something close up, relying on ambient light can cause erratic operation. Somebody may turn off the room lights, or a bird may fly over.

You could use an assembly like this, which provides its own illumination:

http://www.pololu.com/catalog/product/958

The output from the phototransistor would connect to a digital input on your microcontroller. The voltage would go low when the phototransistor receives light, implying light from the LED was reflecting from a nearby object.

If you wanted to make your own detector you could get a phototransistor or photocell and duplicate the circuit. You might need to fiddle with the resistor values to get the right sensitivity, but the 47k shown in the schematic is a decent starting place.

Dave

hinermad
 
Posts: 56
Joined: Sun Sep 13, 2009 1:25 pm
Location: Upstate New York, USA

Re: Yet another ques.. digital photo detector/resistor

by rizla420 on Thu Sep 17, 2009 12:38 pm

Hinermad wrote:If you want to detect the presence of something close up, relying on ambient light can cause erratic operation. Somebody may turn off the room lights, or a bird may fly over.

You could use an assembly like this, which provides its own illumination:

http://www.pololu.com/catalog/product/958

The output from the phototransistor would connect to a digital input on your microcontroller. The voltage would go low when the phototransistor receives light, implying light from the LED was reflecting from a nearby object.

If you wanted to make your own detector you could get a phototransistor or photocell and duplicate the circuit. You might need to fiddle with the resistor values to get the right sensitivity, but the 47k shown in the schematic is a decent starting place.

Dave


Hey dave, thanks for taking the time to research that for me. Sparkfun has this:https://www.sparkfun.com/commerce/product_info.php?products_id=246

Think its similar? or is that more like the second route you mentioned, but just combined into one unit?

BTW, the one you linked to was the analog version. This one outputs digitally: http://www.pololu.com/catalog/product/959. Since its digital could I daisy chain them with a shift in register to read multiples of these? I need 20 (banned.. thats expensive come to think of it).

rizla420
 
Posts: 332
Joined: Thu Feb 05, 2009 9:03 pm

Re: Yet another ques.. digital photo detector/resistor

by hinermad on Thu Sep 17, 2009 3:04 pm

rizla420 wrote:Hey dave, thanks for taking the time to research that for me. Sparkfun has this:https://www.sparkfun.com/commerce/product_info.php?products_id=246

Think its similar? or is that more like the second route you mentioned, but just combined into one unit?

That part has just the LED and phototransistor. You'd still need resistors, but that's generally what I was talking about.

BTW, the one you linked to was the analog version. This one outputs digitally: http://www.pololu.com/catalog/product/959. Since its digital could I daisy chain them with a shift in register to read multiples of these? I need 20 (banned.. thats expensive come to think of it).

I'll let you in on a little secret - all of electronics is analog. Digital is just a set of convenient rules and assumptions that make it easier to design certain kinds of circuits. Both of those circuits will output an analog signal; the only difference is that the "digital" version can be used by a microcontroller to measure the brightness of the light picked up by the phototransistor.

Both of these sensors rely on the fact that a digital input will take any voltage above a certain level as a high, and any voltage below a certain level as a low. The only difference between the two sensors is that you need to also use an output to charge the capacitor in the "digital" version, then measure how long it takes the input to change back to its original state. The longer it takes, the dimmer the light.

If you use the analog sensor you can't measure relative brightness, just whether it's bright or dark. But you also won't need a digital output to charge anything, just the input. By changing the value of the resistor connected to the phototransistor you can change the amount of brightness needed to make the input say "bright." Since you'd need to tailor the resistor value to your application anyway, I'd suggest using that Sparkfun part you linked to. You could use a potentiometer in place of the resistor and adjust it until the input switched at the correct brightness, then measure the pot with an ohmmeter and use a fixed resistor near that value.

Dave

hinermad
 
Posts: 56
Joined: Sun Sep 13, 2009 1:25 pm
Location: Upstate New York, USA

Re: Yet another ques.. digital photo detector/resistor

by rizla420 on Thu Sep 17, 2009 3:53 pm

I guess i shouldnt of bought 20 of the digitals then.. woops.

One of the major aspect to this project that i need though is to be able to wire 20 of them up with using a minimal amount of pins on the arudino. Im thinking of taking a new direction with the project i'm working on, hence me looking at these light sensors.

In a nutshell i'm trying to determine if an object is resting on a particular spot. The way i have it right now i'm using 20 tactile push buttons (the chepo .30/ea ) ones resting in an assembly I created. When something sits on top of it, it pushes the button down and the microcontroller is aware of it. I'm making heavy use of shift registers to keep my pin usage count low because I want to incorporate the wave shield and xbee.

The problem with my solution is that it requires too much work to create the assemblies. I had to create molds and have to cast resin into them for each. It takes up a lot of time. I'm looking for a more simple elegant solution. I was hoping that by using a sensor that gauges light i would simplify it a little bit.

But it seems like a light sensor brings its own set of headaches. It doesnt seem like i can use a shift register to read the value of 20 of those sensors.. and as you stated with the digital sensors that I bought i need an output pin to pulse it.. that was a nice $60 mistake on my part.

Im clueless right now on the best way to determine if an object is sitting on a surface.

rizla420
 
Posts: 332
Joined: Thu Feb 05, 2009 9:03 pm

Re: Yet another ques.. digital photo detector/resistor

by rizla420 on Thu Sep 17, 2009 4:37 pm

Just had another idea. Been reading up on reed switches. Maybe i can put a reed switch down and then embed a magnet in the object and then whenever its close it will cause the reed switch to close.. hmm.. could work. I think i could use them in conjunction with the shift in registers. WOuld i still have to use resistors similar to the pull up/down button to cut down on the floating measurements or will it be a solid on off with the reed switch?

rizla420
 
Posts: 332
Joined: Thu Feb 05, 2009 9:03 pm

Re: Yet another ques.. digital photo detector/resistor

by hinermad on Thu Sep 17, 2009 4:39 pm

You can still use the sensors you've ordered if you don't mind hacking on them a little bit. If you replace the caps with 47k (or whatever value works best for you) resistors you can still use them, and you won't need an output pin to charge them. You can still use your shift register idea - just hook the output of each sensor to an input on the shift register. (Make sure to power the sensors from the same supply as your shift registers, too.)

Dave

hinermad
 
Posts: 56
Joined: Sun Sep 13, 2009 1:25 pm
Location: Upstate New York, USA

Re: Yet another ques.. digital photo detector/resistor

by rizla420 on Thu Sep 17, 2009 4:49 pm

Hinermad wrote:You can still use the sensors you've ordered if you don't mind hacking on them a little bit. If you replace the caps with 47k (or whatever value works best for you) resistors you can still use them, and you won't need an output pin to charge them. You can still use your shift register idea - just hook the output of each sensor to an input on the shift register. (Make sure to power the sensors from the same supply as your shift registers, too.)

Dave



I actually called up and canceled the order for those sensors. Now i'm looking at reed switches, i just found these on ebay: http://cgi.ebay.com/Pack-of-50-Magnetic-Reed-Switches-10W-HYR-2001-SPST-NEW_W0QQitemZ300348647994QQcmdZViewItemQQptZLH_DefaultDomain_2?hash=item45ee2caa3a&_trksid=p3286.c0.m14 I think they might rated to high for use with the arudino though, but im not sure. Anyone know?

rizla420
 
Posts: 332
Joined: Thu Feb 05, 2009 9:03 pm

Re: Yet another ques.. digital photo detector/resistor

by hinermad on Thu Sep 17, 2009 5:08 pm

rizla420 wrote:I think they might rated to high for use with the arudino though, but im not sure. Anyone know?


You can't really have a switch that's rated too high for another device because switches don't source power. It's like saying a pipe is too big for the water flowing through it. Switches just carry what you give them. The specs for those devices say they can safely switch up to 200 volts and up to 0.5 amps. But you're not going to be putting that kind of stress on them. (Are you? (Grin)) You'll most likely be switching 5 volts and current in the milliamps. As long as these are physically small enough to fit your application, they should be almost perfect. You'll still need a pullup resistor for each switch, but a 4.7k resistor connected to a 5 volt source only draws a whisker more than 1 mA.

Dave

hinermad
 
Posts: 56
Joined: Sun Sep 13, 2009 1:25 pm
Location: Upstate New York, USA

Re: Yet another ques.. digital photo detector/resistor

by rizla420 on Thu Sep 17, 2009 5:57 pm

Hinermad wrote:
rizla420 wrote:I think they might rated to high for use with the arudino though, but im not sure. Anyone know?


You can't really have a switch that's rated too high for another device because switches don't source power. It's like saying a pipe is too big for the water flowing through it. Switches just carry what you give them. The specs for those devices say they can safely switch up to 200 volts and up to 0.5 amps. But you're not going to be putting that kind of stress on them. (Are you? (Grin)) You'll most likely be switching 5 volts and current in the milliamps. As long as these are physically small enough to fit your application, they should be almost perfect. You'll still need a pullup resistor for each switch, but a 4.7k resistor connected to a 5 volt source only draws a whisker more than 1 mA.

Dave



only 4.7koh resistor? In my current setup i'm using 10Kohm and a 10ohm with the tacticle buttons and they seem to work well

The 10Kohm is connected to the 5V and the 10ohm is going to the arduino input pin.

BTW, i bought those reed switches. Its amazing how now adays you can buy stuff directly from china. The world is shrinking by the day.

rizla420
 
Posts: 332
Joined: Thu Feb 05, 2009 9:03 pm

Re: Yet another ques.. digital photo detector/resistor

by hinermad on Thu Sep 17, 2009 6:49 pm

rizla420 wrote:only 4.7koh resistor? In my current setup i'm using 10Kohm and a 10ohm with the tacticle buttons and they seem to work well

The 10Kohm is connected to the 5V and the 10ohm is going to the arduino input pin.

That should work fine. I only mentioned 4.7k as an example of how little current you'll be using. 10k will use half that.

Good luck!

Dave

hinermad
 
Posts: 56
Joined: Sun Sep 13, 2009 1:25 pm
Location: Upstate New York, USA

Re: Yet another ques.. digital photo detector/resistor

by rizla420 on Thu Sep 17, 2009 7:00 pm

Dave,

Last question, i promise (maybe :P ). Why would I need to use any resistor if i'm using the reed switch approach? Isnt it only goign to output 0 (low) when its off and then 1 (high) when its on?

rizla420
 
Posts: 332
Joined: Thu Feb 05, 2009 9:03 pm

Re: Yet another ques.. digital photo detector/resistor

by hinermad on Thu Sep 17, 2009 8:21 pm

An input on a microcontroller or other digital device can only detect a high or low voltage. A switch by itself doesn't generate any voltage at all, so if you connected only it to a digital input the input would only ever see a low voltage. (In the real world it might pick up static discharges or other sources of electrical noise, but it's a sure bet they're not what you want your circuit to detect.) The simplest way to get a voltage is to steal it from the power supply. By connecting a resistor from the 5V supply to the input (that's called a pullup resistor), there's a guaranteed source of voltage. But unless you have some way of changing or removing that voltage it just stays high all the time, and that's not very useful. So you hook a switch from the input to ground, and when something interesting happens to close the switch the input see a change from high (5V) to low (0V).

You need to use a pullup resistor because if you just used a wire to connect the 5V supply to the switch then when the switch closed it would create a short circuit from 5V to ground. At best it would just pull the whole 5V supply down to 0V, causing the circuit to quit working. More likely it would blow a fuse in the power supply, damage the supply, or destroy the switch contacts.

Many microcontrollers have built-in pullups on their inputs, so with them you really only need to connect a switch from the input pin to ground. But if you're using logic chips like shift registers, they won't have built-in pullups so you need to used separate resistors.

Dave

hinermad
 
Posts: 56
Joined: Sun Sep 13, 2009 1:25 pm
Location: Upstate New York, USA

Please be positive and constructive with your questions and comments.