Friday, January 9, 2009

IR Remote Controlled Car (PWM motor control using ATmega8)

Hi Friends,
in my last post of Simple DC motor Control, I've discussed controlling a small DC motor using the PWM method with MOSFET H-bridge. The circuit was build with microcontroller ATmega8.
Here, I'm extending the same circuit to control the DC motor with IR remote control. The motor is fitted on a toy car wheels with gears, as shown in the figure above.

Following is the schematic (Click on the image to enlarge it):

The circuit uses two PWM channels of ATmega8 for controlling the speed and direction (reverse, forward) of the car, based on the command received from the IR remote. Here, a Sony TV remote was used. The IR codes were received by using TSOP1738 IR detector from Vishay. (Thanks a lot to Michael Spiceland from tinkerish.com, for helping me out with the code for IR signal decoding!).

Following buttons on the remote are used for control:
'1' : Start motor
Volume+ : Increase speed
Volume-: Reduce speed
Channel+: Forward direction
Channel-: Reverse Direction
'0': Stop motor

Check out the video (the LED blinks whenevr a key on the remote is pressed. The remote is not visible in the video as I was holding the camera and remote both!!)

The coding is done with ICCAVR compiler. It can be easily adapted to other compilers with minor changes. Complete code is given here:

View Code on Google Docs
Download source code files (zip)

Updated Design (done sometime in 2010, added here in 2018):
       As brought out by many in comments, above design is not power efficient, as it uses n-type MOSFETS in upper and lower, both the sides of the H-bridge. So here is the modified design of a Three-wheeled dual DC motor robot (with speed, direction and turning controls), using  the popular L293D motor driver IC, which is very easy to control and size and power efficient, providing two full-bridge circuits in one IC, each having 1A capacity to drive a DC motor.


       Following is the circuit schematic:


     This one is ATmega32 based, IR remote controlled (using TSOP1738 IR detector) with two optical detectors (MOC7811) provision to detect the robot speed. Two detectors can be used to implement a control algorithm, like PID, if required (here only one detector is used, just to display the speed). A slotted wheel is used, mounted on the motor shaft, to work with the optical detector. The wheel slots pass through the detector, generating pulses while robot is moving. The pulses are counted for speed detection.
    It has a 16x2 LCD with 4-bit interface to display the speed and current status of the robot (based on the IR input received). It has a reset button and two user buttons. There is also hardware provision for RS232 driver on-board, for adding any further functionality, like adding user configuration in EEPROM via serial port, without changing the code.
    The design runs on a 9-12V DC supply. A commonly available 9V higher density battery can be used while running the robot. When powered NO, the circuit waits in ready state (with Green LED ON) till the button1 is pressed, after which it starts accepting the IR remote commands, and acts as per the commands (with Red LED ON). Following pictures show some of the functional states.


Here are the IR remote commands used for  robot control:

    Remote Button (IR code) -   Robo Action
    ----------------------------------------    ---------------
  • START/STOP         (21)         Start/Stop
  • VOLUME+            (18)         Increase Speed
  • VOLUME-              (19)         Decrease Speed
  • UP                        (116)        Go Forward
  • Down                    (117)        Go Backward
  • LEFT                     (52)         Turn Left
  • RIGHT                   (51)         Turn Right
  • CENTER               (101)         Pivot Turn

Following are the optical encoder slotted disc, optical encoder and the IR Remote receiver:


        Download source-code files (zip)

         Datasheets & further info:
         TSOP1738 datasheet
         Encoder Slotted Disc

Thanks & Regards,


Michael said...

Do you have a video of it in action?

CC Dharmani said...

I just put it up! check it out.

Arvind Gupta said...


Did u find a Sony RC encoded remote in India? Coz most of common remotes I came across were NEC format encoded. So I made AVR Interface to them you can check it out here.


CC Dharmani said...

Hi Arvind,
I've got a Sony TV remote, so I got the codes online for it and tried the code and it worked. So,I think you can get it easily in India. I've not tried other remotes yet, but shortly I'll test them with same code and post the results here.

Thanks for that link, it'll be really useful for many beginners!

Hari Haran.C said...

I have doubt in the H-Bridge operation, in your circuit you have connected Q1 and Q4 then Q3 and Q2

and it is very clear for me you are operating High side Cross Low side to operate the Motor, but can you clarify me on the following design where a bridge driver is used and with different configuration


Hari Haran.C

Anonymous said...

Hello sir i just wanted to know whether u can just mail me the hex file of this project..... Please depending on u only coz i cant generate hex file... Email: Prashanth_eng@yahoo.com

Mario Marchese said...

great project! very cool blog

abhilash said...

thanks for such an interesting project... can u plz let me know what is the total cost of the project....

gonio said...

i used diferent sony remote but not worked please tell which Sony TV remote you r used
please give remote or TV modle no.

CC Dharmani said...

the Sony TV remote which I used here is: RM-GA002
It is for Sony Triniton TV.

Sunil said...

while going through comments I came to knoe that you hve used same dc motor control ckt for RC car too.But voltage supply is not same in case of motor you r giving 9 v across mosfet.Can it be done with same ckt.

CC Dharmani said...

Yes, you can use the same circuit to drive the motor from VCC, if your motor doesn't need higher power. Make sure that you connect the electrolyte capacitor across the supply, as shown in the circuit, to stop the controller from resetting when motor starts.

Manu said...

Hello Dharmani sir....
can you help me build this remote controlled car project from the scratch - step by step ?
I am a 7th sem B.Tech student and I got to make my final year project...And I think if I am able to make this , I would become a rocking star overnight...
Thank you sir (my ID : manurs87@gmail.com)

Manan Shah said...

Hello Mr Dharmani,
I am working on ATMega128 + H-Bridge + DC motors.

in source code, I saw macros.h and I would like to know get that macros.h
I am still learning about macros.

I am using WinAVR to compile my code.

Thanks in Advance.

TVClassics said...

sorry for grammatical mistake and also I want to past this in other post. but please Help me with macros.h

CC Dharmani said...

macros.h is header file specific to ICCAVR compiler. If you are using other compiler, you don't need it, you can simply remove that line from the code.
For example, if you are using winAVR, then including 'avr/io.h' is sufficient.

TVClassics said...

Thanks a lot for replying. That will make my work lot easier.

I am using winAVR.

Chinmay Kulkarni said...

Hi Dharmani sir,
I'm a 4th sem B.Tech student and am making a prototype of a simple wireless rc vehicle. So could you help me with it by explaining this bot you've made in layman's terms? i'm a begineer at robotics, you see.
Thank you.
Chinmay Kulkarni.

sandeep said...

can i know voltage tat should be given at vcc..... i'm still new to tis field....

ankit porwal said...

i want do make a wire less remote for robo war ...but i m something new in robotics...
so i require dc remote controlling to drive two or four dc motors....
can u help me for designing the simplest remote controlling for dc motors.....

ankit porwal said...

hello sir
can u provide me the picture of designed pcb connections , used in this car .....

Anonymous said...

i want to just know that all these motors , used in this car are moving simultaneosly or not ...
can we control the motors one at a time to move the car right or left.....

CC Dharmani said...

Hi Ankit,
these project uses only one motor, so the car can move only in reverse and forward direction. Speed is variable (using remote). If you want to use more that one motor, you need to provide a driver (H-bridge) per motor (and also atlet one PWM channel per motor). Then you can change the speed of motors independently.

Anbazhagan said...


kindly let me know how to connect RF transmitter and receiver instead of IR....do yo have source code for RF tansmitter and receiver.

Anonymous said...

I see you connected high-side N-Channel MOSFETs source pin to the motor. Since the NMOS is activated when voltage at the gate is over the voltage at the source pin... I wonder, have you considered this? Are the High-side MOSFETs getting hotter or something?

Anonymous said...

Forget about my last commentary. I read the comments related to a previous post about the same issue I noticed in your circuit.

autobodypart8 said...

We have experienced technicians to help you through our ordering process for your truck body replacement parts or your car body parts and body parts for cars and trucks.


Mini Cooper parts

'very interesting post'

arjun said...

can you send me the hex codes plesase .my mail id is acp.9669@gmail.com

Anonymous said...

I am student at the British university in Egypt . I am proceeding this project for my course in electronics 2 and i really need help . I carried out all the project , but
the hex that i used to burn the atmega8 is corrupted . I am really in need for the code and the hex file for this project. If you could send it today ,i will be grateful for ever.because my due time is tomorrow my e-mail is
my_best_gift@ Hotmail.com
thank you in advance

Mak said...

Hi Sir
Could u please suggest and give some robotic project using atmega16 except the line follower. My email id

Anonymous said...

I would like to use ATtiny261. But I don't know where "int0_isr" should be placed. Can I put it in Timer/Counter0 Overflow? Thanks.

Mak said...

hello sir,
Iam mukilan of 4th sem ECE and beginer in robotics can u please send me the .hex file of the remote control car to mashok74@gmail.com

Mak said...

hello sir,
Iam mukilan of 4th sem ECE and beginer in robotics can u please send me the .hex file of the remote control car to mashok74@gmail.com

saqib said...

can it be implimented using 8051??

CC Dharmani said...

Yes, it can be done with 8051, but you'll need to write the code for software implementation of PWM, as 8051 doesn't have hardware PWM. It's just a little extra work.

Anonymous said...

Thank Dharmani. I use ATtiny261V to control the motor and use ATtiny13A for the IR remote using SIRC. It works!

juhi said...

how to do the IR remote interfacing with ATMEGA128 using c code...please reply soon.i need the code.
thank you.

Anonymous said...

hello ,
I was wondering weather i need the following file for the project to work :
#include "PWM_main.h"

However i have successfully compiled and programmed with avrstudio using only

is this the correct way?

Anonymous said...

hello ,
I was wondering weather i need the following file for the project to work :
#include "PWM_main.h"

However i have successfully compiled and programmed with avrstudio using only

#include avr/io.h
#include avr/interrupt.h
is this the correct way?

CC Dharmani said...

Yes, that is a correct way.

The code given here is actually in two parts, if you read the comments there, the upper part is to be copied into a file "PWM_main.h" & the lower part in the "PWM_main.c".
This is just for simplicity, as many people prefer to have a header file for all the definitions.

But if you copy the complete code into one C file, no problem, you don't need #include "PWM_main.h" statement.

The remaining two included files are part of ICCAVR compiler, so if you are using other compiler like winavr, you need to replace those files with your compiler specific header files, just like you did.

Anonymous said...

I reckon the most amazing and challenging part of your project is the ir remote control receiving part of your code. I guess you have had some problems with it too. It is more challenging for me though since i have aiwa remote with no idea which protocol or any parameters for it.

Cold you please help me clear the basic things about ir. I guess the main parameters used are: address bit length and command bit length and protocol bitrate. Am i right?

My second question would be would it be enough to have atmega32 to control up to 4 outputs, which microcontroller should i use to have 6 outputs? Is it the number of clocks in it?

Then again, because i cant use my aiwa remote i have found and tried circuit with another sony remote not exactly same as you have , it did not work. I suppose the leds should blink only when i turn it on by pressing 0. What could be the difference with other sony remotes. At least it should support same protocol but the address bit length and command bit length. Am i right?

Anonymous said...

I have found another sony TV remote, not exactly same as you have ,and tried my circuit with it, it did not work. I suppose the leds should blink only when i turn it on by pressing 0. What could be the difference with other sony remotes. At least it should support same protocol but the address bit length and command bit length could be different. Am i right?

pappu said...

how to write a sourcecode in embedded C

Anonymous said...

I have LG TV remote
what will change in code?

please reply me on below:


AnKiT said...


first of all thank you very much for providing the relevant files for the 3310-ATMEGA8 thermometer, thanks.

i am facing some errors while compiling the codes in the AVRSTUDIO as well as the ICCAVR (by imagecracker)

can you please guide me on how to compile and load the c as well as the header files in any compiler or on the atmega8 controller.

sorry to give you some trouble but i am using the ATMEL products (and so AVR) for the very first time so i am new and unknown...

waiting for you reply!!!



Dinesh said...

Hello Dharmani,
Thank you very much for sharing such an interesting and useful project. I would like to try this project with Onida Remote Control. I googled to find any information related to ondia remote, but unsuccessful. Please share me if you have any information related to Onida Remote Control.

jayanth said...

hi dharmani its a nice project.
i am working on ir remote controllers, can i build the same project using 8051/52 and i have designed a ir remote of my own using 555timers which has 4 switchs, so plz help me......
or there any codes for this then send to my mail....

thanks .......

ece projects said...

Your project helped a lot, thanks for sharing.

Anonymous said...

Hi... sorry for replying to such an old post. anyway, i have AVR Studio 5. do i have to include macros.h or can I use something else? or do I just cut it out?
Thanks so much in advance for replying

CC Dharmani said...

macros.h is required only if you are using ICCAVR compiler. For AVRstudio, you can remove that and include instead the usual header file avr/io.h

roller shutters perth said...

The circuit blueprint is simple enough. But the remote pulses are the most difficult here.

oki said...

hello Dharmani,
how do i change his code to source code codevision? I do not understand iccavr

karthik said...

this is just a wonderful tutorial.......i am like kind of beginner in this so do u have the source code for just running motors using the remote without pwm.........cos i find to confusing to understand the code............if yes pls forward to my mail id........thanks in advance for ur kind help

Aasim said...

Can I get the assembly language code for this??
my email: maasimislam@hotmail.com

anubhav malik said...

hello sir can you please provide me the program for IR controlled car using 8051 as i am working on this project.

2011disaster said...

neat and clean explanation. But i have a doubt? what is the range of IR tansmitter and receiver. Generally we need to generate 38KHz signal as a carrier.

Anonymous said...

we implemented same ckt but TSOP pin connected to INT0 of atmega 8 does not reduce below 3.5V on detection of remote signal.
Please suggest as soon as possible!

CC Dharmani said...

Check the circuit connections again. If that doesn't help, try another TSOP, or try with different remote. The LED connected to ATmega must glow on detection of a code from TSOP.

shreyas said...

From Anonymous:
I used the same remote model that u used but we implemented on bread board.We used ceramic capacitor.
please suggest

Sumit Dandekar said...
This comment has been removed by the author.
Sumit Dandekar said...

what is the programme for micro-controller to drive 2 motors.

shreyas said...

Circuit worked! No problem with ur circuit diagram.Mistake was of programming.
Nice project!!!!!!!!!!!!!!
Sir have u posted anything about creating our own programmers for atmega 8 or 16 on ur website?
If s please tell as soon as possible.
Thank u.

CC Dharmani said...

Visit this post on my blog to see how to make your own AVR programmers:


car hire in singapore said...

Very useful articles. I and my friend to do some research. I am very glad to see such information, I find the very long period of time, was finally I found, thank you.

mohith said...

please mail me the hex file of this project to

thanks in advance

Anonymous said...

can i use atmega16 instead of atmega 8

sridhar said...

hi sir,
sirc protocol using 40 khz carrier signal for sending data but in this project you are using tsop1738 reciever.

it is an 38khz signal.
so how it decodes the 40khz signal pulses.

sricarthi sri said...

hi sir,
i am 5th sem BE student. i can use RM-GA002 tv remote but not working.give me any other circuit sir.

npeducations said...

very clean and neat explanation with pics thank u it made me help in my project.

Anonymous said...

sir i need program or .hex file for this microcontroller used in car project. My mail id navalnaga@hotmail.com

Parishod Kumar said...

I need an help regarding controlling of a DC motor for below specifications,
i. Input Voltage : 24 V.

ii. Input Current : 17A.

iii. Input Power : 400 W.

iv. Loaded Speed : 800 – 1500 RPM.

v. Loaded Torque : 14 - 20 N-M.

No of motors : 1 no

Can i use the same below link circuit, or i need change any of the parameters. please help me regarding this.


mitesh gandhi said...

can you send me the hex codes plesase .my mail id is: miteshgandhi37@gmail.com

mitesh gandhi said...

can you send me the hex codes plesase .my mail id is :miteshgandhi37@gmail.com

mitesh gandhi said...

can you send me the hex codes plesase .my mail id is :miteshgandhi37@gmail.com

Anonymous said...


steve martine said...

Children's are curious to play with remote control car if you are also looking for such amazing car then must buy Rechargeable Wireless Remote Control Car which is fully wireless and controlled by remote. Moreover it comes lots of new and advanced features for more information, please visit : http://www.snapdeal.com/product/rechargeable-wireless-remote-control-car/1687848879?utm_source=aff_prog&utm_campaign=afts&offer_id=16&aff_id=4254

Unknown said...
This comment has been removed by the author.
Unknown said...

Informative content on the electrical projects which provides required information about the latest changes and updates which are available in that field.
final year projects in Chennai | ieee projects in Chennai

mmrkuzsak35 said...

Thanks for sharing... nice article.

Final Year Project centre in Chennai

Electronics Projects said...

Thanks for Nice article, Very much informative for beginners.

Electronics Projects said...

I hope, I to make a content like this. Thanks, Nice content.
Electronics Projects