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.

logic LOW using photo cell

Status
Not open for further replies.

MrDEB

Well-Known Member
need to use a photo cell to input either a logic LOW or logic HIGH but obtaining a signal level to input to pic.
Am updating my Mexican Train hub using a pic instead of the 74hc4017 circuit I ended up using.
The 74hc4017 circuit works great BUT I need to use a lower switch profile. Existing push-buttons are 3/4" long thus the board holding the Leds and switches are to high. Want to stay no higher than 3/8 inchs or less. Thus using photo calls as a switch to trigger the Leds on via the pic.
Leds OFF, cover photo cell briefly= leds on. cover photo cell again and Led turns off.
Issue is obtaining a logic level below 1.5 volts for LOW and higher than say 3v for high. want to have some lee way if possible.
 
We need to know the resistance of the photo cell when fully illuminated, and when covered with your finger. You should mount one just the same as you intend to mount the others, and make the Ohmmeter measurements in place with the ambient illumination you will be eventually using...

These are Cds Photo cells with a lowering resistance as the illumination gets brighter, right?
 
Have you thought of using small tactile push buttons **broken link removed**
Edit.
Another possible solution maybe a membrane keypad. You may find a suitable one on ebay.

Les.
 
Last edited:
I have tactil switches similar but I would need a way to mount to plywood.
my LDR = 1.9K in light and 10K in dark sorry I failed to post this info.
been breadboarding and thought I have a solution but my circuit didn't work as hoped.


5v ------LDR-------/\/\/\/\-----GRD
^ 1 K
to port

light = 2.8v

dark = .74v

my code for one port grounding the port works so code may not be culprit. Would think HIGH (2.8v) is ok and LOW(.74)???
may take another look at tactile switches but?? would need a pcboard for each switch.

WHILE TRUE
if cell = 0 then
Led = 0
end if
if cell = 1 then
led = 1
end if
delayms(500)

WEND
 
I would guess that if you are powering the PIC on 5V, the port trip point is pretty close to 1/2Vdd, or ~2.5V. I ratio-ed R1 to more-or-less center the transition on the supposed trip point.

D7.jpg

Will you be driving a LED with a different port pin that shows the state of each switch? If so, I have an idea how to add some hysteresis to each switch.
 
yes each led is powered off a different port pin
I came up with some ideas but need to simulate first.
 
It the PIC has an unused A/D input, use that and you can set the transition levels to (almost) anything you want in software. Also, you can program in different transition levels for dark-to-light and light-to-dark for hysteresis.

ak
 
I need 10 Leds, 10 LDRs so one ADC port is of no need.
using a 18F4520. Want to use a 18F2420 but not enough ports.
been contemplating a 2.4v zenier with the cathode driving the base of a transistor but using a simulation it dosen't look like it will work.
Using a voltage divider with the LDR.
 
not sure how you would implement a comparator unless your talking bout adding additional IC's. I had a passing thought about using diodes but??
I want to keep parts count to a minimum as 10 "positions" are needed.
 
Here is how to add some hysteresis to prevent the "switch" from chattering:

D7a.jpg

Think of V(cds) as being the resistance of the photocell; 2KV=2KΩ, and so on.

If you had code running in the PIC sort of like this: If(Swport) then ledPort=high else ledPort=low, then wire a feedback resistor from ledPort to Swport like R4. This provides enough hysteresis such that the photocell resistance has to go to 3.6KΩ to "close" the switch, and then to 6.5KΩ to "open" it.

A "software" assisted Schmitt Trigger?
 
Last edited:
I tried bread boarding Mikes suggestion and got no where fast.
I accidentally found out that the 18F2420 has 10 Analog / Digital I/O inputs which might be the answer I need.
 
I tried bread boarding Mikes suggestion and got no where fast...

I have done the Schmitt Trigger trick using digital ports on an 5V Arduino, and it worked first time. However, I knew a-priori the voltages that I wanted it to turn-on and turn-off. I'll bet that your problem is that you really dont know at what LDR resistance you want the "switch" to turn-on and turn-off.

I would hook up as shown in post #5, but feed it into an ADC pin. Write a small test program to display the actual ADC readings as you cover the LDR with your finger. I'll bet that the readings are not mid-scale as they should be if the LDR resistance is ~5K at the trip point.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top