Controlling Led Using Smartphone and Arduino

About: Computer and projects enthusic

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)

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions

    0
    None
    Swansong

    2 years ago

    Thanks for sharing :)