In this tutorial series, we have learned about interfacing potentiometer to get analog input, interfacing of RGB LED by generating PWM output, DC Motor speed control using PWM output, and some other things.
This tutorial explains the serial communication of ATtiny85 with Bluetooth module HC05. ATtiny85 does not have built-in UART or USART with Rx and Tx pins, but it supports configurable USI (universal serial interface). The Arduino programming allows us to use digital IO pins as Tx and Rx pins using SoftwareSerial library. So using this library, we shall make pin 7 (PB2) and pin 2 (PB3) of ATtiny85 work as Rx and Tx pins. The Bluetooth module HC05 communicates with ATtiny85 using these Tx and Rx pins.
The more interesting part is yet to come. The HC05 module gets commands from any smartphone Bluetooth through the Android app – that sends commands from the phone’s built-in Bluetooth. So the smartphone sends a command to ATtiny85 via the HC05 module to control any device. Sounds interesting? Let’s see how it is done.
If you are not following the series from the beginning, you should go through the following two tutorials that explain and demonstrate how to work with ATtiny85 and step by step guide to build hello world (LED blinking) application.
How to work with ATtiny85
LED blinking using ATtiny85
Circuit diagram
Circuit connections
The circuit is built using only three components HC05 module, relay module, and ATtiny85. HC05 (Bluetooth module) has four interfacing pins (1) Vcc (2) GND (3) Tx, and (4) Rx. Tx pin is connected with PB2 (pin 7), and Rx pin is connected with PB3 (pin 2). Vcc pin is connected with 5V, and GND pin is connected to pin four connected to ground. The relay module has three interfacing pins (1) Vcc, (2) GND, and (3) IN. Vcc pin is connected with 5V because the relay is of 5V. GND pin is connected to pin 4 of ATtiny85. PB0 pin is connected to IN pin to switch relay ON/OFF. A 5 V supply is given in the circuit.
Note: one may connect any AC (or DC) device with relay to its contact terminals so that when the relay is switched ON/OFF, the device will be turned ON/OFF
Circuit operation
- When a 5V supply is sent to the circuit, the relay is OFF (so the device will also be OFF). The HC05 module will start blinking to indicate it is searching for another Bluetooth device to which it will be paired (connected)
- The person, who wants to control the device, will first open the Android application by having Bluetooth data sending facility in his smartphone (you may get so many such applications in Google play store. search for “Bluetooth control for Arduino”). This application will search and pair with HC05 module (for pairing 1sttime, it is required to enter Bluetooth passkey for HC05 module, which is by default 1234). When the smartphone get connected with the HC05 module, its blinking rate will be slow
- 现在从应用类型和发送“1”。ph值one Bluetooth will send this ‘1’ to the HC05 module
- HC05 module will receive this ‘1’ and gives it to ATtiny85 through serial communication
- When ATtiny85 gets command 1, it will turn ON relay by sending high to pin PB0. The device connected with the relay is also turned ON
- Now to turn OFF the device (relay), the person has to send the command ‘0’ from the smartphone
- Thus, the device is turned ON / OFF by sending commands through the smartphone
Program
The program is written in Arduino IDE software using the C programming language. It is compiled, and a HEX file is created that is downloaded into the internal FLASH of ATtiny85
Program logic
Initially, the program sends a message to the user’s smartphone that phone Bluetooth is connected with HC05 and sends command 1/0 to turn ON/OFF the device.
Then it waits for any data available from the serial port. If the ‘1’ or ‘0’ command is received, it will switch ON/OFF the relay by sending HIGH/LOW to the relay module input pin. Also, it sends a message to the user’s smartphone that the device is ON/OFF.
In thenext tutorial, we shall learn to build a wireless sensor data logger.
You may also like:
Filed Under:354manbetx
Questions related to this article?
Ask and discuss onEDAboard.comandElectro-Tech-Online.comforums.
Tell Us What You Think!!
You must belogged into post a comment.