Control a lamp connected to Arduino UNO via Bluetooth

Arduino UNO 21-11-23
209 0

Tutorial plan

1- The Arduino UNO board and Bluetooth

2- Why do we use App Inventor to create a mobile application capable of communicating the smartphone with the Arduino UNO board?

3- The components needed to use the HC-06 Bluetooth module, a lamp and a relay  with the Arduino UNO

4- Mounting the Arduino UNO with the HC-06 Bluetooth module , a lamp and a relay

5- Turn on a lamp connected to the Arduino UNO board by a smartphone via Bluetooth with Arduino IDE and App Inventor

 

 

The Arduino UNO board and Bluetooth

The Arduino UNO board and Bluetooth can be used together to create various projects that involve wireless communication. The Arduino UNO is a popular microcontroller board that is widely used for prototyping and creating interactive electronic projects. Bluetooth, on the other hand, is a wireless technology that enables communication between devices over short distances.

To use Bluetooth with an Arduino UNO board, you would typically need to add a Bluetooth module to the board. There are several Bluetooth modules available that can be easily interfaced with the Arduino UNO, such as the HC-05 and HC-06 modules. These modules use the Serial Communication protocol (UART) to communicate with the Arduino.

Here are the general steps to get started with using Bluetooth on an Arduino UNO:

1- Choose a Bluetooth Module: Select a suitable Bluetooth module, such as HC-05 or HC-06, based on your project requirements. These modules are readily available and are relatively easy to work with.

2- Wiring: Connect the Bluetooth module to the Arduino UNO. Typically, you would need to connect the TX pin of the Bluetooth module to the RX pin of the Arduino UNO, and the RX pin of the Bluetooth module to the TX pin of the Arduino UNO. Remember to connect the grounds of both the Bluetooth module and the Arduino together.

3- Power Supply: Make sure the Bluetooth module is properly powered. It usually operates at 3.3V or 5V, so ensure that the voltage levels are compatible with your Arduino UNO and the module.

4- Code: Write an Arduino sketch (program) that communicates with the Bluetooth module using the Serial library. You can send and receive data wirelessly between your Arduino and a Bluetooth-enabled device, such as a smartphone or a computer. Your code should include instructions to establish a Bluetooth connection, send and receive data, and handle any required processing.

5- Pairing and Communication: Once you upload the code to your Arduino UNO and power it up, you can pair your Bluetooth-enabled device with the Bluetooth module on the Arduino. Depending on the module, you might need to enter a specific pairing code.

6- Testing: Test your setup by sending data from your Bluetooth-enabled device to the Arduino UNO and vice versa. For example, you could control an LED, a motor, or any other component connected to your Arduino board.

Remember that specific details may vary depending on the Bluetooth module you are using, so it's important to refer to the datasheet and documentation of your chosen module for accurate wiring, setup, and programming instructions.

With the Arduino UNO and Bluetooth, you can create a wide range of projects, such as remote-controlled robots, home automation systems, wireless sensors, and more. The key is to understand the basics of serial communication and how to interface the Bluetooth module with the Arduino.

Why do we use App Inventor to create a mobile application capable of communicating the smartphone with the Arduino UNO board?

MIT App Inventor is a visual programming environment that allows individuals with little or no programming experience to create mobile applications for Android devices. It is particularly well-suited for creating mobile applications that communicate with external hardware, such as the Arduino UNO board. Here are some reasons why MIT App Inventor is often used to create mobile applications for communication with Arduino boards:

1- Simplicity and Visual Interface: MIT App Inventor uses a visual drag-and-drop interface that makes it easy for beginners to create mobile applications without having to write complex code. The blocks-based programming approach allows users to build logic by connecting blocks that represent different functions.

2- Rapid Prototyping: App Inventor allows you to quickly prototype and test your ideas. You can create functional applications relatively quickly, which is beneficial when you want to iterate and refine your project.

3- Bluetooth Integration: App Inventor provides built-in components and functions for Bluetooth communication, which simplifies the process of connecting your Android device to an Arduino UNO via Bluetooth. This includes Bluetooth Classic (used by modules like HC-05 and HC-06) and Bluetooth Low Energy (BLE) support.

4- Beginner-Friendly: App Inventor is designed with beginners in mind. Its user-friendly interface and intuitive blocks-based programming make it accessible to individuals who are new to programming or electronics.

5- Real-Time Testing: You can connect your Android device to your computer and test your app in real time using the MIT AI2 Companion app. This immediate feedback helps you troubleshoot and make adjustments on the fly.

6- Arduino-Compatible Libraries: App Inventor offers extensions and libraries specifically designed for Arduino communication. These extensions provide pre-built blocks that simplify the process of sending and receiving data between the Android app and the Arduino.

7- Community and Resources: MIT App Inventor has an active community and a wealth of online resources, tutorials, and sample projects. This means you can find help and guidance as you work on your project.

8- Sensor Integration: You can easily integrate various sensors and features of your Android device, such as the accelerometer, GPS, camera, and more, into your mobile application.

9- Cross-Disciplinary Learning: App Inventor bridges the gap between programming and hardware, making it an excellent tool for learners interested in both software and electronics.

While MIT App Inventor is a powerful tool for creating mobile applications that communicate with Arduino boards, it's important to note that it might have some limitations when it comes to complex applications or advanced features. For more advanced projects, you might eventually need to transition to traditional programming languages and development environments. However, App Inventor remains a valuable entry point for beginners and those looking to quickly prototype and deploy simple mobile applications for Arduino-based projects.

The components needed to use the HC-06 Bluetooth module, a lamp and a relay  with the Arduino UNO

To use the HC-06 module  and LED with the Arduin UNO, you will need a few components and connections. Here's a list of the required items:

1- Arduino UNO board:

Arduino Uno

The Arduino UNO board is a popular microcontroller board based on the ATmega328P microcontroller. It is one of the most commonly used Arduino boards and provides a versatile platform for creating interactive electronic projects.

The Arduino UNO board is suitable for beginners and experienced users alike, offering a flexible and accessible platform for prototyping and building various electronic projects, from simple LED blinking to complex robotics and home automation systems.

2- HC-06 Bluetooth Module: 

HC-06 Bluetooth Module

The HC-06 Bluetooth module is a popular and inexpensive Bluetooth module that allows wireless communication between devices over short distances. It is commonly used for projects involving Arduino and other microcontroller platforms. The HC-06 module is a Bluetooth version 2.0 module that supports the Bluetooth Serial Port Profile (SPP), making it relatively easy to interface with microcontrollers like the Arduino.

3- Relay Module:

You'll need a relay module that is compatible with the Arduino UNO and can switch the high-voltage lamp. Ensure it's rated for the voltage and current required for your lamp.

4- Lamp (220V):

The lamp you want to control, which is rated for 220V. Ensure it's in working condition and safe to use.

5- Power Supply for the Lamp:

You'll need a power source for the lamp, typically a 220V AC power supply.

6- Wiring:

Various wires and cables for connecting the components in your circuit.

7- Breadboard:

Test plate

A breadboard is a useful tool for creating temporary electronic circuits. It allows you to connect components without soldering.

8- Jumper wires:

Jumper wires

These wires are used to make connections between the Micro:bit, HC-06 Bluetooth Module, a lamp, a relay and breadboard.

Mounting the Arduino UNO with the HC-06 Bluetooth module , a lamp and a relay

To mount the Arduino UNO board with the KY-032 infrared sensor, a lampa and a relay, you can follow these steps:

1- Connect the HC-06 Bluetooth Module to the Arduino UNO board:

- Connect the VCC pin of the HC-06 Bluetooth Module to the 5V pin on the Arduino UNO board.

- Connect the GND pin of the HC-06 Bluetooth Module to the GND pin on the Arduino UNO board.

- Connect the TXD pin of the Bluetooth module to pin 6 of the Arduino.

- Connect the RXD pin of the Bluetooth module to pin 7 of the Arduino.

2- Connect the Relay to the Arduino UNO:

- Connect the relay's control pin (S) to pin 2 of Arduino UNO board.

- Connect the pin (+) of relay to pin 3.3V of Arduino UNO board.

- Connect the relay's ground pin (GND) to the Arduino UNO's GND.

3- Connect the Lamp and the power supply to the Relay:

- Connect one of the lamp's wires to the relay's common (COM) terminal.

- Connect the phase (live) wire of the power supply to the normally open (NO) terminal of the relay.

- Connect the neutral wire of the power supply directly to the neutral wire of the lamp.

Mounting the Arduino UNO with the HC-06 Bluetooth module , a lamp and a relay

Mounting the Arduino UNO with the HC-06 Bluetooth module , a lamp and a relay

Turn on a lamp connected to the Arduino UNO board by a smartphone via Bluetooth with Arduino IDE and App Inventor

To control a lamp connected to an Arduino UNO board using a smartphone via Bluetooth, you can use MIT App Inventor to create a mobile application and then interface it with the Arduino code. Here's a step-by-step guide to help you get started:

Step 1: Create the Arduino Code:

Step 2 : Create the MIT App Inventor Mobile App:

1- Open MIT App Inventor (ai2.appinventor.mit.edu) and create a new project.

2- Drag and drop the following components onto the screen:

1 ListPicker (choose_hc06)

1 Button (control_lamp)

BluetoothClient (BluetoothClient1)

Here is an example of application design with App Inventor

3- Add the BluetoothClient component to your project.

- The "BluetoothLE1" extension indeed refers to a specific extension for MIT App Inventor which allows you to manage Bluetooth Low Energy (BLE) communication in your mobile applications. This extension facilitates the interaction between your App Inventor application and BLE devices, such as sensors, trackers, wearables, etc.

- The "BluetoothClient1" extension in MIT App Inventor allows you to create mobile applications that can connect to Bluetooth devices, such as serial Bluetooth modules (eg HC-06) connected to microcontrollers, Bluetooth audio devices, etc. . This extension facilitates communication with these devices using serial Bluetooth connections.

4- Create the following blocks:

a- Starting with Android 12, Bluetooth permissions have been enhanced to improve security and user data protection. This is why we must declare the authorizations that your application needs in the AndroidManifest.xml file. For Bluetooth, you'll need to include ACCESS_FINE_LOCATION, BLUETOOTH_SCAN, and possibly BLUETOOTH_CONNECT permissions, depending on the features you're using.

5- When choose_hc06.AfterPicking

- Call BluetoothClient1.Connect: DeviceAddress = (address of your Bluetooth module)

- When control_lamp.Click (for lamp on) ,Call BluetoothClient1.SendText: Text = "on"

- When control_lamp.Click (for lamp off) ,Call BluetoothClient1.SendText: Text = "off"

Download aia project Download apk file

 

Step 3 : Test the System:

1- Upload the Arduino code to the Arduino UNO board.

2- Pair your smartphone with the Bluetooth module on the Arduino.

3- Install and open the MIT App Inventor app on your smartphone.

4- Click the "Connect" button to establish a Bluetooth connection.

5- Click the "Control Lamp" button to light up the Lamp, and click again the "Control Lamp" button to turn it off.

With these steps, you've successfully created a mobile app that can control an Lamp connected to your Arduino UNO board via Bluetooth. This example demonstrates a basic implementation, and you can further customize and expand the functionality based on your project requirements.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info