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.

variable LDR circuit

Status
Not open for further replies.

philr

New Member
Hello

I am in the very early stages of making a light sensitive circuit using a microcontroller.

the idea is to have a variable setting using a LDR and a variable resistor to allow me to fine tune at what light levels is want to trigger pulses to a RC servo to either open or close a door.

From what i have been reading it seems the pulses part of the project to the servo is fairly easy, but not sure of best way to use the LDR, i am using a pic 16f690 (but only because my progger come with it).

Was wondering if this would work picture hopefully attached, by making one of the pins high, or is the comparator the best way to go.

anyone acheived something like this before or tips or pit falls to consider, novice at electronics and pic programming so please dont assume i will understand if getting technical LOL many thanks

Phil tranldr2.gif
 
Connect the LDR/pot between +5V and Common. Use the PIC's ADC input the measure the voltage at the LDR/pot junction. The program can compare that voltage to a constant you set, and act accordingly.

Ken
 
Hi Ken thanks for your reply, i think i have just found an example of what you mean, cannot seem to copy and past or attach so web page where look at 27 section 3. The web page also has other great ideas to look at.

web page here Interfacing With Microcontrollers
 
That's it. Lots of good basic (pun intended) information there.

Ken
 
I have to admit it, i am struggling. Just received a book today from amazon "PIC MICROCONTROLLER PROJECT BOOK" using pic basic and pro.

trouble is that it is 2004, so the section on ADC shows using an external chip and thus program is different.

i know members take a dim view on leechers, but i am trying to get the pic basic pro language for the simple ADC for a 16f690 pic. i have tried google but could not really get a hit for what i am looking for, i love to learn by reading books but amazon mostly shows older books which presumably will have the same problem as before.

can anyone point me in the right direction for either a up to date book, or how best to use google to get more of what i am looking for.

thanks in advance
 
Philr
I've used the LRD /A/D a lot over the last few years and this has worked for me
I connect a A/D input pin directly between the LRD and Pot with the other leg of the LRD to vss and the other leg of the pot connected to Vss ( I use a output pin an only turn on when needed.

if your using Pic Basic Pro
something like this
Code:
LDR=1:Pause 250           'TURN LDR/ADCIN POWER ON


TEST:
NIGHT=0
LED=0
ADCIN 0,NIGHT          'CHECK AN# READ AN0 & STORE IN NIGHT VAR
 
 IF NIGHT=<550  Then LED=1   'IF LED IS ON THEN IT'S LIGHT 
 Pause 250
of course you will need to set up your A/D
I understand were you coming from I'm just a hobbyist TOOOOOOOOOOO
 
My first attempt, and it does not work !!

I must admit all i have done is loads of googling and copied bits of programming language from different web sites. can anyone have a look at the simple program which is designed to light one of two leds to represent open and closed / light and dark at this time, and point out any cockups that is blatantly obvious to the experienced that an amateur like me has missed.

thanks in advance

main:
define adc_bits 8
define adc_clock 1
define adc_sampleus 10
adcvar var byte
trisa=%11111111
adcon1=%100000100
ansel = 1
pause 500
adcin 0, adcvar
pause 50
if adcvar>1500 then gosub led1
if adcvar<1500 then gosub led2
goto main
led1:
trisb.5=0
portb.5=1
return
led2:
trisb.6=0
portb.6=1
return
 
What microprocessor and what version of BASIC are you using? Also, please post the schematic of what you have set up.
 
i cannot upload the image, but it is a simple voltage divider circuit, +5 v two resistors ground and between both resistors a lead going to AN0 of the PIC.

i am using picbasic pro

oh and using a pic 16f690
 
Last edited:
Sorry, I'm not familiar with that particular BASIC. It really helps if you annotate you program lines, especially if you have others troubleshoot it. How many bits is the ADC...8?...10?...12? What is the measured range of voltages (with a DVM) at the ADC input, for light and dark.

Ken
 
Phil
check your PM

Phil,

Why not post the code here, so other forum participants might benefit. The concept of the forum is to not only provide help to specific posters, but also leave the information for other and future users.

Ken
 
Phil,

Why not post the code here, so other forum participants might benefit. The concept of the forum is to not only provide help to specific posters, but also leave the information for other and future users.

Ken

post edited by philr
 
Last edited:
Sorry Phil, the post should have been address to Homemade24, not you.

Ken
 
i have edited my last few posts as i have messed up big time, and upset the only person who helped, for that i can only say "SORRY I MESSED UP, BUT DID NOT INTEND TO"
 
Last edited:
i have edited my last few posts as i have messed up big time, and upset the only person who helped, for that i can only say "SORRY I MESSED UP, BUT DID NOT INTEND TO"

phil,

Would you explain that?

Ken
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top