Yelloo guys.. I hope you are doing good
and this is Jay again from MechStuff!
Today we are going to see how to control
a LED with the help of a bluetooth module
and an Android
So you are going to only need a handful of things..
Like.. an Arduino board and LED, a Bluetooth module, a breadboard and a couple of jumpers
So let's take our first component..
This is our Bluetooth model HC-05
and as you can see..
it has got 6 pins out of which we are not going to use the first and the last pin
So let's just focus on the other 4 pins between them
The 2nd and the 3rd pin - VCC & GND, as always goes to the VCC & GND of the Arduino board
and the TXD & RXD pin goes to pin number 0 and 1 of the Arduino board
which is at the lowest point of 13 digital pins over here
So let's start connecting..
I just mounted the bluetooth module..
As mentioned earlier, no connection to pin number 1,
so pin number 2 goes to VCC
Now pin number 3
Just a second...
Pin 3 goes to GND
Well, just don't connect the pin number 4 and 5 for now..
Let's connect our LED as well...
The positive terminal goes to any of the 13 digital pins over here..
I'll go for pin 8
And negative terminal goes to GND
So connections are done.. and we'll discuss about the RXD and the TXD pin later
Now let's move to our coding part.
As before, in the void setup(), we will declare pin 8 as output pin,
which is connected to +ve terminal of the LED
Then coming to our looping part
So, if the Arduino receives any data
if Serial.available() > 0,
then Serial.read() means - read the data
Then coming to our Switch statement
If the data received is "a", which comes under the Case 'a'
then the LED will glow.. which means the terminal 8 will be HIGH,
and if it is case 'd', then
the terminal will be low and the LED will turn off.
As simple as that
Then coming to our break statement..
After the switch statement, Serial.println(data)
which means that the received data would be printed in the serial monitor
here in the top right corner of your window
and then repeat this whole procedure after every 50 microseconds so
that it would receive the data after
every 50 microseconds.
So, that's it.. 20 lines of code and
you could control things with the help of your smart phone!
So let's just move further..
Let's take our smart phone..
and you download an app called as BluControl from the Google Play Store
Well the link for download is available in the description
Just go and download this Blucontrol app
and then we will connect it to our bluetooth sensor
Just open the app & the app itself
would ask you whether to turn on the Bluetooth
I will grant the access.
Then go to options
select Connect --> Scan for the devices
You'll see here bluetooth sensor HC-05 is visible over here
Let's connect it..
It will ask you a password..
It has already given as the hint that the password would be usually
0000 or 1234
Try both of them..
Well, I know the password so I am trying 1234
It says connected to HC-05,
which means that our Bluetooth module is
successfully paired with our device.
You can check whether the device has been successfully paired with the Bluetooth module
by just looking at the blinking LED on the Bluetooth sensor
If the sensor is blinking at a slower rate than before connecting,
This means the Bluetooth module has been successfully connected
So let's come back to our Android and according to our code,
when I press "a", the LED will be ON and
when I press "d" the LED will be OFF
So lets check it out..
When I press "a", the LED is ON
When I press "D", the LED is OFF
a - ON
d - OFF
You see how easy is that!
So that's all for today guys..
Just remember - YOU NEED TO CONNECT THE RXD & TXD PIN AFTER UPLOADING THE CODE!
Or else it will give you errors and the code will not get uploaded.
Just take care of that one thing.
So in my next video we are going to see how to control an LED
with the help of VOICE COMMANDS !
STAY TUNED
SUBSCRIBE TO MY CHANNEL
& get notified about my further videos.
So take care guys, see you soon ! :D
