Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

making a simple sensor .. not working

Status
Not open for further replies.

X4ROY

Newbie level 6
Joined
Jun 4, 2010
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Bangalore
Activity points
1,416
i am using pic16f877a the aim of this program is to make a simple sensor i have an LDR light resistance around 1k ohms and dark resistance around 600k ohms .... when i cover the ldr i want there to be a low in the inpt and one particular group of leds glow and when i leave it open to light i want there to be a high at pin ra3 and the other set of leds glow ...
connections :
rb0 to rb3 pins connected led and resistor and to ground with proper polarities .
same for rb4 to rb7 pins ...
input side :
i connected 5v pin to one end of ldr the other end to ra3 pin ... it simply doesnt work i mean none of the if cases work no leds are glowing ....

code :

#include<htc.h>
#include<pic.h>
__CONFIG(HS & LVPDIS & UNPROTECT & WDTDIS);
void main(void)
{
TRISA=1x00;
TRISB=0x00;
PORTB=0b00000000;
for(;;)
{if(PORTA=0b00000000)
{PORTB = 0b11110000;)
else if (PORTA=0b00010000)
{PORTB = 0b00001111;}
}}
}

Added after 45 seconds:

hey that for loop there its an infinite for loop ... that symbol came of somehow

Added after 2 minutes:

i have no clue how to use trisa =1 i mean implement inputs ... if i put some voltage to an input port it must be high am i right ???
and if i dont put any voltage it shud be low is my understanding right ??
 

what are the meaning of these lines

if(PORTA=0b00000000)
else if (PORTA=0b00010000)

As far as i know LDR gives you the voltage at output rather than the state like 0 and 1.
So you simply read the voltage at any of the analog pin and after reading the voltage decide which leds are to glow.
for example if voltage is 0v then ON an LED 1
and if voltage is 5v then ON LED 2 and OFF LED 1.
 

Connect the LDR between ground and RA3 and connect a 10k resistor from RA3 to +5V. It will work the opposite way, ie light gives a low on RA3.
This is not the best way to connect up an LDR, better usig an npn between the LDR nd the micro.
 

Quote:
if(PORTA=0b00000000)

Quote:
else if (PORTA=0b00010000)

the first if statement is for checking if ra3 is a low and the second if else is to check if ra3 is a high ...

@colbhaidh : i tried connecting just 1k resistor to ra3 , 5v pin no use none of the led's glow none of the if cases work dunno why ???
 

With my little experiance, I would go for analog inputs for such an app ...
but if you're going for digital inputs, then I would sugest you get the code working with simple voltage inputs first (5-0 volts, no LDR), then work on your LDR sensor circuit ...
so have you configured your I/O ports in register ADCON ?
 

If you want a comparison you should use == not =

By using a single = you are making an assignment.

Keith
 

which c compiler you are using.post your schematic diagram and new code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top