Pelatihan Mikrokontroler RC via Bluetooth September 2024 Pertemuan 3
Table of Contents
Introduction
This tutorial is designed to guide you through the fundamentals of using RC (Remote Control) microcontrollers via Bluetooth. It is based on the training session from ALKA TECHNOLOGY and aims to provide practical skills for working with microcontrollers, particularly in remote control applications. Understanding this technology can enhance your projects in automation, robotics, and IoT.
Step 1: Setting Up Your Microcontroller
-
Gather Required Components
- Microcontroller (e.g., Arduino)
- Bluetooth module (e.g., HC-05 or HC-06)
- Power supply (battery or USB)
- Jumper wires
- Breadboard (optional for prototyping)
-
Connect the Bluetooth Module
- Connect the VCC pin of the Bluetooth module to the 5V pin on the microcontroller.
- Connect the GND pin of the Bluetooth module to the GND pin on the microcontroller.
- Connect the TX pin of the Bluetooth module to a digital pin on the microcontroller (e.g., pin 10).
- Connect the RX pin of the Bluetooth module to another digital pin on the microcontroller (e.g., pin 11).
-
Install Necessary Libraries
- Open your Arduino IDE.
- Go to Sketch > Include Library > Manage Libraries.
- Search for and install the "SoftwareSerial" library if you plan to use multiple serial ports.
Step 2: Writing the Code
-
Basic Code Structure
- Start with including the necessary libraries:
#include <SoftwareSerial.h>
- Start with including the necessary libraries:
-
Define Pin Variables
- Set up variables for the Bluetooth module connection:
SoftwareSerial BTSerial(10, 11); // RX, TX
- Set up variables for the Bluetooth module connection:
-
Initialize the Serial Connection
- In the
setup()
function, initialize serial communication:void setup() { Serial.begin(9600); BTSerial.begin(9600); Serial.println("Bluetooth Module is ready"); }
- In the
-
Read and Send Data
- In the
loop()
function, read data from the Bluetooth module and send it to the microcontroller:void loop() { if (BTSerial.available()) { char c = BTSerial.read(); Serial.write(c); } }
- In the
-
Upload the Code
- Connect your microcontroller to your computer and upload the code using the Arduino IDE.
Step 3: Pairing the Bluetooth Module
-
Enable Bluetooth on Your Device
- Turn on Bluetooth on your smartphone or computer.
-
Search for Devices
- Look for the Bluetooth module (usually named HC-05 or HC-06) and initiate pairing.
-
Enter the Pairing Code
- If prompted, enter the default pairing code, typically "1234" or "0000".
-
Test the Connection
- Use a Bluetooth terminal app on your device (like Serial Bluetooth Terminal) to send commands to the microcontroller.
Conclusion
You have now set up a basic RC microcontroller system using Bluetooth. This tutorial covered connecting a Bluetooth module, writing the initial code, and pairing your device. As a next step, explore adding sensors or actuators to your project for more complex applications. Experimenting with different commands and functionalities will deepen your understanding and capabilities in microcontroller programming.