Atmega8 with Bluetooth radio module

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

This article has 36 Comments

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  21. 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?:)

Leave a Reply