The present PROJECT describes a design and implementation of an infrared (IR) remote controlled RoboCar which can be used for various automated unmanned control applications. I have designed remote controlled RoboCar(left-right/front-back motion). The entire system is based on microcontroller (Atmega32) that makes the control system smarter and easy to modify for other applications. It enables the user to operate or control a RoboCar and operate the mains power switch from about 5 meters away.

Key words: IR Decoder, AVR (Atmega32) Microcontroller, TV remote Controller, Wireless communication

__________________________________________________________________________

## Step 1: ​IR Communication & Applications

IR Communication principle:

a) IR transmission

The transmitter of an IR LED inside its circuit, which emits infrared light for every electric pulse given to it. This pulse is generated as a button on the remote is pressed, thus completing the circuit, providing bias to the LED. o The LED on being biased emits light of the wavelength of 940nm as a series of pulses, corresponding to the button pressed. However since along with the IR LED many other sources of infrared light such as us human beings, light bulbs, sun, etc, the transmitted information can be interfered. A solution to this problem is by modulation. The transmitted signal is modulated using a carrier frequency of 38 KHz (or any other frequency between 36 to 46 KHz). The IR LED is made to oscillate at this frequency for the time duration of the pulse. The information or the light signals are pulse width modulated and are contained in the 38 KHz frequency. Infrared transmission refers to energy in the region of the electromagnetic radiation spectrum at wavelengths longer than those of visible light, but shorter than those of radio waves. Correspondingly, infrared frequencies are higher than those of microwaves, but lower than those of visible light. Scientists divide the infrared radiation (IR) spectrum into three regions. The wavelengths are specified in microns (symbolized µ, where 1 µ = 10-6 meter) or in nanometers (abbreviated nm, where 1 nm = 10-9 meter = 0.001 5). The near IR band contains energy in the range of wavelengths closest to the visible, from approximately 0.750 to 1.300 5 (750 to 1300 nm). The intermediate IR band (also called the middle IR band) consists of energy in the range 1.300 to 3.000 5 (1300 to 3000 nm). The far IR band extends from 2.000 to 14.000 5 (3000 nm to 1.4000 x 104nm).

b) IR Reception

The receiver consists of a photo detector which develops an output electrical signal as light is incident on it. The output of the detector is filtered using a narrow band filter that discards all the frequencies below or above the carrier frequency (38 KHz in this case). The filtered output is then given to the suitable device like a Microcontroller or a Microprocessor which controls devices like a PC or a Robot. The output from the filters can also be connected to the Oscilloscope to read the pulses.

Applications of IR:

Infrared is used in a variety of wireless communications, monitoring, and control applications. Here are some examples:

· Home-entertainment remote-control boxes

· Wireless (local area networks)

· Links between notebook computers and desktop computers

· Cordless modem

· Intrusion detectors

· Motion detectors

· Fire sensors

· Night-vision systems

· Medical diagnostic equipment

· Missile guidance systems

· Geological monitoring devices

Transmitting IR data from one device to another is sometimes referred to as beaming.

## Step 2: IR Communication Via TSOP1738 Sensor

IR sensor

• TSOP1738, SFH-5110-38 (38kHz)

TSOP sensors Features:

• The preamplifier and photo detector both are in single package
• Internal filter for PCM frequency
• Improved shielding against electrical field disturbance
• TTL and CMOS compatibility
• Output active low Low power consumption
• High immunity against ambient light
• Continuous data transmission possible

NEC Protocol:

The NEC IR transmission protocol uses pulse distance encoding of the message bits. Each pulse burst (mark – RC transmitter ON) is 562.5µs in length, at a carrier frequency of 38kHz (26.3µs). Logical bits are transmitted as follows:

• Logical '0' – a 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
• Logical '1' – a 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms

When transmitting or receiving remote control codes using the NEC IR transmission protocol, the WB_IRRC performs optimally when the carrier frequency (used for modulation/demodulation) is set to 38.222kHz.

The four bytes of data bits are each sent least significant bit first. Figure 1 illustrates the format of an NEC IR transmission frame, for an address of 00h(00000000b) and a command of ADh (10101101b).

Understanding the Power Functions IR Protocol:
I started to decypher the Power-Functions infrared protocol by measuring the signals that the IR detector picked up from the remote control. The detector that I used (Radio Shack 276-640) detects infrared signals modulated at 38KHz with light wavelength 940±50nm; but these detectors tend to detect most infrared remote-control signals, even if the modulation frequency is a bit different. The diagram below shows the signals that I measured when I pressed the red button in the forward direction when the remote was set to channel one. Each line represent a burst of signals, with time going from left to write. Each black rectangle represents one detection, and the width of the rectangle represent the length of time the signal was detected. The horizontal distance between rectangle represents the length of time between detections. After each burst of 18 detections, the detector did not detect anything for a fairly long period, and then detected another burst. Each burst is represented in the diagram by a row of rectangle.

Fig2

These measurements allowed me to determine the representation of commands in the protocol. The transmissions consist of signal periods of roughly the same length separated by no-signal periods of varying lengths. The first no-signal period is always the the same length and much longer than all the others. This appears to be some sort of a start-condition indication that does not convey any information (apart from allowing the received to distinguish between this protocol and others). Following that, each short period represents a zero bit and each long one represents a one bit. It could also have been the other way around, but the full analysis of the bit sequences, described bellow, supports this hypotheses. Altogether there are 16 bits in each burst.
I generated histograms of the four relevant periods of this protocol: the signal period, the initial no-signal period in each burst, and the short and long no-signal periods representing bits. I estimate the average signal period to be about 60 clock ticks (), the initial no-signal period to be about 215 ticks, the zero no-signal to be 40, and the one no-signal to be about 110. Before moving on to the actual meaning of the bits, I wanted to know how the bursts are spaced. Here is a another sequence of detections, already translated into zeros and ones. After each burst the program printed the length of time from the end of the previous burst. This sequence represents a longer press of the same key.1000000100010111 130537 1000000100010111 14976 1000000100010111 14839 1000000100010111 23711 1000000100010111 23709 1000000100010111 23786 0000000100001110 29087 0000000100001110 14852 0000000100001110 14923 0000000100001110 23689 0000000100001110 23694We can see that the remote sends repeatedly the same command. The first 6 commands tell the receiver that a particular button is pressed, and the last 5 tell the receiver that buttons are no longer pressed. Each sequence starts with 3 repetitions about 14,900 counter ticks apart. After that, repetitions are spaced further apart. The first repetitions may be spaced closely to allow the receiver to quickly respond even if the first transmissions are lost or corrupt. The wider spaceing after that may be designed to reduce power consumption by the transmitter. Now let's examine the bit sequences that the transmitter sends. There are four buttons no the remote, and when you release them, the remote sends a "no button pressed" command for a short while. Here are the single-press and no-press command sequences for the 4 channels. I split the bits into groups that seem to represent different fields; see below for what the fields appear to mean. channel 1 red forward 1 0 00 0001 0001 011 1 channel 1 red reverse 1 0 00 0001 0010 010 0 channel 1 blue forward 1 0 00 0001 0100 001 0 channel 1 blue reverse 1 0 00 0001 1000 111 0 channel 1 no buttons 0 0 00 0001 0000 111 0

channel 2 red forward 1 0 01 0001 0001 011 0 channel 2 red reverse 1 0 01 0001 0010 010 1 channel 2 blue forward 1 0 01 0001 0100 001 1 channel 2 blue reverse 1 0 01 0001 1000 111 1 channel 2 no buttons 0 0 01 0001 0000 111 1

channel 3 red forward 1 0 10 0001 0001 010 1 channel 3 red reverse 1 0 10 0001 0010 011 0 channel 3 blue forward 1 0 10 0001 0100 000 0 channel 3 blue reverse 1 0 10 0001 1000 110 0 channel 3 no buttons 0 0 10 0001 0000 110 0

channel 4 red forward 1 0 11 0001 0001 010 0 channel 4 red reverse 1 0 11 0001 0010 011 1 channel 4 blue forward 1 0 11 0001 0100 000 1 channel 4 blue reverse 1 0 11 0001 1000 110 1 channel 4 no buttons 0 0 11 0001 0000 110 1

## Step 3: DC Motor Control Using L293D

DC Motor

A DC-motor converts electrical energy into mechanical energy that can be used to do many useful works. It can produce mechanical movement like Go Forward/Backword of my RoboCar. DC motors comes in various ratings like 6V and 12V. It has two wires or pins. We can reverse the direction of rotation by reversing the polarity of input.

Here we prefer L293D as a rating of 600mA is good for driving small DC motors and protection diodes are included in the IC itself. The description of each pin is as follows:
Enable pins: These are pin no. 1 and pin no. 9. Pin no. 1 is used to enable Half-H driver 1 and 2.( H bridge on Left side). Pin no. 9 is used to enable H-bridge driver 3and 4.(H bridge on right side). The concept is simple, if you want to use a particular H bridge you have to give a high logic to corresponding enable pins along with the power supply to the IC. This pin can also be used to control speed of the motor using PWM technique.VCC1 (Pin 16): Power supply pin. Connect it to 5V supply.VCC2 (Pin 8): Power supply for motor. Apply +ve voltage to it as per motor rating. If you want to drive your motor at 12V, apply 12V on this pin. It is also possible to drive motor directly on a battery, other than the one used for supplying power to the circuit, Just connect +ve terminal of that battery to VCC2 pin and make GND of both the batteries common. (MAX voltage at this pin is 36V as per its datasheet).GND (Pins 4,5,12,13): Connect them to common GND of circuit.Inputs (Pins 2,7,10,15): These are input pins through which control signals are given by microcontrollers or other circuits/ICs. For example, if on pin 2 (Input of 1st half H driver) we give Logic 1 ( 5V), we will get a voltage equal to VCC2 on corresponding output pin of 1st half H driver i.e pin no. 3. Similarly for Logic 0 (0V) on Pin 2, 0V on Pin 3 appears.Outputs ( Pin 3,6,11,14): Outputs pins. According to input signal output signal comes.

Motor Movements A B

-------------------------------------------------------------------------------------------

Stop Low Low

Clockwise Low High

Anticlockwise High Low

Stop High High

## Step 4: Circuit Diagrams for Motor Driver and IR Sensor

The ATmega32 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC
architecture. By executing powerful instructions in a single clock cycle, the ATmega32 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.

The AVR core combines a rich instruction set with 32 general purpose working registers. All the
32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. The ATmega32 provides the following features: 32 Kbytes of In-System Programmable Flash Program memory with Read-While-Write capabilities, 1024 bytes EEPROM, 2K byte SRAM, 32 general purpose I/O lines, 32 general purpose working registers, a JTAG interface for Boundaryscan, On-chip Debugging support and programming, three flexible Timer/Counters with compare modes, Internal and External Interrupts, a serial programmable USART, a byte oriented Two-wire Serial Interface, an 8-channel, 10-bit ADC with optional differential input stage with programmable gain (TQFP package only), a programmable Watchdog Timer with Internal Oscillator, an SPI serial port, and six software selectable power saving modes. The Idle mode stops the CPU while allowing the USART, Two-wire interface, A/D Converter, SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning. The Power-down mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next External Interrupt or Hardware Reset. In Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except Asynchronous Timer and ADC, to minimize switching noise during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while the rest of the device is sleeping. This allows very fast start-up combined with low-power consumption. In Extended Standby mode, both the main Oscillator and the Asynchronous Timer continue to run.

All related circuits are give here and main circuit(atmega32) is also given.

## Step 5: Avr Programs

1. remote sensor:

#include
#include

#include "remote.h"

//Globals volatile unsigned int Time; //Main timer, stores time in 10us, //Updated by ISR(TIMER0_COMP) volatile unsigned char BitNo; //Pos of next BIT volatile unsigned char ByteNo; //Pos of current Byte

volatile unsigned char IrData[4]; //The four data Bytes of Ir Packet //2-Byte Address 2-Byte Data volatile unsigned char IrCmdQ[QMAX];//Final Command Received (Buffer)

volatile unsigned char PrevCmd; //Used for repeat

//Variables used for start repeating only after a key is pressed for certain time

volatile unsigned char Repeat; //1=yes 0=no volatile unsigned char RCount; //Repeat count

volatile char QFront=-1,QEnd=-1;

volatile unsigned char State; //State of receiver

volatile unsigned char Edge; //Edge of interrupt [ RISING=1 OR FALLING=0 ]

volatile unsigned int stop;

/**********************************************************************************************/ /* F U N C T I O N S S T A R T S */ /**********************************************************************************************/

void RemoteInit() {

char i; for(i=0;i<4;i++) IrData[i]=0;

//Setup Timer1 //------------ TCCR0|=((1<

TIMSK|=(1<

OCR0=TIMER_COMP_VAL; //Set Compare Value

unsigned char GetRemoteCmd(char wait) { unsigned char cmd;

if(wait) while(QFront==-1); else if(QFront==-1) return (RC_NONE);

cmd=IrCmdQ[QFront];

if(QFront==QEnd) QFront=QEnd=-1; else { if(QFront==(QMAX-1)) QFront=0; else QFront++; }

return cmd;

}

2. main():

int main(void)
{

uint8_t cmd=0; DDRB=0x08;

DDRD=0x80;

DDRC=0x0f; PORTC=0x00;

while (1) //Infinite Loop to active IR-sensor {

cmd=GetRemoteCmd(1);

switch(cmd) {

case xx: { //BOT Moves forward //Ch+ btn forwardmotor();

break; // Both Motors in Forward Direction

}

..........................................................

..........................................................

..........................................................

default: PORTC=0x00;break; // Both left and right motors halt }

}

}/*End of main*/

....................................................................................................................................

// It a basic model, but I can use it in PWM mode......cheers!!!!!

/*#############Rudra Narayan PAUL##############################

M. TECH (COMPUTER SCIENCE ENGG.), BPUT, ODISHA,

####################################################*/

<p>Sir,How much the baud rate value must be ? </p>
Baud rate refers to the number of signal or symbol changes that occur per second. A symbol is one of several voltage, frequency, or phase changes.<br>NEC have a format of bits. Change baud rate is change in CPU speed and timer speed that will scale overall transmission/reception speed in sync. So, go through code and change those values.....
<p>Awesome guide sir ;) , Need a little detail on pin connection for IR sensor</p>
<p>Circuit diagram is perfect, Tsop1738 {Vout----&gt;PD2(atmega32), Vcc-----&gt;5v anywhere in circuit } and for dc-motor you can use port A, B, C or D no problem; just check pin voltages after burning program or use led for each pin that can blink when sensor receive some signal from TV-Remote. Cool........</p>
<p>Thanks a lot, Finally able to get input properly.</p>
<p>Thanks for visit...</p>
<p>Very cool project. Thank you for sharing!</p>