Introduction: Controlling Led Using Smartphone and Arduino

Hello everyone in this tutorial I will be showing all of you how to control an led using Bluetooth module and an Arduino.

Material Required

  1. Arduino Uno
  2. A Led
  3. Bluetooth Module HC-05
  4. A Smartphone (Android Running)
  5. Female to male jumper wires
  6. A power supply for Arduino(or you can use your USB cable also)

Step 1: 1.Circuit:

  • Connect the VCC/5V pin to Arduino’s 5V pin
  • Connect Ground(GND) pin of Module to Arduino’s Ground(GND) pin
  • Connect TX pin to RX pin of Arduino
  • Connect the RX pin of the module to TX pin of Arduino.

Step 2: 2.Coding:

  1. Upload the following code to Arduino using Arduino software
int ledPin = 13; 
int state = 0;
int flag = 0;void setup() {
 pinMode(ledPin, OUTPUT);digitalWrite(ledPin, LOW);
 
 Serial.begin(9600); // Default connection rate for my BT module
}void loop() { if(Serial.available() > 0){
 state = Serial.read();
 flag=0;
 } if (state == '0') {
 digitalWrite(ledPin, LOW);if(flag == 0){
 Serial.println("LED: off");
 flag = 1;
 }
 } else if (state == '1') {
 digitalWrite(ledPin, HIGH);
 if(flag == 0){
 Serial.println("LED: on");
 flag = 1;
 }
 }
}
  1. What is code doing?
    What happens is when we upload the code in Arduino it understands it and act accordingly.So in code, we have written commands to switch on led when the Bluetooth module which is connected to Arduino gets the binary digit “1” and switch off the led when Bluetooth module get command “0”.So when we send a message to Bluetooth module which has 1 in it, the LED switches on.

Step 3: ​LAST STEP

Now all you have to do is go to google play store and download the following app: Bluetooth Terminal HC-05 After you have downloaded the app just go to Bluetooth connect to your Bluetooth module and if it asks for a password it is usually 1234 or 0000.After you have paired with the Bluetooth module go and type 1 in dialog box given there to switch on the led. NOTE: Make sure that your Arduino is connected to the power source with a circuit as given above. If there is any problem comment below.Keep making :)

GET THE APP HERE

Comments

author
Swansong (author)2017-04-12

Thanks for sharing :)

About This Instructable

130views

4favorites

License:

Bio: Computer and projects enthusic
More by bhaveshbhatia85:Getting Sensor Reading on Your Smartphone Using Arduino and Bluetooth.Controlling Led Using Smartphone and Arduino
Add instructable to: