Discussion in "8051 Discussion Forum" started by    SkyTerror17    Sep 26, 2011.
Mon Sep 26 2011, 12:21 pm
#1
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!



[ Edited Mon Sep 26 2011, 12:25 pm ]
Mon Sep 26 2011, 01:26 pm
#2
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;
}
}
}
Mon Sep 26 2011, 09:02 pm
#3
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!
Sun Oct 02 2011, 06:05 pm
#4
We are waiting for update..
Tue Oct 04 2011, 08:18 am
#5
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.


[ Edited Tue Oct 04 2011, 08:40 am ]
Tue Oct 04 2011, 10:53 am
#6
@ SkyTerror17
u can use op amp LM741 as a comparator
Tue Oct 04 2011, 12:05 pm
#7
Alright, am trying it now. But judging from my current schematic, I need to replace the LM741 with the 2N3904 transistor?
Tue Oct 04 2011, 12:13 pm
#8
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
Tue Oct 04 2011, 01:00 pm
#9
Is there any single supply op amp that you guys could recommend?
Tue Oct 04 2011, 01:02 pm
#10
u can use LDR as
http://www.matni.com/Arabic/Elec-Info/LIGHT%20SWITCH/sensor2.htm
it is better way of using LDR

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ArnoldDiant
Fri Apr 26 2024, 03:53 am
RodneyKnorb
Thu Apr 25 2024, 07:08 pm
Williamjef
Thu Apr 25 2024, 02:08 pm
SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm