Displacement sensor with a slide potmeter - Part 1

In this video I am talking about a simple setup which can be used as a precise displacement sensor. It consists of an Arduino Nano, an ADS1115 ADC, an LM317T based voltage regulator and a slide potentiometer.



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

Displacement measurement with a linear potmeter - part 2

Next
Next

Recent updates for the tensile testing machine