This week, I developed a Smart Distance Monitoring System using Arduino. The project measures real-time distances via an ultrasonic sensor and displays them on a custom mobile app. It includes a remote-controlled safety alarm (Buzzer) that can be toggled ON/OFF wirelessly via Bluetooth . so i am gonna show you step by step how to build this project and which apps did i used in details .
This was my first experience integrating Bluetooth technology into a project. I successfully used it to monitor distances in real-time and, more importantly, to achieve wireless control over the system. By developing a mobile interface, I can now toggle the Buzzer alarm remotely from my smartphone, eliminating the need to manually disconnect wires or hardware components to change the system's behavior
I used MIT App Inventor to develop a custom Android application that serves as the project's control hub. My work involved two key stages:
UI Design: Creating a user-friendly interface to display data and control buttons.
System Logic: Programming the "Blocks" to establish a Bluetooth link, enabling the phone to send commands and receive distance readings from the Arduino wirelessly.
This integration transformed the smartphone into a wireless controller, allowing full interaction with the hardware
Designing the application interface was a smooth and intuitive process. I customized the layout by adding buttons, labels, and images to suit my preferences. To ensure a seamless workflow during the programming phase, I renamed every component with a specific ID. This organization made it much easier to identify and link each element to its corresponding logic in the block editor.
The second step was developing the application's logic using the Blocks Editor. In this workspace, I assembled the code by selecting pre-defined logic blocks from the side menu and snapping them together like a puzzle. While the process feels like a game, it requires a deep understanding of logical flow to ensure the app correctly connects to Bluetooth and communicates with the Arduino. This visual approach simplifies complex coding, making the development process both engaging and efficient.
Once the design and logic were complete, I generated the application file (APK) using the Build menu, which provided a QR code for direct installation on my smartphone. After installing the app, I established a connection with the Bluetooth module. Using the standard pairing codes (0000 or 1234), the phone was successfully linked to the project, completing the software setup phase.
phase was uploading the code to the Arduino board. This code handles the distance logic and responds to the mobile app commands. int trig = 9;
int echo = 8;
int buzzer = 11;
char data;
bool isSystemOn = true;
long duration;
int distance;
void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
if(Serial.available() > 0) {
data = Serial.read();
if(data == '1') isSystemOn = true;
if(data == '0') isSystemOn = false;
}
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = duration * 0.034 / 2;
Serial.println(distance);
if(isSystemOn == true && distance < 20 && distance > 0) {
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(buzzer, LOW);
}
delay(200);
}
The system components were connected to the Arduino Uno as follows:
Responsible for measuring the distance:
VCC: Connected to 5V.
GND: Connected to GND.
Trig Pin: Connected to Digital Pin 9.
Echo Pin: Connected to Digital Pin 8.
Provides audible alerts when objects are within the safety zone:
Positive Terminal (+): Connected to Digital Pin 11.
Negative Terminal (-): Connected to GND.
Enables wireless communication with the smartphone:
VCC: Connected to 5V.
GND: Connected to GND.
TX (Bluetooth): Connected to RX (Arduino Pin 0).
RX (Bluetooth): Connected to TX (Arduino Pin 1) through a voltage divider.
Since the Arduino transmits data at 5V and the HC-05 module's RX pin operates at 3.3V, a Voltage Divider was implemented:
I used two resistors (e.g., 1kΩ and 2kΩ) connected in series.
The 5V signal from the Arduino's TX pin passes through this divider to step the voltage down to approximately 3.3V.
Purpose: This setup protects the Bluetooth module from high voltage damage and ensures stable data communication
Now that everything is connected, you can observe the system in action:
Buzzer Control: When the "ON" button is pressed on the app, the buzzer will trigger an alarm only if the distance is 19 cm or less. If the distance is greater than 19 cm, the buzzer remains silent.
Real-time Monitoring: The app continuously calculates and displays the distance on the screen regardless of the buzzer's state.
Deactivating the Alarm: If we switch the buzzer "OFF" via the app, the distance monitoring continues, but the buzzer will not produce any sound even if an object is within the range
This concludes the project for today. By following these steps carefully—from app design to hardware wiring—your system will be fully functional. Everything should work perfectly if the logic and connections are implemented as described.