Led affecting potentiometer reading

I'm using a linear potentiometer with an adc to measure the thickness of some parts.
I also have a flashing led on pin 13 to indicate the state of the machine to the operator.
The problem is, when the led is activated, I get a slightly different reading from the potentiometer. I am using an Adafruit Metro, and it happens even with the built in led on pin 13.
I am using single ended inputs for the adc, and would like to keep it that way if possible.
The problem is the same with external power vs usb.
Any ideas?
Thanks!

The A/D by default uses the Vcc, 5v power supply as its reference voltage . If this voltage varies then so will any external measured voltage.
If your potentiometer is wired between the 5v and ground , then you won’t see any change as the input voltage remains the same proportion of Vcc.
You can use the internal voltage reference to improve matters if measuring an external voltage . Also ...check your power supply is good ( not a 9v little battery ) and that your circuit is correct , pot value > 1kohm , Arduino not powering other devices ??

A quick try is use the 3.3V to power the pot, and I believe the problem will go away. If you have enough resolution problems solved, if not you have a problem on the 5V power side. Please note the USB and the 5V power supply are not the same to the Arduino. USB is about 4.5 because of a protection diode.

Thanks for the replys!
The adc and the potentiometer are both wired to the 5v and ground pin on the Arduino.
The pot is 5kohm. It doesn't seem to matter whether I use external power or usb for the Arduino.
I tried attaching the potentiometer to 3.3v but there was still an issue.
With a big enough resistor on the led, everything seems to work ok. I am thinking now that there is nothing wrong with the circuit, but I am maybe learning that differential inputs are the way to go when using high precision potentiometers.
If anyone has a different opinion about that, I'm all ears!

Only the pot must be wired to 5volt/GND/A0, not the A/D (whatever you mean with that).
Leo..

Sorry, I didn't really word that correctly. The pot is wired to 5v/GND/A0 and the adc VDC and GND pins are attached to the same 5v and ground.

I hope you did not attach them. This is already done internally.

As always, posting according to the forum guidelines could have avoided this conversation.
For proper help we need the sketch (inside code tags), and a diagram/picture of the project.
Leo..

Oh man, I just realized that. I'm really sorry. This is my first post and I am still new to the whole electronics thing.
So hopefully I am doing the right thing here. I read the "getting started" post, but I didn't really understand most of it.
I attached a jpg of the layout and the code.

The pot shown on the picture is just to represent a lmcr8 5kohm 1% pot: https://p3america.com/lmcr8-series/

Thanks again so much for your help, and sorry to leave this out!

#include <Wire.h>
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads1115; // Construct an ads1115 

int calibration_state;
const int status_led_pin = 13;
int status_led_counter = 0;
int x;
int probe_number;

int probe_reading[3];

int probe_sample1[3];
int probe_sample2[3];
int stationary_counter[3];

int printout;


void flashing_led()     //flashes the status led
{
if (status_led_counter < 1){
    status_led_counter++;
  }else{
    status_led_counter=0;
  }
  if (status_led_counter == 1){
    if (digitalRead(status_led_pin) == HIGH){
      digitalWrite(status_led_pin, LOW);
    }else{
      digitalWrite(status_led_pin, HIGH);
    }
  }
}


int measure_cane(int probe_number)   //take a measurement and return value
{
  int sample_difference;
  int result;
  //check to see if probe is engaged. If it is in one position for long enough, return its value.
  if (probe_reading[probe_number] > 100){              
    probe_sample2[probe_number]=probe_sample1[probe_number];
    probe_sample1[probe_number]=probe_reading[probe_number];
    sample_difference=probe_sample1[probe_number]-probe_sample2[probe_number];
    sample_difference=abs(sample_difference);
    if (sample_difference < 4){
      //count for how many cycles the probe has remained stationary
      stationary_counter[probe_number]++;
    }
  }else{
    //if probe disengaged, return everything to 0
    probe_sample1[probe_number]=0;
    probe_sample2[probe_number]=0;
    sample_difference=0;
    stationary_counter[probe_number]=0;
    result=0;
  }
  //if probe has remained stationary for long enough, save the last result of the probe
  if (stationary_counter[probe_number] > 3){
    result=probe_sample2[probe_number];
  }
  //Serial.print("sample difference: "); Serial.println(sample_difference);
  //Serial.print("stationary counter: "); Serial.println(stationary_counter[probe_number]);
  //Serial.print("result: "); Serial.println(result);
  return result;
}


void setup(void)
{
  Serial.begin(9600);
  Serial.println("Hello World!");
  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV)");

  ads1115.begin(0x48);  // Initialize ads1115 at address 0x48 (ground)
  
  calibration_state = 0;

  pinMode(status_led_pin, OUTPUT);
  
}

void loop() 
{
  if (calibration_state == 0){
     flashing_led();
  }

  int16_t adc0, adc1, adc2;
  adc0 = ads1115.readADC_SingleEnded(0);
  adc1 = ads1115.readADC_SingleEnded(1);
  adc2 = ads1115.readADC_SingleEnded(2);

  Serial.print("AIN0: "); Serial.println(adc0);
  Serial.print("AIN1: "); Serial.println(adc1);
  Serial.print("AIN2: "); Serial.println(adc2);
  Serial.println(" ");
  
  probe_reading[0]=adc0;
  probe_reading[1]=adc1;
  probe_reading[2]=adc2;
 
  
  printout=measure_cane(0);
  Serial.print("printout: "); Serial.println(printout);

  printout=measure_cane(1);
  Serial.print("printout: "); Serial.println(printout);

  printout=measure_cane(2);
  Serial.print("printout: "); Serial.println(printout);

  if (calibration_state == 0){
    
  }
  
  delay(1000);
}

This is the first time you told us that you use an ADS1115 to read the pot.
That explains the instability.

The ADS1115 is an absolute A/D, and should not be used to read a ratiometric source (like a pot).
You will get a better result if you just use the ratiometric A/D of the Uno.
Smoothing/oversampling code could get you a higher resolution, if needed.

Oh, and try not to share power/GND of the pot with other users on the breadboard.
Leo..

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.