=============================================================================================================

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!!)

video

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)

Download datasheet & further info:
TSOP1738 datasheet
Info on Sony remote control codes

Thanks & Regards,
ccd@dharmanitech.com

76 comments:

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...

Hello

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.

http://extremeelectronics.co.in/code-libraries/using-ir-remote-with-avr-mcus-part-ii/

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...

Hi,
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

http://hades.mech.northwestern.edu/wiki/index.php/Driving_a_high_current_DC_Motor_using_an_H-bridge

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...

Hi,
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...

Hi,
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.
chk5391@gmail.com

sandeep said...

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

ankit porwal said...

hello
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 .....

ankit 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...

hai

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.

Thanks

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
mashok74@gmail.com

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

#include
#include
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...

Hi,
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?
regs.

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:
dharmesh25_6@rediffmail.com

thanks

AnKiT said...

HI CC DHARMANI !!

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!!!

thanks!!!

ANKIT JOSHI

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....
jayanth_vits@yahoo.co.in



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...

hello,
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
karthik(karthik4294@gmail.com)

Aasim said...

HI,
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.
http://www.npeducations.com/2011/01/design-of-ir-transmitter-and-receiver.html

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:

http://www.dharmanitech.com/2008/09/diy-avr-programmers.html

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...

hello
please mail me the hex file of this project to
rayapatimohith@gmail.com

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.
karthi5610@gmail.com

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.

http://4.bp.blogspot.com/_zqABT3suzXE/SShhr5Lur9I/AAAAAAAAANU/ap-j59gZL6o/s1600-h/motor+control+sch.JPG

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...

CAN YOU PLEASE GIVE ME THE AVR MOTOR ROTATION CODE?
IN C LANGUAGE

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