One little trick I have always liked is to use a lm78L05 to92 cased regulator to feed your input, then you only flow 5v into the pic and it is small as a transistor and cheap too.
One little trick I have always liked is to use a lm78L05 to92 cased regulator to feed your input, then you only flow 5v into the pic and it is small as a transistor and cheap too.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
HenrikOlsson: Thanks, your answer is very helpful and informative. Just to be sure though, when you said point 4 above (for the high value resistor) did you mean point 2?
With the switch that makes sense, before starting on this I was originally thinking that there was high low and open but as you say it is either 0 or 5V.
Archangel: That's a neat trick, thank you.
Indeed I did, sorry about that.Thanks, your answer is very helpful and informative. Just to be sure though, when you said point 4 above (for the high value resistor) did you mean point 2?
Actually, you can, instead of switching the output between high and low switch the pin between output (high or low) and input (high impedance). But in this case you'll end up with the same problem as with the LED. When the pin is an input current would flow thru whatever "feeds" the switch, into the PIC pin, up thru the clamp diode and into the 5V rail making the voltage at (4) around 5.5V which might fool the external circuit into thinking the button is pressed. Obviously all this depends on what is actually inside that black box.With the switch that makes sense, before starting on this I was originally thinking that there was high low and open but as you say it is either 0 or 5V.
I created a simulation of two LEDs using a breadboard and and using the 47K Ohm resistor approach it work, I could sense which LED was on or if neither were on.
However, sometimes it seems to get confused and misread, it is as if there is some interference or noise being picked up. I check all the connections and tried varying the resistors but it still happens.
Any thought?
I'm also going to pick up some lm78L05 to92 and give that approach a try as well.
Thanks again for the help and continued education
I would suggest trying a lower value resistor but it seems you've already done that.
What is the voltage at the pin (on the PIC) when the LED is on and off? Are you running the PIC on 5V?
I think I found the problem, although not entirely sure why it did what it did. The initial LED circuit had one LED and when I added the second (in haste) I shared the same dropping resistor (based on the fact that that both LEDs would never be on at the same time). Giving each LED its own resistor appears to have solved the problem.
The voltage at the pin is 5.6V Off and 0V (0.5mv on my meter) On
The PIC is running on 5V (via 7805) but both circuits are fed from the same 12V supply, that is how it will be with the final circuit.
thanks again.
Update and further question:
I'm sensing the state of 6 LED's using the resistor approach which a great with 5 out of the 6 LEDs. I'm using a resistor of great enough value not to light the LED.
The problem with one of the LED is that the sensing is unreliable (sometimes it would read the LED coming on and sometimes it wouldn't). Using a meter I found that when the problem LED was on the voltage was ~1.2V at point 2 of the original diagram where the other 5 were at close to zero. It is strange because all 6 LEDs are in the same circuit. The issue appears to be that the PIC sees the ~1V as high which makes sense.
I did tried the lm78L05 to92 approach but couldn't stop it causing the LED to be illuminated when the LED was off.
Any ideas?
Last edited by Bdlhome; - 13th August 2011 at 13:35.
I have been using the resistor approach and sensing the voltage when the LED is off and then that drops close to zero when the LED is illuminated.
There are 6 LEDs in play and 5 out of the 6 work flawlessly but I'm having problems with one and it is driving me crazy.
Intermittently the PIC reads the input as positive even when the LED is illuminated just on that one LED. Further information to set the scene:
This circuit is in a car
When the engine isn't running it appears much more reliable (suggesting perhaps noise or voltage related)
With the engine running, turning on the courtesy light will sometimes correct the reading (falsely reading until the courtesy light is turned on and then it reads correctly). This again suggested voltage but turning on something else like the headlights does not have the same effect.
I've tried varying the resistor value and putting in capacitors but has no effect.
Anybody have any ideas? I'm pulling my hair out here.
Bookmarks