How to Use Arduino UNO Q With Potentiometer

by DIYables in Circuits > Arduino

28 Views, 0 Favorites, 0 Comments

How to Use Arduino UNO Q With Potentiometer

arduino-uno-q-potentiometer-cover.jpg

This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-potentiometer

A potentiometer lets you set a value by turning a knob, useful for volume, brightness, or motor speed control. This guide connects one to the Arduino UNO Q, reads its ADC value on the STM32 MCU, converts it to voltage, and uses the Linux side with Bridge to report the current reading remotely over Telegram.

Supplies

Wiring

arduino-uno-q-potentiometer-wiring-diagram.jpg

The potentiometer has three pins. Connect GND to the Arduino UNO Q's GND, VCC to 3.3V (the MCU on UNO Q runs at 3.3V, not 5V), and the output (wiper) pin to analog input A0. A0 is read by the STM32 MCU side of the board, not the Linux MPU side.

How It Works

Turning the knob changes the resistance between the wiper and GND/VCC, which changes the output voltage proportionally: 0V at one end, 3.3V at the other, and anything in between follows (angle / ANGLE_MAX) x 3.3V. The STM32 MCU on UNO Q has a 12-bit ADC, giving readings from 0 to 4095 with a 3.3V reference, unlike the 10-bit, 0-1023 ADC on many other Arduino boards. Convert ADC to voltage with voltage = adc_value mapped from 0-4095 to 0-3.3.

Code

The MCU sketch reads A0 with analogRead(), converts the value to voltage, and exposes a Bridge.provide() function so the Linux MPU can request a reading. The MPU can't read the potentiometer directly since it's wired to the MCU, so it calls Bridge.call() to get the ADC value and voltage. A Python script running in Arduino App Lab on the MPU side connects to a Telegram bot: sending /read triggers a Bridge call to the MCU and returns the current reading. Never use /dev/ttyHS1 or Serial1 directly, they're reserved for the Arduino Router that carries Bridge traffic.

arduino-uno-q-potentiometer.ino - the sketch from the tutorial, unchanged.

/*
* This Arduino UNO Q code was developed by newbiely.com
*
* This Arduino UNO Q code is made available for public use without any restriction
*
* For comprehensive instructions and wiring diagrams, please visit:
* https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-potentiometer
*/

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void setup() {
// nothing to set up
}

void loop() {
// Read ADC value from pin A0 (12-bit: 0-4095 on Arduino UNO Q)
int adc_value = analogRead(A0);
// Convert ADC value to voltage (3.3V reference on Arduino UNO Q)
float voltage = floatMap(adc_value, 0, 4095, 0, 3.3);

// TO DO: use adc_value or voltage in your logic here
// Example: map to a 0-100 scale
// int level = map(adc_value, 0, 4095, 0, 100);

delay(500);
}


Things That Go Wrong

If readings seem stuck at 0 or max, check that the output pin is wired to A0 and that VCC goes to 3.3V, not 5V. If Telegram doesn't respond to /read, confirm the MCU sketch with the Bridge.provide() function is uploaded and running before starting the Python script, and that YOUR_BOT_TOKEN has been replaced with the real token from @BotFather.

Full Tutorial

The complete tutorial, wiring diagram and code explanation: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-potentiometer