Let's Workshop: Keyestudio Potentiometer and Slide Potentiometer

Posted by Sebastian Karam on

Here is a quick and simple introduction to using potentiometer modules. This will provide you with an entry point to using potentiometers as a means of control and help give you the confidence to begin using them in your projects.

This example will demonstrate the use of an Arduino UNO in monitoring an analog pin over the range of movement of the potentiometer component.

Components

  • 1pcs Arduino UNO or Compatible - LCAA100005
  • 1pcs Keyestudio Potentiometer Module - BIAA100017
  • 1pcs Keyestudio 10K Slide Potentiometer Module - BIAA100042
  • 3pcs Male to Female Jumper Cables - GBAA100002

Wiring

Wire the one of the two boards to the Arduino as can be seen in the images below, taking care to match the pin numbers. In the case of the slide, you only need to wire the VCC,GND and OTA.

 

Coding

The code consists of a definition, setup and loop. First the A0 pin is assigned followed by a varaiable to store the value read. This allows easier use later in your program. A setup informs the system that the pin is an input is an input and then lauches the serial connection. Next we enter the loop, where the value on the pin is read and stored in the variable declared earlier. Following that we send it to the serial monitor so that the value can be read on the screen.

Load the code below into the Arduino IDE and upload it to your board.

/*
  A simple program designed to setup and demonstrate the Keyestudio 
  potentiometer and slide potentiometer modules.
 
  The program monitors two analog pins and outputs the value to the
  serial monitor.
  
  modified 17th April 2019
  by Sebastian Karam - Flux Workshop
*/
int analogApin = 0; // define OTA/S signal pin
int analogA; // define variable to store value read from pin
  
void setup() {
  pinMode(analogApin, INPUT); // set the OTA/S signal pin as an input
  Serial.begin(9600); // launch the serial monitor
  Serial.println("Flux Workshop Example");
}
 
void loop() {
  analogA = analogRead(analogApin);  // read the voltage level on the A0
  Serial.println((String)"Position: " + analogA); // send the result to the serial monitor
  delay(200); // pause for a moment before repeating
}

Running

With the board loaded with the program and all the connections made the serial monitor will produce an output like the two seen below.

Standard rotary potentiometer

Slide potentiometer

What to try next?

  • Investigate manipulating the output read to control a variable scale, like volumne.
  • Update a screen regularly to produce a digital dial

Share this post



← Older Post Newer Post →


Leave a comment