First of all, what is HC-05?
HC-05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup. Serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and baseband.
So, they basically transfer incoming Bluetooth communication to serial data.
So, what are we going to do in this mini project?
Basically our first aim is to set up a connection between our Arduino and our phone. (There are specific apps for this which I will talk about).
Next, to understand how it works better, we will connect three LED’s to Arduino. So if you press 1, the first LED would glow and if you press ‘2’ the second and so on.
So, Here you are able to witness the output of what you type on your phone in your desktop/laptop monitor.
Components Required
Arduino Uno
HC-05 Bluetooth Module
Three LED’s
Three 220 ohm Resistors
Smartphone (Android or IOS)
USB cable
Breadboard
Connecting wires
Circuit Diagram
Schematic Diagram:
So, Wire up your circuit as shown above!
Next, Download an app named “S2 terminal for Bluetooth” or (also known as BT term) on your smartphone. It is a free app available on both Google play and IOS.
Then, pair your phone with your Arduino(Bluetooth module).
Go to the app, and again pair up your phone to HC-05 via the app.
Next, upload the given code below and you are good to go!
SO now, you can type in from your phone( in the app basically) and see the result on your monitor and vice versa. ( observe the results by opening Serial Monitor on your desktop)
Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
int led1=13;
int led2=12;
int led3=8;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
int ans=mySerial.read(); // returns ASCII values of numbers
if(ans=='1')
{
digitalWrite(led3, LOW);
digitalWrite(led1, HIGH);
}
if(ans=='2')
{digitalWrite(led2, HIGH);
digitalWrite(led1, LOW);
}
if(ans=='3')
{
digitalWrite(led3, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led1, LOW);
}
if (Serial.available())
mySerial.write(Serial.read());
}
No comments:
Post a Comment