Measuring Voltage Across a Potentiometer

MEASURING VOLTAGE ACROSS A POTENTIOMETER

Parts List

  • CPX + USB Cable

  • Potentiometer

  • Alligator Clips (x3)

  • Resistor

At this point you've learned about analog to digital converters (ADC). It turns out that the CPX has 8 analog ports hooked up to a 3.3V logic 16 bit ADC. The input range on the ADC is 0 to 3.3V and the output range is 0 to 65536 which is 2^16 hence 16 bits. In order to get accustomed to the ADC on the CPX, we’re going to do a simple example where we measure the voltage drop across a potentiometer. You can read about potentiometers online if you wish. Basically though, a potentiometer is a variable resistance resistor that changes resistance by turning a knob. The knob changes the connection point of a wire and thus the length of the wire. This in turn changes the resistance. Potentiometers come in all shapes and sizes. Here are some examples.

Here’s my circuit all hooked up. Two legs are connected to 3.3V and GND while the middle leg of the potentiometer is connected to pin A2.

CAUTION!!!: Some potentiometers do not have enough resistance when turned all the way down. I suggest that you put a resistor in between the third leg and ground. Some experimenters have melted plastic or gotten really hot. One student even blew up a potentiometer.

There is a relevant Adafruit Learn Tutorial to help with the analogio module but I’ll explain the minimum required here to get some analog values plotted in Plotter and Python on your computer. First let’s take a look at some simple example code to read an analog signal and plot it using the Plotter.

In the example code above, lines 1-3 again import the necessary modules with analogio being the new module here. Line 5 creates the analog object by attaching pin A2 to the analog function. Lines 7-9 then simple read the analog value and print it to Serial and the Plotter. Running this code on my laptop and turning the knob on the potentiometer produces this output. My potentiometer has a very large knob on the front and is easy to turn. Some potentiometers have a small screw on top that you need to turn with a screwdriver. Turning the screw or the knob results in chaning the resistance and therefore changing the voltage read by the CPX.

For this lab I want you to spin the potentiometer all the way to one side and then the other while recording time and the analog value. I then want you to plot the data with time on the x-axis and voltage on the y-axis. Remember to convert a digital output to voltage you just need to use the equation below where D is the raw value from the analog port. 3.3V is the range of the ADC and 2^16 is the maximum value the ADC can represent.

After doing this experiment myself, this is the plot I obtain. The code is not provided as reading data and plotting has been discussed in a previous lab. From the screenshot though you can see how I convert the digital output to an analog signal.

NOTE THAT ON LINE 6 IT READS

time -= time[0]

Notice the minus sign in front of the equal sign. That effects a lot.

Your assignment for this lab is to do the same as I’ve done above. Wire up the potentiometer, read the analog signal and plot it in Python on your desktop computer.

I’ve made some youtube videos on first just creating the circuit and plotting the data and then another video where I write data to the CPX using method 3.

Turning in this Assignment

Once you've done that upload a PDF with all of the photos and text below included. My recommendation is for you to create a Word document and insert all the photos and text into the document. Then export the Word document to a PDF. For videos I suggest uploading the videos to Google Drive, turn on link sharing and include a link in your PDF.

  1. Include a video of you wiggling the potentiometer and watching the digital signal in the Plotter in Mu go up and down (make sure your face is in the video at some point and you state your name) - 50%

  2. Embed your plot of voltage vs time in a document and also include your code In Python both from the CPX and in Thonny or Spyder to plot - 50%

Last updated