One of the main applications of Bluetooth is to send data to a smart phone. This data which sent can be used to make real time calculations and do a specific task based on them.
In this tutorial, we will learn to send sensor data from an Arduino to our smart phone.
Software -To receive the sensor data, we will use The Arduino Bluetooth Terminal (click here to download).
Hardware -Many sensors receive and send data through 1 pin. In this part, we will discuss about the hardware of this project and how to send multiple data inputs to the Arduino.
In this project, we are using 1, 10k Ω potentiometer to represent the sensor side. (we can use any other sensor). As per the schematic (at the bottom of the page) the middle pin is the data output pin and the other 2 pins are GND and VCC (this can be interchanged as we don't specifically use it except for power). Here, the data is sent to analog pin 1 (A1) of our Arduino from where it sent to the smart phone.
To send multiple data inputs, we simply wire them to the Arduino and store them in a variable which is sent over the smart phone via code.
We are using the HC-05 Bluetooth module for this project which is very cheap and durable. We use a voltage divider to make sure that our RX pin remains safe and is not permanently damaged.
Code -As discussed in the last section, majority of the sensors send data through 2 pins rather than 1. In this section, we will show you how to send multiple data outputs to the smart phone.
Here we initialize the SoftwareSerial library and create a second serial port. We also create 2 variables, 1 to store the input and the second to store the input pin.
SoftwareSerial bluetooth(10, 11); //RX, TX
int input;
int device = A1;
In this snippet of the code, we initialize the serial port and the "bluetooth" software serial port. We also initialize Pin A1 as an input pin.
void setup()
{
Serial.begin(9600);
bluetooth.begin(9600);
pinMode(device, INPUT);
}
Our data is sent in the format - "data;". The ";" marks the end of the data stream and helps the application differentiate between different versions of the same data. To send multiple outputs, we separate each data by a comma (no whitespace) as such - "data1, data2;".
void loop()
{
input = analogRead(device);
input = map(input, 0, 1023, 0, 180);
bluetooth.print(input);
bluetooth.print(";");
Serial.println(input);
delay(20);
}
Application Set Up -Steps to set it up -
- Power the Arduino.
- Now, the hc-05 module should blink rapidly.
- Next, Open the app.
- Allow it to access Bluetooth settings.
- In the list, select hc-05.
- Select receiver mode.
- Now the module should blink once every 2 seconds.
- Here, click the link 🔗 icon on the bottom right hand corner.
- It will load for some time now.
- Afterwards, this is what you will see -
Comments
Please log in or sign up to comment.