control LED using HC-05 BT module

in #utopian-io8 years ago (edited)

Introduction

This tutorial is an open source arduino project that teaches how to control 8 LEDs wireless on your smartphone using bluetooth module, the possible purpose of this lesson is you can make an LED chaser using 8 leds that you can control using this components.

20180225_163439.jpg

What Will I Learn?

  • how to control LED using bluetooth and smartphone
  • how to make an LED chaser
  • how to program a code on arduino Desktop IDE
  • how to connect all the components connection using diagram
  • HARDWARE

    • Step 1: Gather all the Requirements

    Requirements

    • Bluetooth Module HC-05/06/07
    • 8 Pcs LED
    • 8 x 220k ohms Resistors
    • Breadboard
    • jumper wires
    • Type B usb cable
    • Arduino UNO R3 board
    • PC

    Difficulty

    • Basic arduino Project

    Tutorial Contents

    • Information about the 4 main components

    Bluetooth Module HC-05

    20180225_160010.jpg

    For this tutorial I will going to control led using HC-05 bluetooth module, this module is a component that uses for controlling an Arduino using a smartphone, The HC-05 module is a Bluetooth Serial Port Protocol module, which means it communicates with the Arduino via the Serial Communication.

    LED

    20180225_160032.jpg

    The light emitting diode or the LED this component emits visible light when current passes thru it, it is a lowe powered components, high efficiency and long life as long as it doesnt short circuit. the led has 2 set of legs, the common ground and the VCC which we will discuss on the experimental stage.

    Resistor

    20180225_160446.jpg

    Resistor have a specific measured in ohms, in this tutorial i use the 220k ohms for the LED They are passive components, meaning they only consume power it controls the amount of current that flows into the components to protect them from over volume of current that flows through the LED

    20180222_151336.jpg

    The arduino UNO R3

    has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. 32k Flash Memory, 
    source

    codes and programs can be uploaded on to it from the easy Arduino computer program. which makes it a very easy way to get started working with embedded electronics. The name R3 is the third, and latest version of Arduino Uno Board

    Experimental Procedures

    • Step 2: Build the circuit

    The HC-05 has 6 set of pins, we will use only the 4 pinswhich are the (1) VCC it refers to the power signal of the LCD typically connected to 5volts, (2)GND or sometimes zero voltage, It is also the common connection of the module must connect to in one way or another path in order to complete the circuit. (3) RX (Receive Pin, which supports only 3.3V) needs to be connected through a voltage divider then to pin TX on the arduino. On the other hand, the line between the Bluetooth module (4) TX pin to the RX Arduino pin.

    image.png

    • RXD pin to - TX of the arduino pin
    • TXD - RX pin
    • GND- GND
    • VCC - 5V

    The LED has 2 sets of leg the short one is the common cathode and the long leg will be the VCC, on this procedure place the leds on the breadboard vertical rail or on the middle rail, on the short leg connect the 22ok ohms resistor to the horizontal rail of the breadboard then to GND on the arduino. the long leg should be conncted tospecified arduino digital pin.

    image.png

  • LED 1 - pin 2 of the arduino
  • LED 2 - 3
  • LED 3 - 4
  • LED 4 - 5
  • LED 5 - 6
  • LED 6 - 7
  • LED 7 - 8
  • LED 8 - 9
  • Connect both Bluetooth module and the 8 LEDs in one breadboard circuit.

    20180225_163507.jpg

    SOFTWARE

    • Step 3: Dowload the Software and application.

    If you’re ready to get started, click on the link below then select the version with your operating system.
    Dowload the arduino Desktop IDE: https://www.arduino.cc/en/Main/Software

    When the download is finished, un-zip it and open up the Arduino folder to confirm that click yes, there are some files and sub-folders inside. The file structure is important so don’t be moving any files around unless you really know what you’re doing.

    Download the androin application Arduino Bluetooth Control LED link here; https://play.google.com/store/apps/details?id=arduino.bluetooth.leds
    by Digital2u.net the app can control 8 led using arduino and bluetooth module.

    • Step 5: Programming

    We are using the sketch code from github: https://github.com/amphancm/ArduinoBluetoothLED/blob/master/BluetoothControlLED.ino

    Source code

    #define LED_PIN1  2  //
    #define LED_PIN2  3
    #define LED_PIN3  4
    #define LED_PIN4  5
    #define LED_PIN5  6
    #define LED_PIN6  7
    #define LED_PIN7  8
    #define LED_PIN8  9
    int inByte1 = 0;         // incoming serial byte
    int inByte2 = 0;
    byte bit0 = B00000001;   // 1
    byte bit1 = B00000010;   // 2
    byte bit2 = B00000100;   // 4
    byte bit3 = B00001000;   // 8
    byte bit4 = B00010000;   // 16
    byte bit5 = B00100000;   // 32
    byte bit6 = B01000000;   // 64
    byte bit7 = B10000000;   // 128
    byte bitDelay = 100; 
    boolean status_unlock;
    boolean status_bluetooth;
    long interval = 100;           // interval at which to blink (milliseconds)
    long previousMillis = 0;        // will store last time LED was updat
    int minite,sec;
    void setup()
    {
      // start serial port at 9600 bps:
      Serial.begin(9600);
      pinMode(LED_PIN1, OUTPUT);
      pinMode(LED_PIN2, OUTPUT);
      pinMode(LED_PIN3, OUTPUT);
      pinMode(LED_PIN4, OUTPUT);
      pinMode(LED_PIN5, OUTPUT);
      pinMode(LED_PIN6, OUTPUT);
      pinMode(LED_PIN7, OUTPUT);
      pinMode(LED_PIN8, OUTPUT);
      digitalWrite(LED_PIN1, LOW);  // switch on LED
      digitalWrite(LED_PIN2, LOW);  // switch on LED
      digitalWrite(LED_PIN3, LOW);  // switch on LED
      digitalWrite(LED_PIN4, LOW);  // switch on LED
      digitalWrite(LED_PIN5, LOW);  // switch on LED
      digitalWrite(LED_PIN6, LOW);  // switch on LED
      digitalWrite(LED_PIN7, LOW);  // switch on LED
      digitalWrite(LED_PIN8, LOW);  // switch on LED 
      Serial.print("Arduino control LEDs Start");
      Serial.print('\n');
    }
    void loop()
    {
      while (Serial.available() > 0) {          
        inByte1 = Serial.parseInt(); // get incoming byte:  
        char c = Serial.read();
        if ( (c == '\n') || (c == '\r')) {
                  Serial.println(" ");       
                  if (inByte1 & bit0){                             // if bitwise AND resolves to true
                    digitalWrite(LED_PIN1,HIGH);                  // send 1
                  }
                  else{                                           // if bitwise and resolves to false
                    digitalWrite(LED_PIN1,LOW);                   // send 0
                  }
                  if (inByte1 & bit1){                             // if bitwise AND resolves to true
                    digitalWrite(LED_PIN2,HIGH);                  // send 1
                  }
                  else{                                           // if bitwise and resolves to false
                    digitalWrite(LED_PIN2,LOW);                   // send 0
                  }
                  if (inByte1 & bit2){                             // if bitwise AND resolves to true
                    digitalWrite(LED_PIN3,HIGH);                  // send 1
                  }
                  else{                                           // if bitwise and resolves to false
                    digitalWrite(LED_PIN3,LOW);                   // send 0
                  }
                  if (inByte1 & bit3){                             // if bitwise AND resolves to true
                    digitalWrite(LED_PIN4,HIGH);                  // send 1
                  }
                  else{                                           // if bitwise and resolves to false
                    digitalWrite(LED_PIN4,LOW);                   // send 0
                  }
                  if (inByte1 & bit4){                             // if bitwise AND resolves to true
                    digitalWrite(LED_PIN5,HIGH);                  // send 1
                  }
                  else{                                           // if bitwise and resolves to false
                    digitalWrite(LED_PIN5,LOW);                   // send 0
                  }
                  if (inByte1 & bit5){                             // if bitwise AND resolves to true
                    digitalWrite(LED_PIN6,HIGH);                  // send 1
                  }
                  else{                                           // if bitwise and resolves to false
                    digitalWrite(LED_PIN6,LOW);                   // send 0
                  }
                  if (inByte1 & bit6){                             // if bitwise AND resolves to true
                    digitalWrite(LED_PIN7,HIGH);                  // send 1
                  }
                  else{                                           // if bitwise and resolves to false
                    digitalWrite(LED_PIN7,LOW);                   // send 0
                  }
                  if (inByte1 & bit7){                             // if bitwise AND resolves to true
                    digitalWrite(LED_PIN8,HIGH);                  // send 1
                  }
                  else{                                           // if bitwise and resolves to false
                    digitalWrite(LED_PIN8,LOW);                   // send 0
                  }
                  Serial.print(inByte1);
                  Serial.print(" OK");             
        }
         //delay(inByte2 * bitDelay);                    //delay
         //Serial.println("OK");    
      } // if(Serial    
    } //Loop
    • Step 6: Connecting the Smartphone to the HC-05 Bluetooth Module

    Open your bluetooth settings on your cellphone, search for available devices < look for > HC-05 device name then PAIR input password 1234 then connect.

    bt.png

    • Open the app then choose the bluetooth device HC-05 to connect it. you can make an LED chaser by tapping the start LOOP in many times.

    I hope this Tutorial might help you on your future activity. thank you.



    Posted on Utopian.io - Rewarding Open Source Contributors

    Sort:  

    Thank you for the contribution. It has been approved.

    You can contact us on Discord.
    [utopian-moderator]

    Hey @lapilipinas I am @utopian-io. I have just upvoted you!

    Achievements

    • Seems like you contribute quite often. AMAZING!

    Suggestions

    • Contribute more often to get higher and higher rewards. I wish to see you often!
    • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

    Get Noticed!

    • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

    Community-Driven Witness!

    I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

    mooncryption-utopian-witness-gif

    Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x