Displacement measurement with a linear potmeter - part 2

In this video, I will show you how to make a very simple displacement sensor using a linear slide potmeter, a voltage regulator, an ADS1115 AD converter and an Arduino. I will also show you how to make a very simple calibration to know the absolute position of the wiper of the potmeter or to know the relative displacement.

Please check the previous video where I go into more details with some things.



Arduino source code

#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;  
 
//-------Variables-------------
int16_t channel_1, channel_2;
 
float voltage_1, voltage_2;
 
float distance_1, distance_2;
 
float percentage_1, percentage_2;
 
//-----------------------------
 
void setup() {
 
  Serial.begin(115200);
 
  //----Set default------
  ads.setSPS(DR_128SPS); //Sampling speed 128 SPS
  ads.setGain(GAIN_TWO); //PGA settings +/- 2.048 V
 
  ads.begin();
  //------------------------------------------------------
 
  Serial.println("ADS1115 linear potmeter");
 
}
 
void loop()
{
 readPotmeter_Diff();
 //readPotmeter_Sing();
 delay(1000);
 
}
 
void readPotmeter_Diff()
{
  channel_1 = ads.readADC_Differential_0_1(); //A0 + A1
  Serial.print("D= "); Serial.println(channel_1);
  channel_2 = ads.readADC_Differential_2_3(); //A2 + A3
 
  percentage_1 = (channel_1 / 327.68);
 
  Serial.print("p= ");  Serial.print(percentage_1,3); Serial.println(" %");
 
  voltage_1 = (channel_1 * 0.0625)/1000;
  Serial.print("U= "); Serial.print(voltage_1,6); Serial.println(" V");
  voltage_2 = (channel_2 * 0.0625)/1000;
 
  distance_1 = 0;
 
  distance_2 = 0;
 
}
 
void readPotmeter_Sing()
{
  channel_1 = ads.readADC_SingleEnded(0); //A0
  Serial.println(channel_1);
  channel_2 = ads.readADC_SingleEnded(1); //A1
 
  percentage_1 = 100 * (channel_1 / 32768);
 
  Serial.println(percentage_1, 2);
 
  voltage_1 = (channel_1 * 0.125)/1000;
  Serial.println(voltage_1,6);
  voltage_2 = (channel_2 * 0.125)/1000;
 
  distance_1 = 0;
 
  distance_2 = 0;
 
}

Previous
Previous

Arduino with TB6600 using AccelStepper library

Next
Next

Displacement sensor with a slide potmeter - Part 1