ATtiny85 - Bluetooth

About: Hi, I just launched an Indigogo campaign support my projects by backing it. https://www.indiegogo.com/projects/tinker-usb-a-wifi-based-badusb#/

In the last instructable I showed you how to program an ATiny85, in this instructable I will show you how to start serial communication with the ATiny85 over a Bluetooth network. For this instructable I will be using a HC05 Bluetooth module which can be purchased for cheap on eBay.

So lets get started....

Step 1: Tools and Components

Here is what you need -

Step 2: Circuit

Setup the connections between the ATiny and the Bluetooth as follows -

  • Bluetooth Module Rx --> ATiny85 Pin 1
  • Bluetooth Module Tx --> ATiny85 Pin 2
  • Bluetooth Module Gnd --> ATiny85 Pin 4
  • Bluetooth Module VCC --> ATiny85 Pin 8

Step 3: Code

Here is a test sketch you can run, connect a led at 6 and upload the code. Sending 1 from a serial terminal will turn on the LED and sending 0 will turn it off.

#include //Software Serial Port
#define RxD 1 #define TxD 2

#define DEBUG_ENABLED 1 SoftwareSerial blueToothSerial(RxD,TxD);

int led = 4; void setup() { pinMode(RxD, INPUT); pinMode(TxD, OUTPUT); setupBlueToothConnection(); pinMode(led,OUTPUT); digitalWrite(led,HIGH); } void loop() { char recvChar; while(1){ //check if there's any data sent from the remote bluetooth shield if(blueToothSerial.available()){ recvChar = blueToothSerial.read(); if(recvChar == '1') digitalWrite(led,HIGH); else digitalWrite(led,LOW); } } } void setupBlueToothConnection() { blueToothSerial.begin(9600); //Set BluetoothBee BaudRate to default baud rate 38400 blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode blueToothSerial.print("\r\n+STNA=HC-05\r\n"); //set the bluetooth name as "HC-05" blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here delay(2000); // This delay is required. //blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable blueToothSerial.print("bluetooth connected!\n"); delay(2000); // This delay is required. blueToothSerial.flush(); }

Share

    Recommendations

    • PCB Contest

      PCB Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Toys Contest

      Toys Contest

    8 Discussions

    0
    None
    MostafaSalahEldain

    2 months ago

    #include <SoftwareSerial.h> //Software Serial Port

    #define TxD 0 //pin 5 de l'ATtiny à relier au pin RXD du module bluetooth (pin5)

    #define RxD 1 //pin 6 de l'ATtiny à relier au pin TXD du module bluetooth (pin4)

    SoftwareSerial blueToothSerial(RxD,TxD);

    int relais = 4; // pin 3 de l'ATtiny qui commande le relais

    void setup()

    {

    pinMode(RxD, INPUT);

    pinMode(TxD, OUTPUT);

    blueToothSerial.begin(9600);

    //delay(2000); // délai nécessaire

    blueToothSerial.print("Bluetooth connecté !\n");

    delay(4000); //Vérifie que tous les relais sont bien inactifs après un reset

    pinMode(relais,OUTPUT);

    digitalWrite(relais,LOW); // ouvre le relais

    }

    void loop()

    {

    char recvChar;

    while(1) {

    //vérifie s'il y a des données envoyées à partir du module bluetooth

    if(blueToothSerial.available()){

    recvChar = blueToothSerial.read();

    if(recvChar == '1')

    digitalWrite(relais,HIGH);

    else

    digitalWrite(relais,LOW);

    }

    }

    }

    0
    None
    BenitoB3

    9 months ago

    i am trying with this library

    #include <SoftSerial.h>

    and... compiled!!

    0
    None
    loptica62

    2 years ago

    the first line of code should read as follows:

    #include <SoftwareSerial.h>

    ....I didn't get any compile error....

    0
    None
    tvikneshwar

    2 years ago

    i am trying to make communication beteen attiny-85 and hc05 its not working bro plz help me

    0
    None
    Bullitt4511

    2 years ago

    Well, something's missing. Where to hook up to Arduino?

    1 reply
    0
    None
    IvanV52

    2 years ago

    Any ideas on faster bitrate than 9600 ?