Experiment with infrared proximity sensor LEDs and ATTINY

user warning: Unknown column 'i18n.language' in 'where clause' query: SELECT DISTINCT b.* FROM blocks b LEFT JOIN blocks_roles r ON b.module = r.module AND b.delta = r.delta LEFT JOIN i18n_blocks i18n ON (b.module = i18n.module AND b.delta = i18n.delta) WHERE (i18n.language ='fr' OR i18n.language ='' OR i18n.language IS NULL) AND ( b.theme = 'garland' AND b.status = 1 AND (r.rid IN (1) OR r.rid IS NULL) )ORDER BY b.region, b.weight, b.module in /var/alternc/html/o/orangeseeds/usr/drupal-6/modules/block/block.module on line 456.

In this experiment, we managed to connect infrared LEDs to the ATTINY. The other one ( infrared receptor seem like LED) is used for read rebounding object light form a infrared led, acting as a simple proximity sensor. ( 3 feets ...)

___________________________­[ Avr Code ]__________________________

/* -----------------------------------------------------------------------
* Title:    Asynchronous data transmit input (auto timing pulse detection)
* Author:   Samuel St-Aubin (samuel.st-aubin@sympatico.ca)
* Date:     15.1.2008
* Hardware: ATtiny13
* Software: WinAVR 20060421
-----------------------------------------------------------------------*/
#define F_CPU 1200000

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

#define SD_DATAIN PB0
#define LED PB4

volatile int Data ;
char timer;
int i;
int x;

int main(void) {

GIMSK = _BV (INT0);                       // int - Enable external interrupts int0
MCUCR = _BV (ISC01);                    // int - INT0 is falling edge
sei();                                               // int - Global enable interrupts

Data = 50;

DDRB &= ~(1<<SD_DATAIN);          // use PortD for input (switches)
DDRB |= (1 << LED);                       // Set direction register output

for (;;)                                            // Main loop (endless)
{

// interrupts do the job because he's cool
}

return 0;
}

ISR (INT0_vect)                                        // Interrupt on Int0 vector
{                                       

while (bit_is_set(PINB, SD_DATAIN))     // Calculated one pulse timing
{                                                            //
_delay_ms(1);                                      //
timer++;                                               //
}                                                            //

for ( x = 0 ; x < (3 * timer); x++)            // Wait 1.5 pulse ( 3 divided by 2)
{                                                             // (.5 for half pulse synchronysing)
_delay_ms(1);                                      //
x++;                                                     // double incrementation
}                                                            //

Data = 0;                                                // Initialize data register

for (i = 0 ; i < 7 ; i++)                              // For loop 0 to 7
{                                                             //
if bit_is_set(PINB,SD_DATAIN)              // Bit detector on Sd_Data input
{                                                           //
Data ^= (1<<i);                                  // Update data register (one by one bit )
}                                                           //

for ( x = 0 ; x < timer; x++)                  // One pulse time calculation
{                                                          //
_delay_ms(1);                                   //
x++;                                                  //
}                                                         //

}

timer = (timer * 10);                         // Show result of "timer" variable 
for ( x = 0 ; x < timer ; x++ )            // 0 = 10 usec, 255 = 2550 usec
{                                                       //
PORTB ^= (1 << Piezo);                  // Inverte led bit
_delay_us (10);                              //
}

}

Commentaires

infrared imitter (ver 1)

/* -----------------------------------------------------------------------
* Title: Infraled imitter
* Author: Samuel and Sofian Audry ( http://accrochages.drone.ws/ )
* Date: 25.12.2007
* Hardware: ATtiny13
* Software: WinAVR 20060421
-----------------------------------------------------------------------*/

#define F_CPU 9600000UL

#include
#include

#define LED_INFRA PB0

int i;
volatile int Data;
int counter1;

void init()
{

for (i = 0 ; i < 400 ; i ++)
{

PORTB ^= (1 << LED_INFRA);
_delay_us (13);
}

PORTB |= (1 << LED_INFRA);
_delay_ms (1);

}

void on()
{
for (i = 0 ; i < 50 ; i ++)
{

PORTB ^= (1 << LED_INFRA);
_delay_us (13);
}
}

void off ()
{
PORTB |= (1 << LED_INFRA);
_delay_ms (1);

}

void send_8bit_serial_data() // This will send data in bit 7~0, updating the clock each bit
{

unsigned char x;
int bitMask8[8] = {
0x01, // binary 00000001
0x02, // binary 00000010
0x04, // binary 00000100
0x08, // binary 00001000
0x10, // binary 00010000
0x20, // binary 00100000
0x40, // binary 01000000
0x80 // binary 10000000
};

init();

for(x = 0; x < 8; x++) // Loop through all the bits, 7...0
{
if(Data & bitMask8[x])
{
on();
}
else
{
off();
}

}
}

int main(void) {

for (;;)
{
Data = 173;

init();
send_8bit_serial_data();
_delay_ms (100);

}
return 0;

}

Led wavelength

There is several kind of infrared wavelength. The receptor must match with adapted emitter ... so we can you use 2-3 different channel at the same time... ; )

Infrared led solution..

With supply filter glitch ( capacitor between 5 volts and ground ) the range of touch distance is 2.7 feets. ..

The led is inexpensive and small...I'll try to change the kind of Led ...for + best "Watts / cm2" and wave length.

Another approach: detecting motion

The PIR325 (4 USD each) acts as a motion detector by detecting human body heat. You can combine it with a fresnel lens to increase the range (see http://www.glolab.com/pirparts/pirparts.html). As described here you can apparently build a circuit that can detect motion "in the 10's of meters". You can also detect the direction of movement.

We're getting somewhere...

Sam suggested to look for other models as well, like this one. They are pretty cheap and can detect up to 20 feet (!) We can still use the IR in/out with a higher range, for intercommunication between the agents.