Microcontrollers do a great job for allowing the simple user to gain access to advanced electronics applications.

For one of the robots I've built, I had to find a way of connecting an Atmega8 running at 16MHz with a Windows Mobile Smartphone. The idea was that the microcontroller handles some basic sensor data and controls some motors, and the smartphone runs an advanced application that controls the robot.

So how to do it? I've tried Infrared, since the Smartphone had an infrared port, but had little success with that. No way of connecting the two via serial port, since the Smartphone only had an USB connector.

The final solution was a bluetooth radio link.

We all know that connecting an Atmega8 to a computer's serial port is easy, by using the famous MAX232 module:

Using Bluetooth was even easier, since no electrolytic capacitors were needed as in the case of the max 232:

Here's the module's datasheetfor details regarding voltage and other parameters.

The Atmega8 needed a 16MHz crystal to assure reliable UART functionality at 9600bps (to sync with the BT Module). After putting everything together, I could establish a conneciton from my Bluetooth enabled PC, to the Atmega8+BtModule, and serial port service was available and connected as COM4. Using Hyperterminal, exchanging data worked flawlessly.

See my bluetooth enabled Atmega8 as used in my latest robot, Perseus 3.

Wireless Bluetooth connectivity offers a large number of possible applications. Good thing it is so easy to use!

Radu Motisan

(Visited 2,492 times, 11 visits today)
facebooktwittergoogle_plusredditpinterestlinkedinmailfacebooktwittergoogle_plusredditpinterestlinkedinmail
Tagged on:         

36 thoughts on “Atmega8 with Bluetooth radio module

  • November 27, 2009 at 8:01 pm
    Permalink

    ESTA INTERESANTE TU TRABAJO PERO QUISIERA SAVER SI ME PUEDES DAR UANA MANO COM UN PROYECTO QUE QUIERO HACER SE TRATA DE UNA PANEL ELCTRONICO HACIONADO VIA BLUETOOTH SI PUDIERAS DARME UNA AYUDA TE LO AGRADECERIA

  • November 27, 2009 at 10:09 pm
    Permalink

    Ola YONATHAN,

    I’ll do my best to help you, so let me know what you need.

  • December 12, 2009 at 1:19 pm
    Permalink

    Could you send me a link or something about how to write the program or a program itself to atmega8 and bluetooth module connection ( mine is a rayson BTM 222 ). I mean program for the atmega microcontroller to handle the module. ( Basic would be the best,but anything would be a good help. )
    Thanks

  • December 12, 2009 at 7:54 pm
    Permalink

    Szia Zsolt,

    I’m simply using the RX/TX to send/recieve serial data via UART. It worked from the first try

    Let me know if you need an UART sample.

  • December 16, 2009 at 5:03 am
    Permalink

    en si estioy en nada sobre ek proyecto no se por donde empesar pero no seria mas facil utilizar el usar antes que el uart bueno
    lo que estoy buscando haorita es un simulador para lo que va ser la tx y rx si tu vieras un simulador o algo que me ayude te lo agradeseria

  • February 2, 2010 at 4:46 pm
    Permalink

    Salut,

    De unde ai cumparat modulul BT ?

  • February 2, 2010 at 6:24 pm
    Permalink

    @razvan: ebay.

  • March 3, 2010 at 10:16 pm
    Permalink

    Dear Radu,
    I have needed the Bluetooth serial converter.I am in Kolkata.I dnt get this device in here market.So plz give me any site or address about this device.It too much important for me.So plz give me the site.I will buy in limited cost.So plz help me.
    Thank You.And nice Job.

  • March 3, 2010 at 11:38 pm
    Permalink

    Paul, are you referring to the UART Bluetooth Module?

  • May 6, 2010 at 11:34 pm
    Permalink

    Salut! Poti sa ma ajuti un pic? Am un modul BT foarte asemanator, si nu stiu cum ar fi bine sa-l montez pe PCB.

  • May 7, 2010 at 6:42 pm
    Permalink

    ce modul e? poti pune niste poze?

  • April 7, 2011 at 6:42 am
    Permalink

    Hi, first of all I have to thank you for share your work whit everyone, and second I have a question, I have an Atmega48P, can I use this mricrocontroller or do I need to get one different?

  • April 7, 2011 at 10:07 am
    Permalink

    Hello Diego, thanks.

    Yes you can use the Atmega48, to interface the bluetooth module you will only need the two uart pins tx and rx.

    Good luck, and feel free to post pictures with your project when completed.

  • May 24, 2011 at 3:42 pm
    Permalink

    Did you have any interference problem using bluetooth? I’m using a roving networks rn-41 bt module with an atmega328 and a gyro (via ADC), and i get interference from bt module. If i try the board via serial cable, it works just fine, accurate and stable. When I change te cable for the rn-41 some kind of RF noise shows up, and it just never get stable, it’s always sending little variations (as if the gyro was being rotated, wich is not). I tried changing the supply of bt module just in case it would be a matter of high current consumption of BT, but it didn’t solve the problem. Later i tried to get the BT module away from atmega328 via cable extension (about 10 inches), and altough the noise still existed, it starter to show up in bigger intervals of time (there was more time between noise and noise). Sorry about my english, i’m not to good at it yet. Then i restored the bt to the board and extenden the gyro via cable to get it far away from BT, but the problem persisted. So i think the noise problem it’s between BT module and atmega328 … any hint on how to solve this? The size of the board it’s pretty important on my project, so getting the BT away it’s not really a solution since distance its huge (the entire board it’s 4 inches lenght)

  • May 24, 2011 at 9:40 pm
    Permalink

    Hi Jorge,

    I didn’t get such issues, but,

    let’s not forget we are talking about digital transmissions, where information is digitally encoded, it also comes with checksums and error correction mechanisms, it is unlikely for a RF interference to corrupt the data at Bluetooth serial port profile protocol level.

    So I suspect there is a software bug somewhere, you might want to double check the Bluetooth code part , or post it here.

    Hope this helps,
    Radu

  • May 24, 2011 at 10:39 pm
    Permalink

    It’s not that the data sended by the bluetooth get corrupted. In a steady position, gyro shouldn’t send any data towards the MCU, since there is no angular velocity being applied to it. Therefore, MCU shouldn’t send any data towards the computer via BT module. But when in a steady position (i.e. laying in a table) the MCU sends constant data at the computer, as if the gyro was detecting constant movement being applied to him, wich is not. My first tought was that the gyro was being afected by the RN-41 (let’s remember that via cable, this doesn’t happen). Now after several tests (described above) i think the problem its somewhere between the RN-41 and the atmega MCU. I’m trying filters to see if i can get it stable.

    I know that gyro has an error range, that makes him detect angular velocitys even when there is none (or maybe some “natural” oscillations of the floor because of traffic or something), but according to datasheet, and to the tests i made via cable, these variations are a lot smaller than the ones i detect via Bluetooth. Lets say after ADC in range of 0-1023, normal variaton of gyro goes from +-3 of the “zero” reference (wich is 500), and when i connect via Bluettoth i detect variations from +-30. That’s a lot if you consider that moving the gyro really fast you’ll get aproximately +- 120 (so +-30 it’s actually a 25% noise signal).

    Thanks four your fast reply!

  • May 25, 2011 at 7:51 am
    Permalink

    Jorge, what are you building?

  • May 25, 2011 at 3:31 pm
    Permalink

    I manage myself to find the cause of the problem. After re-cheking the complete pcb i found that one of the Power supply tracks that I was cutted in order to separate BT supply from MCU supply was not completley cutted. So i re-cutted it, test different Power Supplies for each part of the board and it worked just fine. So it was a problem of noise being generated by the RN-42 in the supply line, because of dramatic changes from low to high current consumption during TX.

    Klein: I’m trying to build a sort of stability control for my robot. The idea it’s to carry things in a container that is keept paralell to horizon all the time (so things don’t fall when climbing or descending).

  • May 26, 2011 at 7:18 pm
    Permalink

    you mentioned that you connect your smartphone with atmega via BT. But you said connect with computer.Recently some people succeed in connect atmega with phone via BT.there is a library by mit on android.But i’m looking for ios.

  • May 27, 2011 at 5:00 pm
    Permalink

    @Radu Motisan,yes.And I see your Android controlled robot ,that is what i’m serching for on ios.Sometimes i just do without PC.

  • May 27, 2011 at 5:09 pm
    Permalink

    @Radu Motisan,see work by someone else.you both have well program skill

  • May 28, 2011 at 9:10 am
    Permalink

    Sorry feng, that would take time to develop.

  • May 28, 2011 at 5:21 pm
    Permalink

    this make me consider to buy an android or flash android to itouch later

  • July 25, 2011 at 5:54 am
    Permalink

    hi…this is Titus
    i hv one doubt from bluetooth link
    can i do bluetooth link betwn android mobile to PIC controller(16F877A) ???
    if it is “yes”
    tel me hw
    give some idea to start and examples
    plzz help me

    this is my email id
    titusece@yahoo.com

    thanx

  • July 25, 2011 at 9:20 am
    Permalink

    yes titus you can.

    the best example is this article, read it and see the schematics.

    what you need to do is connect the BT module to PIC’s UART pins.

  • September 7, 2011 at 11:36 pm
    Permalink

    Radu, over on http://www.slideshare.net/erinyueh/android-bluetooth-introduction you mentioned “Using Bluetooth, I managed to control a 4×4 Robot (Drone) remotely, using my Android G1. I’m using a serial connection over bluetooth”.

    Is that code available for review somewhere? I would like to have a look at it if so.

    Thanks!

    Darrin

  • Pingback: Android controlled robot (via Bluetooth) – Part 1 « PocketMagic

  • February 11, 2013 at 4:19 am
    Permalink

    Hi Radu,
    I have to make in my last year project a rectifier controlled by microcontroller PIC16F887, how can i use this rectifier to make my robot?

  • November 30, 2013 at 12:28 pm
    Permalink

    Hello Radu, Do we need to use MAX232 if we are not using RS232 ? I wanna send data to my AtMega32 via android. So all I need is Atmega32 and Bluetooth Module, right ? Also suggest me Bluetooth Module for this

  • December 1, 2013 at 1:24 am
    Permalink

    @Shree: you are correct, the MAX232 is not needed for your purpose. You can use HC-05 Bluetooth modules, also available on Ebay.

  • December 24, 2013 at 8:13 am
    Permalink

    Hi Radu, Thanks for the Response. I see many HC-05 Bluetooth modules there, which one you suggest for ATmega32 ?

  • November 3, 2014 at 6:56 pm
    Permalink

    Hello, I would like to use a HC-06 bluetooth module, but no success yet. The microcontroller doesnt get the right data from PC, but if I send something from the controller, I get it. Some suggestion?:)

  • Pingback: Digital bench power supply - PocketMagic

Leave a Reply

Your email address will not be published. Required fields are marked *