Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to control LEDs using the MIT App Inventor and Bluetooth

By Nikhil Agnihotri February 25, 2024

In a previous tutorial, we discussed the MIT App Inventor, a popular online platform for building mobile applications using visual programming. The platform is helpful for quickly prototyping Internet-of-Things (IoT) applications and simple embedded systems that interact with mobile devices. 

We already reviewed the platform’s architecture and user interface. Its visual programming platform is ideal for building beginner to intermediate mobile applications that interact over Wi-Fi or Bluetooth. 

Now, we’ll use the MIT APP for mobile app development, integrating our new app with embedded electronics. In this tutorial, we’ll control an LED light using Arduino and a mobile app built using the MIT App Inventor. The mobile application will communicate with Arduino via Bluetooth using the HC-05 Bluetooth module. 

To begin, we’ll build a mobile application and transmit data from it to Arduino, using Bluetooth. Next, we’ll learn how data received over Bluetooth can be used to manipulate Arduino’s circuit. 

Building mobile-controlled electronics and IoT applications
When designing the circuit and firmware of the IoT device, we must also consider the mobile application. The app is the interface or medium we’ll use to control an IoT device or access its features wirelessly. So, evaluating how the microcontroller will interact with our app is important.

For example, how will the microcontroller connect with the mobile app? What data will be exchanged? What IoT features will be accessed? The mobile application development goes hand-in-hand with the firmware development. As a result, the microcontroller’s firmware must be designed per the intended interactions with the mobile app.

Additionally, it’s essential to figure out the mobile application’s functionality. What do you want it to control in terms of the IoT device? And how will its user interface behave? Once, we’re clear on the app’s functionality and user interface, we must determine the application’s logic. The IoT device will communicate data to the mobile app, or the mobile app will transmit some data to the device. In each scenario, It’s necessary to determine the type and range of data and operations to be conducted.

When building electronics or IoT applications which will be controlled via a mobile application, we must:

1. Design the circuit of the IoT device.
2. Program the device’s firmware, considering its interaction with the mobile application.
3. Build the mobile application interface.
4. Develop the mobile app’s logic based on its interaction with the device.
5. Test the device and all its interactions with the mobile application.
When using the MIT App Inventor, the interaction of the mobile application with the microcontroller will be done via Bluetooth or Wi-Fi.

Components required
To build the circuit of this application, you’ll need the following components.

  1. Arduino UNO/Arduino MEGA x1
  2. LED x1
  3. 330Ω Resistor x1
  4. HC05 Bluetooth module x1
  5. Breadboard x1
  6. Connecting wires or Dupont wires
  7. A smartphone

Connecting the circuit
First, we must assemble the circuit for the IoT device. We’ll begin by interfacing an LED with Arduino so it can source current to the light. To do so, connect the LED’s anode with Arduino’s GPIO2 pin and connect the LED’s cathode with the ground via a series resistor of 330 ohms.

As we want to control the LED, so we’ll need to devise a way for Arduino to communicate with our mobile application. Arduino can communicate with the app (which is on a smartphone) through Bluetooth or Wi-Fi. We’ll use Bluetooth.

We’re also using Arduino UNO (or Arduino MEGA), which doesn’t have built-in Bluetooth or Wi-Fi functions. So, we need to interface the HC-05 Bluetooth module with Arduino so it can communicate with our app. To interface the HC-05 Bluetooth module with Arduino, connect the HC05 module’s RX and TX pins with Arduino’s TX (GPIO1) and RX (GPIO0), respectively. Connect the HC05 module’s VCC and GND pins with Arduino’s 5V out and ground pins, respectively.

Circuit diagram

Programming the microcontroller
When programming the microcontroller, we must consider the interaction of the mobile application with the IoT device. The app will switch the LED on Arduino ON or OFF. 

The mobile application must send a data value of ‘1’ via Bluetooth whenever a user turns ON the LED and send a data value of ‘0’ via Bluetooth whenever a user turns OFF the LED. 

The microcontroller’s firmware will “look” for an incoming data value or command from the Bluetooth application and set the digital output at the pin depending on if the LED is connected to HIGH or LOW (based on the incoming value). 

Note that the firmware application’s logic depends entirely on the circuit design. As the LED is connected such that Arduino sources current, we must set the pin HIGH to turn ON the LED and the pin LOW to turn off the LED. 

The sketch 

char command = 0;

void setup(){
  Serial.begin(9600);
  pinMode(2, OUTPUT);
}

void loop(){
  if(Serial.available() > 0){
    command = Serial.read();
    Serial.print(“Command Received Over Buetooth: “);
    Serial.println(command);
    if(command == ‘1’){digitalWrite(2, HIGH); Serial.println(“LED TURNED ON”);}
    else if(command == ‘0’){digitalWrite(2, LOW); Serial.println(“LED TURNED OFF”);}
  }
}

Upload this sketch before making circuit connections or remove Arduino’s VCC and GND connections with HC05 while uploading the sketch. Otherwise, you might encounter an error because the same UART port is shared between the computer and the HC05 Bluetooth module.

Building an app using the MIT App Inventor
The mobile application requires two functions to properly control the LED on Arduino. One must connect with Arduino via Bluetooth and the other must turn ON and OFF the LED.

To build the application, login to the MIT App Inventor platform and create a new project by navigating to Projects-> Start New Project.

Name the project something like ‘LEDOnOff’ or ‘LEDControlBluetooth’ and click OK.

Upon creating a new project, you’ll see a blank screen. Select the screen and change the title of it, so it indicates the purpose of the application.

Now, we’ll need to build the user interface of our mobile application. The user interface lets users connect with Arduino through Bluetooth to control the LED.

First, we must select a Bluetooth device to connect to. This is provided through a ListPicker element. Select ListPicker from the ‘User Interface’ tab and drag and drop it to Screen1.

Set the font size of ListPicker to 24 points, increase the width to fill parent, and change its text to ‘Select Bluetooth Device.’

Two buttons are required to control the LED —  one to turn it ON and another to turn it OFF. These buttons can be set in a horizontal arrangement. Select ‘HorizontalArragement’ from the ‘Layout’ tab. Drag and drop it to the screen.

Drag and drop two buttons in the ‘HorizontalArragement.’

Change the background color of Button1 to Green, set its font size to 24 points, change the width to 50 percent of the parent, and change its text to ‘ON.’

Change the background color of Button2 to Red, set its font size to 24 points, change the width to 50 percent of the parent, and change its text to ‘OFF.’

We’ll need a Bluetooth Client on the screen to enable a Bluetooth connection. Select ‘Bluetooth Client’ from the ‘Connectivity’ tab. Drag and drop it in the screen.

The Bluetooth Client appears as an invisible element in the user interface. This completes the user interface of our mobile application. It has a ListPicker to connect to a Bluetooth device (i.e., Arduino) and two buttons in a horizontal arrangement for turning the LED ON and OFF.

Now, its time to design the logic of our mobile app through visual programming. Click on the ‘Blocks’ button on the top right corner. We must implement the following logic in the application.

Now, it’s time to design the logic of the mobile application through visual programming. Click on the ‘Blocks’ button in the top right corner. It must follow this logic:

  • Populate a list of available Bluetooth devices in the ListPicker for selection by the user.
  • Once a user selects a Bluetooth device, the application must immediately connect to that selected Bluetooth device.
  • When Button1 is clicked, the app transmits a command to turn ON the LED — a data value of ‘1’ in our case.
  • When Button2 is clicked, app transmits command to turn OFF the LED — a data value of ‘2’ in our case.

To populate the ListPicker with the available Bluetooth devices, click on ListPicker in the ‘Blocks’ tab, and select ‘When ListPicker1 BeforePicking.’ Drag it to the Viewer.

Select ‘Set ListPicker1.Elements To’ from ‘ListPicker’ and drag it to the Viewer under ‘When ListPicker1 BeforePicking.’ Next, select ‘BleutoothClient1.AddressesandNames’ from ‘BluetoothClient1’ and drag it to ‘Set ListPicker1.Elements To.’

To connect with the selected Bluetooth device, drag and drop ‘When ListPicker1.AfterPicking’ from ‘ListPicker1’ in the Viewer. Drag and drop ‘Set ListPicker1.selection To’ from ‘ListPicker1’ under ‘When ListPicker1.AfterPicking.’ Drag and drop ‘Call BluetoothClient1.Connect Address’ to ‘Set ListPicker1.selection To.’

To change the test of the ListPicker to ‘Connected,’ drag and drop ‘Set ListPicker1.Text To’ under ‘When ListPicker1.AfterPicking.’ Drag and drop ‘Text’ from ‘Text’ to ‘Set ListPicker1.Text To’ and set the text to ‘Connected.’

To turn the LED ON when clicking Button1, drag and drop ‘When Button1.click’ in the Viewer. Then, drag and drop ‘Call BluetoothClient.1 SendText Text’ to ‘When Button1.click.’ Lastly, drag and drop text from ‘Text’ and set it to ‘1’.

To turn the LED OFF by clicking Button2, drag and drop ‘When Button2.click’ in the Viewer. Then, drag and drop ‘Call BluetoothClient.1 SendText Text’ to ‘When Button2.click’. Drag and drop text from ‘Text’ and set it to ‘0’.

This completes the programming of our mobile app.

Testing the application
We have built the circuit of our device, programmed Arduino to interact with the mobile app, and completed our app using the MIT App Inventor. Now, it’s time to test our application.

To do so, install the MIT App Companion on your smartphone. In the MIT App Inventor, navigate to Connect-> AI Companion. A window will pop up prompting you to scan a QR code or enter a code to launch the app in the MIT App Companion.

Open the MIT App Companion on your smartphone and scan the QR code or enter the presented code to launch the application.

Now, you can interact with your app! First select the Bluetooth device. After connecting with Arduino via Bluetooth, tap on the ‘ON’ and ‘OFF’ buttons to ensure they work and turn the LED ON and OFF.

The mobile application controlling the LED is demonstrated in the following video.

https://www.engineersgarage.com/wp-content/uploads/2024/02/MITAPP02-DV.mp4

Conclusion
It’s fairly quick and easy to build mobile applications using MIT App Inventor. It’s a useful platform for creating apps that can interact with electronics and IoT devices. Always begin by designing the circuit of your device based on the requirements of the application. Then, co-design the microcontroller firmware and mobile app based on intended interaction between the device and the app. Have fun!

 

You may also like:


  • The top mobile app development tools for IoT and electronics

  • How to build a plant health monitor using ESP8266 and…

  • What is Matter? An all-new smart home standard

  • How to get started with MIT App Inventor

  • How to make HTTP requests using Arduino for the IoT

  • The top long-range Bluetooth modules of 2023

Filed Under: IoT tutorials, Tutorials, Video
Tagged With: app, Arduino, bluetooth, led, microntroller, mitappinventor, mobileapps, tutorial
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe