Simple Bluetooth and microcontroller

Discussion in 'The Projects Forum' started by kakorio, Mar 26, 2013.

  1. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
    Hi Everyone,

    I have very little experience with electronics and I am looking into starts some projects. I am a mechanical engineer so i know VBA and C language (from college a while back) so i guess I have a little little background. Since i know so little about micro-controllers and Radio frequency, I need some kind of a jump start to a project I would like to do.

    Basically, i would like to connect a Bluetooth module to a micro-controller and a speaker. once the bluetooth is paired to a specific device, I would like the micro controller to make the speaker go off if the signal is between a certain range.

    Again, I know very little about this so here I go. I was looking into the PIC16F505-I/P micro-controller (very cheap) and a Wireless Serial 4 Pin Bluetooth V2.0 with a EDR RF Transceiver Module RS232. I have no idea if they can even be connected because in the datasheet I couldn't see the RX and TX pin.

    I will truly appreciate any help you can give me.
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    The 16F505 does not have a UART built in. At your level of experience, you would find it extremely challenging to implement. I have a lot of PIC experience and I wouldn't even consider it on a '505.

    As a starter, you maybe should look at Arduino, PICAXE, Parallax or similar with a bluetooth module built in. These have simplified programming environments with a lot of the chip's low level hardware stuff handled so you don't have to.

    Were you to insist on a PIC, you should look at their bluetooth stuff and read the manuals and application notes here. Pick up an evaluation board with some horsepower, PICkit and download the XC compiler. Even with all of that, you'd find Arduino easier for a beginner.

    Cost is relative. The first time out, its OK to pay a bit more to have some of the details worked out i.e. Arduino et.al. As you gain experience in uControllers, you can dig deeper into the lower level nuts and bolts.

    Just my $.02
    Have fun!
     
    Last edited: Mar 26, 2013
  3. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
    Hi JohnInTx,

    You are correct about the 16f505, I wanted to post the question so fast I didnt do my research as supposed to:eek:. I think the arduino and others are a good Idea but due to cost and bulkiness (if that is even a word) I would prefer to build something from scratch.

    I was thinking of using ATMEL AT90S2313-10PI (hope i have it right this time) and Bluetooth class 2 RS232. I know the programing might not be that easy, but the connection seems to be somewhat straight forward I hope.

    I think the programing would be only to pair a specific module and to set the alarm at a certain "signal strength".

    Regarding the bluetooth, for my application, I am hoping to "guess" distance with signal strength. I dont want a accurate measurement just a range for the alarm to sound. I will be working the sound if it goes between 20 to 30 feet apart, Do you think I should get a Class 1 bluetooth instead? Here is what I am thinking, I dont want the alarm to go off everytime the bluetooth goes out of range (that would be annoying) I just want to sound if the bluetooth is paired and the signal is between (just throwing numbers) 10% to 30%. That way, if the other bluetooth is suddenly turned off (hence 0 signal) it would technically not set the alarm because is lower than 10% (I would need to take the readings every 3 seconds or so to give enough time for the bluetooth to go below 10% once it is shut down).

    Also, Do you think this might be doable by a beginner? I just see it so simple in my head, since I know programing, but I dont know if it will be as simple as throwing a bunch of ifs and loops etc...

    Thank You for your post, It really moved me to do some research.:D
     
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    What a great quote. Let's take it step by step.

    Doable by a beginner? Sure! Everyone is a beginner sometime. I've not done Bluetooth so I would be a beginner at this too. The difference is when problems occur, I have a lot of debugging experience to draw on. You maybe not so much. But if you start out with some pre-built functional blocks (uC -> RS232->BlueTooth module etc) your debugging will be more of a functional block nature (whoops, didn't send the init sequence to the BlueTooth module) rather than being down in the weeds (my firmware UART in the '505 works but only at 16503.45 baud! Now what?).

    Simple in your head? Then sketch out a block diagram. Make sure the connections between the blocks are FULLY understood.

    I know programing. Good. Write a flow chart, generate the pseudocode and desk-check it. Once you have done that, and can trace the flow from RESET to working, you'll know if it boils down to something..

    as simple as throwing a bunch of ifs and loops etc...
    exactly! But the key is how all of those ifs and loops should be arranged.

    If you get to that level of detail, you'll find the coding pretty easy.PS I was charmed by your choice of words about throwing ifs and loops at it. I once had a client object to my quote on a job saying exactly that 'What's so hard? Its just keywords, loops and ifs!' I politely declined the job. When I saw it again 18mos. later to help debug it, sure enough.. there were keywords, ifs and loops galore! So much so that the source listing for main() ran over 130 pages! I politely declined again.

    Hey, thanks for the flashback. Get some specifics down on paper or .pdf or whatever, post it and we can take a look.

    And, nice work so far!
     
    Last edited: Mar 30, 2013
  5. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
    Hi John,

    Attached is the connection I was thinking about. I would need to connect the microcontroller to the computer first to program it but in essence this is how I have in my mind it will end. I am not connecting a key because I dont want the user turning on/off the bluetooth.

    What do you think?
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    What is the P/N of the bluetooth module?
     
  7. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    ..the datasheet is in Chinese. I found them on Amazon but didn't drill down enough to get a datasheet in English. If you can post one, that would be a help.
     
  9. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
  10. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    So its like a little modem with an AT-like command set.
    First step would be to hook it up like Fig.8 (App circuit #2).

    I would be tempted to use the MAX3232 to hook the BT module to a PC first and use HyperTerminal to buzz out the serial link and command set. Type the character sequence(s) that the module will respond to and make sure you understand what it needs to get up and connected. Go ahead and pair it with your target BT device and test it. The reason for this step is that its a lot easier to troubleshoot on a PC than a uC.

    Once you have that working set it aside and program your serial comms on the uC. It should have at the least an interrupt driven RX buffer and preferably, a TX buf too. To test that serial link, use the MAX3232 again to the PC. Write a firmware routine that just echos chars from the PC when sent by HyperTerm. If you can, send a large text file to be echoed, capture it then compare with the source file. If they match, you know you can send and receive reliably to the uC.

    Then, hook the uC and BlueTooth module together. You don't need the MAX for this but if the uC is 5V, you'll need to use some level shifting like Fig 8 shows (the transistor/diode circuits next to the MAX..).

    Finally, write the firmware to drive the BT module using the AT sequences you verified in HyperTerminal.

    You should be ready to go. Throw some of those ifs and loops in there and you're done;)

    PS I'm not that familiar with Atmel but others here are.
     
  11. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
    I just ordered the components. Will let you know how it turns out.

    Thanks
     
  12. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
    Hi,

    I already received the bluetooth module btu i noticed I needed something to connect it to the computer, so i bought this:
    http://www.ebay.com/itm/221158958927?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

    Now, I think that would help me to connect it with a RS-232 cable, right? Could you help me out with the connection, I know how to connect the microcontroller with the Bluetooth, but I am a little lots with the Bluetooth/Microcontroller to PC. I wouldn't want to burn both of them.
     
  13. #12

    Expert

    Nov 30, 2010
    16,257
    6,762
    I deleted this.
     
    Last edited: Apr 13, 2013
  14. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
    Hi,

    I already received the bluetooth module btu i noticed I needed something to connect it to the computer, so i bought this:
    http://www.ebay.com/itm/221158958927...84.m1439.l2649

    Now, I think that would help me to connect it with a RS-232 cable, right? Could you help me out with the connection, I know how to connect the microcontroller with the Bluetooth, but I am a little lots with the Bluetooth/Microcontroller to PC. I wouldn't want to burn both of them.
     
  15. cheypr

    Active Member

    Oct 13, 2009
    34
    0
    whats you status on this project?
     
  16. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
    Hi chey,

    I already connected the bluetooth to the computer. Now i am trying to figure out what program i can use to send the at commands to the bluetooth module. I have a mac, do you have any ideas?
     
  17. kakorio

    Thread Starter New Member

    Mar 26, 2013
    11
    1
    Hey Guys,

    Sorry to keep bothering but I havent been able to send at commands to the HC-05 module. I have a Mac and I am using Zterm but I cant seem to figure out how to use it. Any ideas on how to do this? Once I am able to send the AT commands I can start playing with the commands to get the desired output.

    Any help is appreciated
     
Loading...