Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Help with using TSOP1738 for line sensing using ATMEGA16

  1. #11
    Junior Member Newbie
    Join Date
    Nov 2004
    Location
    bhopal, india
    Posts
    6

    Default Re: Help with using TSOP1738 for line sensing using ATMEGA16

    {The LED is glowing but I dont have any device to confirm whether the produced frequency in correct or not.}

    i wonder!! if your digital multimeter has no frequency measurement option,
    if it is there ,put the probes in series with with LED,
    I did the same (measuring output frequency & adjusting the POT.),while generating 38kHz using IC555 .[/u]

  2. #12

    Default

    Well to check whether your TSOP is working the best and the simplest way is to check it using your tv remote control ( Not Sony as they work on other frequency ). Steps to check.
    1.TSOP is getting appropriate voltage ( +5v and GND ) on proper pin.
    2.Point remote on TSOP keep pressed a buutton on remote.
    3.Check voltage at output if it drops Voila.


    There are many different TSOP available 1738 means it works on 38 freq 1739 , 1740 etc etc so do check you have the right one.

  3. #13

    Talking Here you go . easy as pie.

    Use a photo-transistor and a set of bright white LEDS?
    only drawback would be ambient light. either put you array under the bot and mask the front, or use a color filter and colored LEDs


    /*
    Author : Jithinbp AT GMAIL.COM
    Free and open code.. if you couldn't code this on your own,
    I do believe you deserve a peek for free.

    MOTOR control port is D
    Right Motor : 1 forward, 2 backward
    Left Motor : 4 forward, 8 backward

    Photo sensor:
    left = ADC 5
    mid = ADC 4
    right = ADC 3
    */

    #include <inttypes.h>
    #include <avr/io.h>


    #define RM 100 // 40
    #define MM 100 // 51
    #define LM 150 // 127

    typedef uint8_t u8;

    void
    delay(y)
    {
    volatile uint16_t x = y;
    while(x--) ;
    }


    u8 adval(u8 ch)
    {
    ADMUX = BV(ADLAR) | ch;
    ADCSRA = BV(ADEN) | BV(ADSC) | 7; // Low clock speed
    while ( !(ADCSRA & (1<<ADIF)) ) ; // wait for ADC conversion
    ADCSRA |= BV(ADIF);
    return ADCH;
    }

    void fwd()
    {
    u8 x;
    PORTD=5;
    for(x=0;adval(4) > MM && x < 10;x++)
    delay(500);
    PORTD = 10;
    delay(50);
    PORTD=0;
    }

    void sharpright()
    {
    u8 x;
    PORTD = 6;
    for(x=0;adval(3) > RM && x < 10;x++)
    delay(50);
    PORTD = 0;
    }

    void sharpleft()
    {
    PORTD = 9;
    u8 x;
    for(x=0;adval(5) > LM && x < 10;x++)
    delay(50);
    PORTD = 0;
    }

    void right()
    {
    PORTD = 4;
    delay(500);
    PORTD = 0;
    }

    void left()
    {
    PORTD = 1;
    delay(500);
    PORTD = 0;
    }


    void reverse()
    {
    right();
    left();
    PORTD=10;
    delay(5000);
    PORTD=0;

    }
    int main (void)
    {
    u8 lt, mid, rt,started=0,turn=0,x=0;

    DDRB = 0; // configure portB as in
    DDRC = 0;
    DDRD = 255; // PORTD 3 LSBs are outputs


    ADCSRA = BV(ADEN);

    for(;
    {
    lt = adval(5);
    mid = adval(4);
    rt = adval(3);

    if(lt >LM && rt > RM && mid > MM) //on total black surface
    {
    if(turn==1)
    sharpleft();
    else if(turn==2)
    sharpright();
    else
    continue;

    x++;
    if(x==3)x=0,turn=0;

    }


    if(lt < LM && rt < RM && mid < MM) //on total white surface
    {
    if(started==0)
    continue;
    }
    if(lt > LM && rt >RM && mid < MM)
    sharpleft(); //fork in the track -> take the left one . add a forward step maybe

    else
    if( lt > LM && mid > MM) //left realignment
    left(),x=0,turn=0;
    else
    if( rt > RM && mid >MM) //right realignment
    right(),x=0,turn=0;


    else
    if( lt > LM && mid < MM)
    {
    sharpleft();
    turn=1;
    } //sharp left bend
    else
    if( rt > RM && mid < MM) //sharp right bend
    {
    sharpright();
    turn=2;
    }


    else
    if( mid > MM )
    {
    fwd(); //move forward

    started=1; //record that bot has started
    }




    }
    return 0;
    }

  4. #14
    Senior Member T-1000
    Join Date
    Jun 2007
    Location
    Jamshedpur/Bhubaneswar
    Posts
    421

    Default

    TSOP wont work for LFR. It is too sensitive and difficult to adjust at that height.
    To confirm this fact.

    Pick up a remote control of your TV, a black paper, a white paper.

    Fire the remote on black paper such that the paper reflects the IR Radiation to the sensor of TV (Note the result, i.e if TV responds or NOT)

    Replace black paper with white paper and repeat the experiment.

    The result is that TV Responds in all cases. This proves the above fact.

    Now how your friend made that stuff. The thing is becasue your friend used NE555, whose frequency is adjusted by a variable resistor. So your friend adjusted it for optimal results of Line detection. The fact to be noted at that point the NE555 is NOT at- all producing 38KHz it must be gererating something like 32 or 42KHz. Since TSOP looses its sensitivity when the frequency deviates from 38KHz.

    If you use MCU to generate perfect 38KHz TSOP will become TOO sensitive for Line detection purpose. It can bounce upto 3 or 4 times traveling up-to 40 feets and reach IR sensor from any side and trigger it.

    Long back I read on RI how to use TSOP to make a very cheap IR rangefinder. I made that using AVR.

    Code:
    #include <avr/io.h>
    #include <util/delay.h>
    
    #include "lcd.h"
    
    void delay()
    {
    	char i;
    	for(i=0;i<6;i++)
    	_delay_loop_2(0);
    }
    void SetFrequency(long fq)
    {
    	
    	OCR1A=(F_CPU/(2*fq));
    }
    void DrawBar(uint8_t n)
    {
    	LCDGotoXY(0,1);
    	uint8_t i;
    	for(i=0;i<n;i++) 
    	{
    		LCDData('*');
    	}
    }
    void main()
    {
    	uint16_t i;
    	uint8_t range,out_of_range,r1,r2;
    	TCCR1A|=(1<<COM1A0);			//Toggle OC1A on compare match
    	TCCR1B|=(1<<WGM12)|(1<<CS10);	//CRC Mode Prescalar=1
    
    	DDRB|=(1<<PB1);					//Set OC1A Pin as output
    
    
    	InitLCD(LS_BLINK|LS_ULINE);
    	while(1)
    	{
    		for(i=44000,range=1,out_of_range=1;i<57000;i+=1000,range++)
    		{
    			SetFrequency(i);
    			_delay_ms(1);
    			r1=(PINB & 0b00000001);
    			_delay_ms(1);
    			r2=(PINB & 0b00000001);
    			if((!r1) & (!r2))
    			{
    				out_of_range=0;
    				break;
    			}
    		}
    		LCDClear();
    		LCDWriteString("Distance - ");
    		if(!out_of_range)
    		{
    		LCDWriteIntXY(14,0,range,2);
    		DrawBar(range);
    		}
    		else
    		{
    		LCDWriteStringXY(14,0,"XX");
    		LCDWriteStringXY(0,1,"Out of Range");
    		}
    		delay();		
    
    
    	}
    	
    	
    }
    The target is ATmega8 @ 12MHz
    Attached Files Attached Files
    Last edited by avinash_g; 06-19-2011 at 08:52 AM.
    Avinash Gupta
    ************
    www.eXtremeElectronics.co.in

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •