In the previous tutorial, we have learned how ATtiny85 serially communicates with Bluetooth module HC05 and send/receive commands from smartphone Bluetooth
This tutorial also involves the role Bluetooth module HC05. But instead of receiving commands from a smartphone, it sends sensor data values to the smartphone. The sensor is connected to an analog input pin of ATtiny85. It can be any analog sensor like LDR or temperature sensor (LM35), soil moisture sensor, etc. ATtiny85 will read analog voltage output from the sensor, convert it into a digital value, and transmit it to the smartphone using the HC05 module. So it becomes a wireless sensor data transmitter. Let’s see how it is done.
Suppose you are not following this tutorial series from the beginning. In that case, you are requested to go through the following two tutorials that explain and demonstrate how to work with ATtiny85 and step by step guide to build a “hello world” (LED blinking) application.
The circuit is built using only 3-4 components HC05 module, one LED, ATtiny85, and one three-pin sensor module (any sensor module shown here like a potentiometer, LM35 temperature sensor module, LDR sensor module, and soil moisture sensor module). 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 4 connected to ground. The sensor module has three interfacing pins (1) Vcc (2) and (3) Signal. Vcc pin is connected with 5V, and GND pin is connected to pin 4 of ATtiny85. The signal pin that is the sensor’s analog output is connected to analog input pin A2 of ATtiny85. The circuit above shows a 5 V supply.
Note: Almost all analog sensors have a three-pin interface. A potentiometer is connected in this circuit, but any other sensor that operates on 5V can also be connected in place of this potentiometer.
- When 5V supply is given to the circuit, the HC05 module will start blinking to indicate it is searching for another Bluetooth device to which it will be paired (connected)
- The person reading the sensor data will first open an Android application with having Bluetooth communication facility in his smartphone. (You may get so many such applications in the Google play store. Just search for “Bluetooth control for Arduino”). This application will search and pair with the HC05 module (for pairing 1st time, it must enter Bluetooth passkey for the HC05 module, which is by default 1234). When the smartphone get connected with the HC05 module, its blinking rate will be slow
- Now the android app in the phone is ready to receive sensor data
- ATtiny85 will read analog voltage output from the sensor and convert it into digital
- Then transmits this value to the smartphone through the HC05 module. It just sends this value serially to the HC05 module, and the module will further transmit it wirelessly to the smartphone
- the android app uses the phone’s Bluetooth and gets this sensor data, and display it on the smartphone screen
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
There are four different programs for four different types of sensors. Mainly the program is the same, but there is little change in the sending data value formats.
Initially, the program sends a message to the user’s smartphone that Bluetooth is connected with HC05 and sends sensor data.
Program for Potentiometer
Program for LDR
Program for LM35
Program for soil moisture
Then the program continuously reads sensor data, converts it in the proper format, and then serially transmits it to the phone. It blinks LED whenever new sensor data is transmitted, and this is repeated after every 1 second.
This is the last tutorial of this series. In this tutorial series, we have learned about the ATtiny85 microcontroller from the basic to the application level and interesting applications.
You can also build any small and simple application using an ATtiny85 microcontroller, especially when there are fewer IO pins and you want to build a tiny and compact device with a small form factor.
You may also like:
Filed Under: Tutorials