go_away

Author Topic: IR led/phototransistor usage  (Read 5130 times)

0 Members and 1 Guest are viewing this topic.

Offline izuaTopic starter

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
IR led/phototransistor usage
« on: May 13, 2008, 09:16:22 AM »
Hi!
I've bought a bunch of phototransistors and IR leds for usage on my soon-to-be robot.
I want to make a bunch of sensors, as the ones used for edge detection, line following, obstacle avoidanance, you know the idea. My question is, how exactly is this reading done?
Take for example, module a and b. module a has the power for the led and power for the phototransistor. module b has power in parallel for both of them. So, the first module uses 4 wires, while the second one uses only 3.
But the first module can take a reading with custom illumination, and without it.
Is it worth this extra wire? Of course, software for noise cancelling should be written, but is it actually any good by itself?

Thanks

edit: whoops, wrong picture
« Last Edit: May 13, 2008, 09:22:37 AM by izua »
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline AndrewM

  • Robot Overlord
  • ****
  • Posts: 255
  • Helpful? 0
Re: IR led/phototransistor usage
« Reply #1 on: May 13, 2008, 09:36:26 AM »
With four wire setup you have the following: 1) pulse signal to IR Led 2) ground from IR Led 3) power to phototransistor 4) signal from phototransistor.  What this allows for is to send certain frequencies to an IR Led for your light output, usually in the 48KHz range (I would have to look to be sure).  By using this pulse signal your phototransistor (which is atuned by the manufacturer for this range) will respond to that particular signal, as opposed to just any old light that hits it.  This gives you better accuracy in a lit enviroment, and is usually used for range finding and obstacle avoidance.  But your phototransistor has to be of a type that is tuned to a certain frequency to do this.

Under three wire you have the following:  1) Power to IR Led (always on) and phototransistor 2) Ground from IR Led 3) signal from phototransistor.  Because your IR Led is always on, if the light reflects off something your phototransistor will always be on (in some state).  This setup is good for line following and edge detection as you are only looking for when there is a signal, or there isn't, and is usually facing downward out of any external light sources.

Hope that makes sense.
blog: www.iamwhen.com
Saving the world from humanity one robot at a time.

Offline Steel_monkey

  • Full Member
  • ***
  • Posts: 85
  • Helpful? 0
Re: IR led/phototransistor usage
« Reply #2 on: May 13, 2008, 03:23:50 PM »
I've bought a bunch of phototransistors and IR leds ...

Is these pre-buid modules, or just some type of schematic you are trying to use discrete parts in?
If they are pre-build, is there anything else rather than phototransistor in first module? If it has receiving circuit , as AndrewM said, prefer it. Otherwise, you can use light modulation yourself. Some info about "light navigation" http://www.societyofrobots.com/member_tutorials/node/102

Offline izuaTopic starter

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: IR led/phototransistor usage
« Reply #3 on: May 13, 2008, 11:39:17 PM »
No, they are bare leds and phototransistors, no module. No, I am not talking about modulation, but sampling with the led on and off. Although, modulation is the same thing, but at very high speed.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline Steel_monkey

  • Full Member
  • ***
  • Posts: 85
  • Helpful? 0
Re: IR led/phototransistor usage
« Reply #4 on: May 14, 2008, 02:15:42 PM »
So, only first option is really useful. For ON/OFF it might be necessary to use transistor for switching depending of IR LED current and efficiency. Use PNP with emitter connected to VCC and drive it with MCU pin. Perhaps, direct MCU pin without transistor will work too.
Also you need ADC to sample results during ON and OFF and subtract it in MCU. I saw such a device, and it worked very well, detecting distance to obstacle at close range (resolution was modest, but it worked! ).
In modulation method another technology is used. Signal from phototransistor, modulated most commonly with 40 KHz, is processed in analog filter, amplifier and comparator to get digital result. In this method, distance measurement i not so straightforward.    

Offline izuaTopic starter

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: IR led/phototransistor usage
« Reply #5 on: May 15, 2008, 05:29:35 AM »
I do not want modulation, and an AVR has sufficient current per pin (40mA) to command a led.
Sampling with on and off is what i'm looking for - and then interpreting the difference - does it give any good results? anyone has any links?
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline Steel_monkey

  • Full Member
  • ***
  • Posts: 85
  • Helpful? 0
Re: IR led/phototransistor usage
« Reply #6 on: May 15, 2008, 01:58:12 PM »
For example, ARM has only 4 mA per pin ;)
In this schematic, LED is told to draw 50 mA, so MOSFET is strict.

CodeVisionAVR code
Code: [Select]
/*

Chip type           : ATmega8
Program type        : Application
Clock frequency     : 8,000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
 */

#include <mega8.h>
#include <delay.h>
#define ADC_VREF_TYPE 0x40




bit ADC_complete;
int gADC_result;

interrupt [ADC_INT] void adc_isr(void)
{
unsigned int adc_data;
adc_data=ADCW;
gADC_result=adc_data;
ADC_complete=1;
}


int poll_sensor(void){ 
int delta;
PORTB.0=1;        
delay_ms(1);
ADCSRA|=0x40;
while(ADC_complete!=1);
delta=gADC_result;
ADC_complete=0;

PORTB.0=0;
delay_ms(1);
ADCSRA|=0x40;
while(ADC_complete!=1);
delta=gADC_result-delta;
ADC_complete=0;
return delta;
}

void main(void)
{
int razn;

PORTB=0x00;
DDRB=0xFF;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0xFF;
TCCR0=0x00;
TCNT0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
TIMSK=0x00;
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 1000,000 kHz
// ADC Voltage Reference: AVCC pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x8B;

// Global enable interrupts
#asm("sei")

while (1)
      {
      razn=poll_sensor();
// for exmple, turn different LEDs on portD depending of obstacle distance 

      if(razn >10)  PORTD.0=1;
      if(razn >20) PORTD.1=1;
      if(razn >30) PORTD.2=1;
      if(razn >40) PORTD.3=1;
      if(razn >50) PORTD.4=1;
      if(razn >60) PORTD.5=1;
      if(razn >70) PORTD.6=1;
      if(razn >80) PORTD.7=1;
      delay_ms(1);
      PORTD=0;
      };
}
Small video http://licrym.org/images/wiki/irbump.avi
Taken from  licrym.org.

« Last Edit: May 15, 2008, 01:59:54 PM by Steel_monkey »

Offline izuaTopic starter

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: IR led/phototransistor usage
« Reply #7 on: May 15, 2008, 03:00:35 PM »
Hmm, these ARM thingies are cool.
Are they controllers or processors? How reliable are they, compared to an atmega?
Can you develop for them using only hobby tools? (IE make programmer at home)
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline paulstreats

  • Supreme Robot
  • *****
  • Posts: 1,381
  • Helpful? 21
Re: IR led/phototransistor usage
« Reply #8 on: May 15, 2008, 04:56:39 PM »
ARM's are mcu's

The only ARM's that i have worked with have been surface mount, so obviously very tricky to work with physicallly. Most ARM's that I worked with have a direct serial programming interface or a JTAG interface for programming, Im imagining that you would be better off looking for a well designed development board.

ARM's are able to run a lot faster than the low end mcu's (such as pic and atmega) and luckily the c compilers are usually free, Its a great next step to take but make sure that you are comfortable with using a selection of low end mcu's first and work up gradually otherwise there is going to be too much to take in. I believe that a lot of the high end ATMEL controllers are built on ARM's ?? as well as other companies standard controllers such as Analog Devices. The good thing about ARM controllers is that a lot of differewnt companies make their own version of ARM controllers, but you usually only need one C compiler and 1 programming interface and they work with them all (rather thn having a specific c compiler for each brand of mcu).

Personlly having worked with ARM controllers, they are easy to use as long as you know how controllers work but the problem at the hobby level is trying to solder tbe fine lead pitch. I would love to be able to use ARM controllers in my personal / hobby time but i just dont have the equipment at the mo

Offline Steel_monkey

  • Full Member
  • ***
  • Posts: 85
  • Helpful? 0
Re: IR led/phototransistor usage
« Reply #9 on: May 15, 2008, 05:23:35 PM »
ARM 7 is much closer to MCU than MPU. However they require "many" initial parts to turn on (3.3 Volts, 1.8 Volts, external Brown-out ...). Also, they need tight PCB, only TQFP (and BGA ... micron) packages are available. They have good peripheral: 1-3 UARTs, 2-4 SPIs, 2 and more I2C and others, but suffer from unpredictable interrupt-entering time. There is free C compiler for them - WinARM ( in style of WinAVR), JTAG can be home-made if you have LPT ( it contains only 74x244 buffer and transistor). NXP LPC can be programmed via UART with some black magic (3 Volts), Atmel AT91 can be  programmed even directly from USB. JTAG can help with program debugging - it works like ICE, and you can step code on powered device.
But I don't really think they are the must. I have made PCB and programmer, but really don't need something more powerful than ATmega. You need to have good embedder skills to deal with ARMs. They are harder to understand and code ( Von'Neumann architecture). If you really need them, you will understand it same time  ;D
paulstreats was a little faster  :D
« Last Edit: May 15, 2008, 05:26:28 PM by Steel_monkey »

 


Get Your Ad Here

data_list