Connect Arduino Potentiometer to BlueBot App via Bluetooth

Connect Arduino Potentiometer to BlueBot: In this guide, we’ll walk you through the process of connecting an Arduino to the BlueBot app using Bluetooth, and reading potentiometer values to control devices remotely. You will learn how to send potentiometer data to BlueBot and even reverse the potentiometer’s range based on your needs.

Connect Arduino Potentiometer to BlueBot: This simple project allows you to control and monitor potentiometer values using Bluetooth

Components Required:

  • Arduino board (e.g., Arduino Uno)
  • HC-05 Bluetooth module
  • Potentiometer
  • Jumper wires
  • Breadboard (optional)

Setting Up the Bluetooth Communication

Before diving into the code, ensure that your Arduino is properly set up with the HC-05 Bluetooth module. Connect the TX pin of the HC-05 to the RX pin of Arduino (pin 10 or 2 in this case), and the RX pin of HC-05 to the TX pin of Arduino (pin 11 or 3). Don’t forget to connect the GND and VCC pins for power.

Code to Send Potentiometer Data

We’ll use the SoftwareSerial library to communicate between Arduino and the Bluetooth module. This allows us to establish a Bluetooth serial communication using non-hardware serial pins (pins 2, 3, 10, 11, etc.).

cppCopy code#include <SoftwareSerial.h>

// Define the pin for the potentiometer
const int potentiometerPin = A0; // Potentiometer connected to analog pin A0
int potentiometerValue = 0; // Variable to store potentiometer value

SoftwareSerial btSerial(10, 11); // RX, TX pins for Bluetooth communication (connect to HC-05 module)

void setup() {
  Serial.begin(9600);         // Start serial communication for debugging
  btSerial.begin(9600);       // Start Bluetooth serial communication
  pinMode(potentiometerPin, INPUT);  // Set potentiometer pin as input

  delay(1000); // Wait for the Bluetooth connection to be established
}

void loop() {
  potentiometerValue = analogRead(potentiometerPin);  // Read the potentiometer value

  // Map potentiometer value to a range (0 - 1023)
  int potentiometerValueMapped = map(potentiometerValue, 0, 1023, 0, 1023);

  // Send potentiometer value to the Bluetooth device
  btSerial.print(potentiometerValueMapped);
  btSerial.print(";");

  delay(200); // Delay to avoid sending data too frequently
}

In this code:

  • We read the potentiometer value using analogRead().
  • We use map() to scale the potentiometer value, ensuring it fits the range of 0-1023.
  • Then, the potentiometer value is sent to the Bluetooth module via btSerial.print(), where it will be received by the BlueBot app.

Reversing the Potentiometer Value

If you want to reverse the potentiometer value, for example, so that turning the potentiometer clockwise sends higher values, you can modify the code like this:

cppCopy code#include <SoftwareSerial.h>

// Define the pin for the potentiometer
const int potentiometerPin = A0; // Potentiometer connected to analog pin A0
int potentiometerValue = 0; // Variable to store potentiometer value

SoftwareSerial btSerial(2, 3); // RX, TX pins for Bluetooth communication (connect to HC-05 module)

void setup() {
  Serial.begin(9600);         // Start serial communication for debugging
  btSerial.begin(9600);       // Start Bluetooth serial communication
  pinMode(potentiometerPin, INPUT);  // Set potentiometer pin as input

  delay(1000); // Wait for the Bluetooth connection to be established
}

void loop() {
  potentiometerValue = analogRead(potentiometerPin);  // Read the potentiometer value

  // Reverse the potentiometer value by subtracting it from 1023
  int potentiometerValueMapped = 1023 - potentiometerValue;

  // Send the reversed potentiometer value to the Bluetooth device
  btSerial.print(potentiometerValueMapped);
  btSerial.print(";");

  delay(200); // Delay to avoid sending data too frequently
}

Explanation of the Code

  • analogRead(): This function reads the potentiometer value, ranging from 0 to 1023.
  • map(): The map() function adjusts the potentiometer value to fit a specific range, though in this case, the value is already in the 0-1023 range.
  • Reversing the value: In the second code snippet, we reverse the potentiometer value by subtracting it from 1023. This makes the value decrease when the potentiometer is turned clockwise.
  • Bluetooth communication: We use SoftwareSerial to send the potentiometer values to the HC-05 Bluetooth module. The data is then transmitted to the connected BlueBot app for further use.

Testing the System

Once the code is uploaded to your Arduino:

  1. Pair your Bluetooth module (HC-05) with your mobile device.
  2. Open the BlueBot app on your phone or tablet.
  3. Establish a connection between the app and the Bluetooth module.
  4. You should start seeing the potentiometer values sent from the Arduino to the app, either directly or with the reversed behavior based on your code.

Conclusion

Connect Arduino Potentiometer to BlueBot: This simple project allows you to control and monitor potentiometer values using Bluetooth in real-time. Whether you’re sending data from your Arduino to the BlueBot app in a straightforward way or reversing the potentiometer’s range, this setup is great for learning about wireless communication and sensor data transmission.