Home - Search - Members
Full Version: Interfacing LDR with 8051
SkyTerror17
Sep 26 2011, 2:51 AM
Hi guys,
My project is a medical reminder and dispenser system.
So I am planning to use LDR to act like a switch to send a high or low to a 8051 pin with only just my circuit.
My main idea was to use sbit to turn off a buzzer and LED when it is low and turn on a buzzer and LED when it is high.

I need help for the programming codes as I am bad at it.
Any help or tips would be greatly appreciated!



majoka
Sep 26 2011, 3:56 AM
sbit is used in c it means u want to do coding in c
#include<reg51.h>
// let say pins are as i suppose
sbit LDR = P1^0;
sbit LED = P1^1;
sbit BUZ = P1^2;

void main (void)
{
BUZ=LED=0;  // off the buzzer and led at start up
while(1)         // forever loop
{
if(LDR==1)   // if high
{
LED=BUZ=1;
}
else           // it means low
{
LED=BUZ=0;
}
}
}


SkyTerror17
Sep 26 2011, 11:32 AM
Oh ya, I wanna code in with C programming, forgotten to mention it!
Alright, thanks for the help! I will give it a shot and update you about it!

Ajay Bhargav
Oct 2 2011, 8:35 AM
We are waiting for update..
SkyTerror17
Oct 3 2011, 10:48 PM
Just got back from a school overseas industrial visit, sorry for not updating!
Apparently, I am having some trouble to allow the LDR to communicate with the 8051, as the LDR is analog while 8051 is digital.
So I am finding a way to convert the analog signal to digital as they cant communicate directly.
The LED has 2V when high, 1.5V when low.
While my LDR has 0.7V when high, 0.5V when low.
And I am figuring how to adjust the LED port to 3.3V at the moment.
majoka
Oct 4 2011, 1:23 AM
@ SkyTerror17
u can use op amp LM741 as a comparator
SkyTerror17
Oct 4 2011, 2:35 AM
Alright, am trying it now. But judging from my current schematic, I need to replace the LM741 with the 2N3904 transistor?
romel_emperado
Oct 4 2011, 2:43 AM
Hi,

There is also an exmple project here for LDR and 8051..

http://romelemperado.blogspot.com/2011/08/inout-door-counter-with-nokia-3310-lcd.html
SkyTerror17
Oct 4 2011, 3:30 AM
Is there any single supply op amp that you guys could recommend?
majoka
Oct 4 2011, 3:32 AM
u can use LDR as
http://www.matni.com/Arabic/Elec-Info/LIGHT%20SWITCH/sensor2.htm
it is better way of using LDR
SkyTerror17
Oct 4 2011, 3:40 AM
Yeah, I saw that website, its really useful.
But I am required to use a single supply op amp and no relay.
Is there anyway to test a schematic using some software program or something?
majoka
Oct 4 2011, 6:18 AM
@ SkyTerror17
u can operate that circuit with 5 volt
12 volt is for relay
replace a relay and diode with 10k resistor and get logic on the collector of transistor
SkyTerror17
Oct 4 2011, 8:47 AM
Oh okay I will try it and update you!
SkyTerror17
Oct 4 2011, 9:39 PM
Just asking, what if my power supply is single supply? Does it still works?
majoka
Oct 5 2011, 12:42 AM
@ SkyTerror17
in normal cases single power supply is need connect (-) in schematic to ground and (+) to 5 volt nothing else
SkyTerror17
Oct 5 2011, 1:24 AM
Yah, I was alittle confused on that part. I did a schematic and place the components on the breadboard to test it out, still troubleshooting!

The pic below is a new schematic that I just made. I intend to have a 3.3V at the output when LDR is covered (dark) but still having some problems with the output voltage.

majoka
Oct 5 2011, 3:53 AM
@ SkyTerror17
what is the problem u just to tune some values nothing else it should work
ExperimenterUK
Oct 5 2011, 11:56 AM


I intend to have a 3.3V at the output when LDR is covered.

SkyTerror17


Your setup will be low when the LDR is covered.
Either reverse Vr1 and the LDR or reverse the inputs to the op-amp.

Why drop the output to 3.3 volts ?
R3 and R4 are the wrong way round, and I would use lower values for each.

SkyTerror17
Oct 5 2011, 12:27 PM
@majoka
Yeah, everything is almost done. I just have to tune the values of the resistor for R3 and R4 to reach the output voltage that I want!

@ExperimenterUK
Yeah, I swapped the LDR and VR1.
So does the R3 and R4, I even changed the values to 1k for R3 while 10k for R4.
Apologies as my group-mate got the concept wrongly!
We need to drop the output to 3.3V because our 8051 runs on 3.3V.
And we are gonna send a high or low input to it.
ExperimenterUK
Oct 5 2011, 3:48 PM


So does the R3 and R4, I even changed the values to 1k for R3 while 10k for R4.

SkyTerror17


10k is too high ..
1k and 1.8k would be better.
SkyTerror17
Oct 6 2011, 2:56 AM
@ExperiementerUK
Okay, thanks for the tip!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007