Project 5 – Led ON and OFF using bluetooth

In this project you will learn to develop an App to turn on and off an LED from a mobile device with Android operating system through Bluetooth.

You can control the LED using the buttons and voice commands of the App.




  • 1 White LED
  • 1 Clear or white plastic cup
  • 1 Build&Code 4in1 control board
  • 1 USB – Micro USB wire
  • Computer
  • Material to make the lamp structure
  • Adhesive

¿What is bluetooth?

Bluetooth is a wireless technology standard used for exchanging data between fixed and mobile devices over short distances.


Connect white LED  to digital port 9 of Build&Code 4in1 main board.

To guide you, look at the wire colors and the terminal colors of the Build & Code 4in1 controller board. Each cable must be connected to its color:


To build the lamp structure you will use wooden sticks of 150 mm x 18 mm, a plastic, white or transparent glass and hot silicone to make all the joints of the structure.
Download fast guide and follow steps:


The program consists of controlling the behavior of the LED through an App that we will develop with App Inventor, an application development environment for Android devices using instruction blocks.

The Build & Code 4in1 board has a Bluetooth module that will allow us to control the components connected to the digital and analog inputs. It is not possible to program the control of the Bluetooth module using block-based programming software and we will need to use Arduino IDE.

In the Arduino sketch we will include some instructions at the beginning to be able to change the name of the Bluetooth module so that it is easier for us to differentiate our controller board.

Below you will find the necessary programming code.

Arduino Code

If you use it for first time with Arduino IDE or you have any issue loading the program, please visit Arduino IDE section in our first steps guide.

Open Arduino IDE software and paste code below:


//Cambio de nombre dirección Bluetooth 4in1
char nombre[10] = "4in1_A01"; //Entre comillas: nombre del módulo Bluetooth que podemos personalizar

char password[10] = "0000"; //Entre comillas: contraseña del módulo Bluetooth que podemos personalizar 

char baud = '4'; //4 = 9600 baud

//Variables programa Bluetooth y LED

char data = 0; //Variable de lectura Bluetooth

int PLED = 9; //Puerto de conexión del LED

void setup() {

  Serial.begin(9600); //Abre puerto serial a 9600 bps

  pinMode(13, OUTPUT); //LED placa como salida 
  digitalWrite(13, LOW); //LED placa apagado

  Serial.print("AT"); //Iniciar la configuración
  delay(1000); //Espera 1000 mseg (1 segundo)
  Serial.print("AT+NAME"); Serial.print(nombre); //Instrucción que reconoce la placa para cambiar nombre
  Serial.print("AT+PIN"); Serial.print(password); //Instrucción que reconoce la placa para cambiar contraseña
  Serial.print("AT+BAUD"); Serial.print(baud); //Instrucción que reconoce la placa para cambiar baudios

  digitalWrite(13, HIGH); //LED placa encendido
  digitalWrite(13, LOW); 

  pinMode (PLED, OUTPUT); //LED como salida 
void loop() {

   if (Serial.available() > 0) 
   data =; //Guarda en la variable “data” el dato recibido por Bluetooth

    switch (data){

      case 'A': //LED ON
      digitalWrite(PLED, HIGH);

      case 'B': //LED OFF
      digitalWrite(PLED, LOW);

Connect the board to the computer, make sure the switch is in “USB” and load the program. Once the program is loaded, disconnect the board from the computer and place the switch on the board in the “BLT” position. Reconnect the board to a power source (with the USB cable to the computer or with the battery holder). The board is ready!

Now, copy the Ebotics_LEDcontrol.apk file to your Android device and install the application. You may have to grant permissions for this in your Android device.

Connect the Bluetooth of the Android device. In Bluetooth settings select “Search”. Select the available device that corresponds to the name of the board you have written in the programming (failing “4in1_A01”). It is likely that the name will appear, you can click on the device called “HC-06” to speed up the process. Type the password of the device we want to link (the code shows “0000” by default).

Open the installed application and press the “Connect” button. Select the device with the name corresponding to the board.


You can use the App buttons to turn the LED on and off. You can also press the microphone icon to control the LED by voice. As configured in the App you can say “turn light on” or “turn light off” to turn the LED on and off.

Download Ebotics_LEDcontrol.aia to modify the appearance of the App, notification messages, voice commands, etc. You must import it from the AppInventor edition website If is the first time you use it, you will need to register as user there.

0 0