top of page

~*~ BLE Magic ~*~
Controlling LEDs from a Mobile Phone

Overview:

We saw above how we can pass strings from the BLE mobile app to Arduino. We will use these strings to control our leds.

 

In order to do so, we shall define some system to send commands to our Arduino software, and in the main loop we shall search the string for the command we sent, and execute it.

 

In the ancient world of dial-up modems, there was a use in “AT Commands”, where usually, you will send the module you want to communicate with the prefix “AT+” and the rest of the string will be the command itself and the arguments needed in order to complete it.

For example: “AT+cmd,7”. The module will search for the “AT+” prefix and execute the request or give some information in return.

(Technically, it is Hayes command set), and this form of communicating with a module is still in use for many modules.

 

Prefix - We will define and use our own command set, the “Embedded Workshop” commands, with the prefix “EW=”.

Command body - every LED will be represented by the first letter of its color ‘R’ - red, ‘G’ - green, ‘Y’ - yellow. After the letter we will send its value: ‘1‘ for HIGH (LED is on) and ‘0’ for LOW (LED is off).

For example: “EW=Y0G0R1” will set the red LED ON and the green and yellow LEDs OFF.

 

Optional reading:

There are two reasons we are using “EW” prefix and not “AT”; first of all, the software already using AT commands that Adafruit has implemented, we I would not like to confuse the two. Secondly, I wanted to show that there is no other magic behind this process of defining and sending commands, and you can understand the entire flow, so you can add commands by yourself.

 

Task Goal:

To control our three leds form our mobile phone (turn them on or off as we wish).

 

Code:

In this part, we will use the same code as in the first warm-up.
Folder name: part_7_ble

 

Instructions:
Note:
 this part of the tutorial assumes you are already familiar with the instructions on "BLE Warm-Up #1 UART over BLE".

  1. First, make sure you’ve read the “overview” of this section.

  2. Enable our code, by setting “true” to the feature enabler flag (named EW_cmd_enable).

  3. Search the code for the flag (EW_cmd_enable) and try to understand what does it control?

  4. Make sure all the leds are connected to the board, in the right pins (the pins 11, 12, 13 shall be set from the previous parts of the workshop).

  5. Repeat steps 1-7 from "BLE Warm-Up #1 UART over BLE" (compile, upload, connect via mobile-app), but instead of sending “Hello Bluefruit!” send the command “EW=Y1G1R1”. ALL LEDS SHALL LIGHT UP!

  6. Try different LEDs combinations such as: “EW=Y0G1R0” to light only the green led.

Feature Flag:

Screenshots of the setup and process:

bottom of page