Control a Relay with ESP32 via Bluetooth Using MIT App Inventor _Part 3

Control Relay with ESP32 via Bluetooth – Part 3 MIT App Inventor Design

Welcome to Part 3 of our ESP32 Bluetooth Control series. While the code on the ESP32 is important, the User Interface (UI) is what you will interact with every day.

In this tutorial, we focus exclusively on the Designer View of MIT App Inventor. We will not just drop buttons randomly; we will use Layout Managers to create a professional, centered dashboard that scales well on different phone screen sizes.


Step 1: Setting the Screen Properties

Before adding buttons, we need to configure the main screen to handle our components correctly.

  • AlignHorizontal: Change to Center (3). This ensures all your buttons stay in the middle.
  • AlignVertical: Change to Center (2) for a modern look, or Top (1) if you plan to add a lot of components.
  • Theme: I recommend switching from "Classic" to Device Default for a cleaner, native Android look.

Step 2: Using Layout Containers

Pro Tip: Never drag buttons directly onto the screen background. They will stack vertically and look messy. Instead, use Layout components.

1. The Main Container

Drag a VerticalArrangement from the Layout tab.
Settings: Set Height to Fill Parent and Width to Fill Parent. This creates a canvas that takes up the whole screen.

2. The Button Row

Inside the VerticalArrangement, drag a HorizontalArrangement. This allows us to place the ON and OFF buttons side-by-side rather than one on top of the other.


Step 3: Styling the Components

Now, drag your user interface elements into the layouts we just created. Here are the specific properties to adjust for a polished look:

Component Property Change Why?
ListPicker Text: "Connect Bluetooth"
Width: 80%
Makes the connection button prominent and easy to tap.
Button (ON) BackgroundColor: Green
Shape: Rounded
Visual feedback that this is an "Active" action.
Button (OFF) BackgroundColor: Red
Shape: Rounded
Visual feedback that this is a "Stop" action.

Crucial Step (Renaming): In the "Components" panel, rename Button1 to btn_ON and Button2 to btn_OFF. This will make programming the logic in Part 4 much easier.


Step 4: Adding Non-Visible Components

Finally, we need to add the engine that powers the connectivity. Go to the Connectivity folder in the palette.

  • Drag BluetoothClient onto the screen.
  • It will appear at the bottom under "Non-visible components."
  • This component has no properties to change now, but it is required for the app to function.

Watch the Design Process

If you want to see exactly how to nest the layouts and adjust the styling live, watch the video tutorial below:


Now that your interface is beautiful, let's make it functional. Proceed to Part 4: Programming the Logic.

Comments

Popular posts from this blog

How to Import CSV Files into PostgreSQL Automatically

Apache NiFi ETL Tutorial for Beginners | Installation & Data Pipeline Basics

ESP32 TFT LCD 240x240 Tutorial-Display Images & DHT11 Sensor

Contact Form

Name

Email *

Message *