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.

[SOLVED] Ir sensor interfacing problem

Status
Not open for further replies.

SHUBHAM AGIWAL

Newbie level 4
Joined
Oct 20, 2011
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,318
hey friends i am trying to interface an ir sensor wih atmega 32 which gives a ttl output such that when an obsatcle is detected it glow the led. but sadly the led glows all the time. i want it to glow only when the obstacle is detected.

here is the code

#include<avr/io.h>
#include<util/delay.h>

void main()
{
DDRA=0xf0;// PA0 is the input
// PA7 is the led pin

while(1)
{
if(PINA & 0b00000001)
{
PORTA=0x80;
_delay_ms(10);
PORTA=0x00;
_delay_ms(10);
}
}
}
 

See Bro this problem i think not is with your MCU coding what kind of IR sensor is this can you please Put the secifications of that Sensor because if it is hand made then you can modify it accordingly but if it is purchased then it is basically NC typr sensor further it is NPN or PNP this could be suggesated by the model number.......

:)

- - - Updated - - -

and one more thing please tell me y you had used that & condition in if () you can simply write
if(PINA == 0b00000001)

PORTA=0x80;
_delay_ms(10);

else
PORTA=0x00;
 
Last edited:

refer this link as it contains the ir sensor i am using
**broken link removed**


and & operator is used to check the particular bit is high or not .== is an operator is used to check the entire port input pins whether they are high or not. if any one is false then the whole condition is false.....
 

Hi SHUBHAM AGIWAL
yes i agree with Gagandeep sharma, cos in his program also work fine, and in my point of view better check with your hardware part, is it giving the 5v at the time of obstacle detects and 0v at no obstacle, with the multimeter ,and make sure with your if else statement..
 

hey avinesh

i checked my sensor. it gives 4.45v when it detects any obstacle and gives zero volts when no obstacle is detected..... and if u have opened the link then u will find out that the sensor i am using has an led attached to output to check whether it detects the obstacle or not

please do help as i am trying this for the past two days

regards
shubham agiwal
 

Hi
in your program u cant able to use like this because, If you check the header file "iom.h", you'll see that PINB0 is defined as the constant 0. So, your condition is never true.

hope this will help u.. and try to check with the below code.

Code:
# include <avr/io.h>
#include<util/delay.h>

int main (void)
{
    // set all pins on PORTB for output
    DDRB = 0xFF;

    // set port pin PORTD2 as input and leave the others pins 
    // in their originally state (inputs or outputs, it doesn't matter)
    DDRD &= ~(1 << PD2);  
      
    while (1) 
    {
        if (PIND & (1<<PD2))    
        {
            PORTB |= (1<<PB2);  
            _delay_ms(10);
         }
        else
        {           
             PORTB &= ~(1<<PB2); 
             _delay_ms(10);
         }

    }
    return 0;
}
 

why not simply direst the value o PA0 to PA7. If that value is 1 (%V), then the LED will glow else it will not glow.
Also, you are writing PA0=0x80, while you have configured only PA3 to PA7 as output. So these modifications and get back with results.
 

thanks all for ur help!!!!!!!!!! thanks avinesh for ur code... i found out that there was a hardware glitch on my board..... the problem for ir sensor interfacing is done............

regards
Shubham agiwal
 

thanks all for ur help!!!!!!!!!! thanks avinesh for ur code... i found out that there was a hardware glitch on my board..... the problem for ir sensor interfacing is done............

regards
Shubham agiwal

Any time bro and if want share some ideas or any technical work then you can mail me.
gaganfrpro@gmail.com with your EDA refrence.:p

- - - Updated - - -

thanks all for ur help!!!!!!!!!! thanks avinesh for ur code... i found out that there was a hardware glitch on my board..... the problem for ir sensor interfacing is done............

regards
Shubham agiwal

Any time bro and if want share some ideas or any technical work then you can mail me.
gaganfrpro@gmail.com with your EDA refrence.:p
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top