Transmitter
An ATTINY, using a MOSFET to drive the LED near max. capacity despite the limit on the pin, drives the LED. It uses this code to get 36kHz and send bursts as not to overload the TSOP:
// ATMEL ATTINY45 / ARDUINO // // +-\/-+ // Ain0 (D 5) PB5 1| |8 VCC // Ain3 (D 3) PB3 2| |7 PB2 (D 2) INT0 Ain1 // Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 // GND 4| |5 PB0 (D 0) pwm0 // +----+ void setup(){ DDRB |= (1<<PB0); //Set pin PB0 as output DDRB |= (1<<PB1); //Set pin PB1 as output TCNT0 = 0; TCCR0A = 0; TCCR0B = 0; TCCR0A |=(1<<COM0A0); //Timer in toggle mode Table 11-2 - PB0 TCCR0A |=(1<<COM0B0); //PB1 TCCR0A &=~(1<<COM0A1); TCCR0A &=~(1<<COM0B1); TCCR0A |=(1<<WGM01); //Start timer in CTC mode Table 11.5 TCCR0B |= (1 << CS00); //Prescaler Table 11.6 OCR0A = 12; //CTC compare value, 36kHz } void loop(){ //cycle = 1/36 = 28μs TCCR0A |=(1<<COM0A0); //burst on for 10+ cycles TCCR0A |=(1<<COM0B0); delayMicroseconds(500); TCCR0A &=~(1<<COM0A1); //off for 14+ cycles TCCR0A &=~(1<<COM0B1); delayMicroseconds(1000); } Receiver
The receiver is an active-low TSOP that, via a comparator, is connected to an Arduino calling the attachInterrupt() function. There are two LEDs and two receivers to determine direction. The C code calculates direction and spits out the result.
