Potentiometer is affecting a value it should not be affecting? Can anyone help?

Hi, I'm using two variables that are going to be displayed on a LCD screen The setup looks like this:

Pressure: PRESSURE / MAXPRESSURE

PRESSURE = Variable that displays the analog value given from a flexiforce pressure sensor MAXPRESSURE = Variable that displays the analog value given from a potentiometer

The problem is that as I turn the pot, the PRESSURE goes up as well

So I start with this readout, and as I turn the potentiometer check out what happens. First value should only be affected by the flexiforce pressure sensor, but instead when it is left constant the potentiometer does affect it. Keep in mind the first value is PRESSURE (force sensor controlled) and the second value is MAXPRESSURE (pot controlled).

0/0 8/40 12/60 16/80 20/100

It's oddly linear too, but I have nothing to cause this 1:5 ratio.

Here is the section of the code where the variables are read, in void loop.

void loop() {
  
  //PRINT POTENTIOMETER READING
  int maxpressure = analogRead(pot); 
  maxpressure = map(maxpressure,0,1023,0,100);
  Serial.println("Potentiometer Reading: "); 
  Serial.println(maxpressure); 
  
  //DECLARE PRESSURE READINGS
  int pressure = analogRead(flexi);
  pressure = map(pressure,0,1023,0,100);
  Serial.println("Pressure Reading: "); 
  Serial.println(pressure);

The values above are what is displayed in the serial monitor (scaled down to 100 from 1023) and it is identical as to what is on the LCD. What am I doing wrong?

Here is the ENTIRE code for reference:

//LIBRARIES
#include <LiquidCrystal_I2C.h>
#include <Wire.h>  
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 

/* 
LCD Guidelines:

GND - GND
VCC - 5V
SDA - Pin A4
SCL - Pin A5
*/

//VARIABLES
int light = 5; //LED that lights up when too much pressure is applied
int up = 6; //switch pin
int down = 7; //switch pin
int flexi = A0; //pressure sensor 
int pot = A1; //potentiometer pin

//MILLIS VARIABLES
unsigned long previousMillis = 0;//Last time updated 
unsigned long seconds = 0;//Time in seconds

void setup() {
  
  //START SERIAL
  Serial.begin(9600);
  
  //DECLARATIONS
  pinMode(light, OUTPUT);
  pinMode(up, INPUT);
  pinMode(down, INPUT);
  
  //INITIAL STATES
  digitalWrite(up, HIGH);
  digitalWrite(down, HIGH);
  
  //INITIAL LCD DISPLAY
  lcd.begin(20,4);
  lcd.setCursor(0,0); 
  lcd.print("AYJ Corporation");
  lcd.setCursor(0,2); 
  lcd.print("Welcome to the");
  lcd.setCursor(0,3); 
  lcd.print("Cane Enable (v1.0)");
  delay(5000);
}

void loop() {
  
  //PRINT POTENTIOMETER READING
  int maxpressure = analogRead(pot); 
  maxpressure = map(maxpressure,0,1023,0,100);
  Serial.println("Potentiometer Reading: "); 
  Serial.println(maxpressure); 
  
  //DECLARE PRESSURE READINGS
  int pressure = analogRead(flexi);
  pressure = map(pressure,0,1023,0,100);
  Serial.println("Pressure Reading: "); 
  Serial.println(pressure);
  
  //LED TURNS ON IF TOO MUCH PRESSURE
  if(pressure>maxpressure)
  {
    digitalWrite(light, HIGH);
  }
  else
  {
    digitalWrite(light,LOW);
  }
  

  //GOING UP THE STAIRS 
  lcd.clear();
  if(digitalRead(up)==LOW) //If the switch is in this position...(reads this pin off) 
  {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= 1000) 
    {
    previousMillis = currentMillis;
    seconds ++; //Initiats timer countdown so that switch changes and pressure readings are instanteously, does not block like a delay
    }
    
    if ( seconds <= 5 ) //First 5 seconds...this happens!
    {
    lcd.backlight();
    lcd.setCursor(0,0);
    lcd.print("                    "); //Artificial clear for only one line
    lcd.setCursor(0,1); 
    lcd.print("                    ");
    lcd.setCursor(0,0);
    lcd.print("Instructions for");
    lcd.setCursor(0,1); 
    lcd.print("going up");  
    lcd.setCursor(0,3);
    lcd.print("Pressure:"); 
    lcd.setCursor(10,3);
    lcd.print(pressure);
    lcd.setCursor(13,3);
    lcd.print("/");
    lcd.setCursor(14,3);
    lcd.print(maxpressure); 
    delay(800);
    }
    
      if ( seconds > 5 && seconds <= 10 ) //Second 5 seconds...this happens!
      {
      lcd.setCursor(0,0);
      lcd.print("                    ");
      lcd.setCursor(0,1); 
      lcd.print("                    ");
      lcd.setCursor(0,0);
      lcd.print("Place strong foot");
      lcd.setCursor(0,1); 
      lcd.print("on next stair");
      lcd.setCursor(0,3);
      lcd.print("Pressure:"); 
      lcd.setCursor(10,3);
      lcd.print(pressure);
      lcd.setCursor(13,3);
      lcd.print("/");
      lcd.setCursor(14,3);
      lcd.print(maxpressure);     
      delay(800);
      }
      
        if ( seconds > 10 && seconds <= 15 ) //Third 5 seconds...this happens!
        {
        lcd.setCursor(0,0);
        lcd.print("                    ");
        lcd.setCursor(0,1); 
        lcd.print("                    ");
        lcd.setCursor(0,0);
        lcd.print("Place weak foot");
        lcd.setCursor(0,1); 
        lcd.print("on next stair"); 
        lcd.setCursor(0,3);
        lcd.print("Pressure:"); 
        lcd.setCursor(10,3);
        lcd.print(pressure);
        lcd.setCursor(13,3);
        lcd.print("/");
        lcd.setCursor(14,3);
        lcd.print(maxpressure);     
        delay(800);
        }
        
          if ( seconds > 15 && seconds <= 20 ) //Fourth 5 seconds...this happens!
          {
          lcd.setCursor(0,0);
          lcd.print("                    ");
          lcd.setCursor(0,1); 
          lcd.print("                    ");
          lcd.setCursor(0,0);
          lcd.print("Place cane");
          lcd.setCursor(0,1); 
          lcd.print("on next stair"); 
          lcd.setCursor(0,3);
          lcd.print("Pressure:"); 
          lcd.setCursor(10,3);
          lcd.print(pressure);
          lcd.setCursor(13,3);
          lcd.print("/");
          lcd.setCursor(14,3);
          lcd.print(maxpressure);     
          delay(800);    
          }
            if ( seconds >= 20) //After 20 seconds, reset the LCD and second counter
            {
              lcd.clear();
              seconds = 0;
            }
  }

  //GOING DOWN THE STAIRS
  lcd.clear();
  if(digitalRead(down)==LOW) //If the switch is in this position...(reads this pin off) 
  {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= 1000) 
    {
    previousMillis = currentMillis;
    seconds ++; //Initiats timer countdown so that switch changes and pressure readings are instanteously, does not block like a delay
    }
    
    if ( seconds <= 5 ) //First 5 seconds...this happens!
    {    
    lcd.backlight();
    lcd.setCursor(0,0);
    lcd.print("                    ");
    lcd.setCursor(0,1); 
    lcd.print("                    ");
    lcd.setCursor(0,0);
    lcd.print("Instructions for");
    lcd.setCursor(0,1); 
    lcd.print("Going down");  
    lcd.setCursor(0,3);
    lcd.print("Pressure:"); 
    lcd.setCursor(10,3);
    lcd.print(pressure);
    lcd.setCursor(13,3);
    lcd.print("/");
    lcd.setCursor(14,3);
    lcd.print(maxpressure); 
    delay(800);
    }
    
      if ( seconds > 5 && seconds <= 10 ) //Second 5 seconds...this happens!
      {    
      lcd.setCursor(0,0);
      lcd.print("                    ");
      lcd.setCursor(0,1); 
      lcd.print("                    ");
      lcd.setCursor(0,0);
      lcd.print("Place cane");
      lcd.setCursor(0,1); 
      lcd.print("on next stair");    
      lcd.setCursor(0,3);
      lcd.print("Pressure:"); 
      lcd.setCursor(10,3);
      lcd.print(pressure);
      lcd.setCursor(13,3);
      lcd.print("/");
      lcd.setCursor(14,3);
      lcd.print(maxpressure); 
      delay(800);
      }
      
        if ( seconds > 10 && seconds <= 15 ) //Third 5 seconds...this happens!
        {
        lcd.setCursor(0,0);
        lcd.print("                    ");
        lcd.setCursor(0,1); 
        lcd.print("                    ");
        lcd.setCursor(0,0);
        lcd.print("Place weak foot");
        lcd.setCursor(0,1); 
        lcd.print("on next stair"); 
        lcd.setCursor(0,3);
        lcd.print("Pressure:"); 
        lcd.setCursor(10,3);
        lcd.print(pressure);
        lcd.setCursor(13,3);
        lcd.print("/");
        lcd.setCursor(14,3);
        lcd.print(maxpressure); 
        delay(800);
        }
        
          if ( seconds > 15 && seconds <= 20 ) //Fourth 5 seconds...this happens!
          {
          lcd.setCursor(0,0);
          lcd.print("                    ");
          lcd.setCursor(0,1); 
          lcd.print("                    ");
          lcd.setCursor(0,0);
          lcd.print("Place strong foot");
          lcd.setCursor(0,1); 
          lcd.print("on next stair");     
          lcd.setCursor(0,3);
          lcd.print("Pressure:"); 
          lcd.setCursor(10,3);
          lcd.print(pressure);
          lcd.setCursor(13,3);
          lcd.print("/");
          lcd.setCursor(14,3);
          lcd.print(maxpressure); 
          delay(800);
          }
          
            if ( seconds >= 20) //After 20 seconds, reset the LCD and second counter
            {
              lcd.clear();
              seconds = 0;
            }
  }
  
  //MIDDLE STATE
  lcd.clear();
  if((digitalRead(up)==HIGH)&&(digitalRead(down)==HIGH)) //If the switch is in both these positions, IE the middle (both pins are on)
  {
    lcd.setCursor(0,0);
    lcd.print("Pressure:");
    lcd.setCursor(10,0);
    lcd.print(pressure); 
    lcd.setCursor(13,0);
    lcd.print("/");
    lcd.setCursor(14,0);
    lcd.print(maxpressure); 
    lcd.setCursor(0,1);
    lcd.print("1st # = Pressure Now");
    lcd.setCursor(0,2);
    lcd.print("2nd # = Max Pressure");
    lcd.setCursor(0,3);
    lcd.print("Do not exceed 2nd #!");
    delay(800);
  }
}

I can't see anything wrong in that snippet of code. I haven't fully checked the whole code.

Maybe the problem is in the wiring of your circuit.

Could you post a circuit diagram (hand drawn is ok) and/or a photgraph of your setup, please?

^ That.

Drawing of your sensors, with resistance values. Leo..

You need to clear line 3 of the lcd before writing the new values of pressure / maxpressure. Your leaving odd chars behind from the last time you wrote to it.

Mark

Mark -

Line 3 is refreshed every 8/10 of a second, with the delay(800) function.

JohnLincoln -

I checked and my potentiometer circuitry is fine.

Here is a simpler code to understand that experiences the same thing, in both serial monitor and the LCD. It is very strange. Potentiometer is hooked up fine…

//LIBRARIES
#include <LiquidCrystal_I2C.h>
#include <Wire.h>  
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 


//VARIABLES
int flexi = A0; //pressure sensor 
int pot = A1; //potentiometer pin

void setup() {
  
  Serial.begin(9600);
  
  lcd.begin(20,4);
  lcd.setCursor(0,0); 
  lcd.print("Wassup?");
  delay(2000);
  
}

void loop() {
  
  //DECLARE PRESSURE READINGS
  int pressure = analogRead(flexi);
  pressure = map(pressure,0,1023,0,100);
  Serial.println("Pressure Reading: "); 
  Serial.println(pressure);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Flexi Reading:"); 
  lcd.setCursor(15,0);
  lcd.print(pressure); 
  
  //PRINT POTENTIOMETER READING
  int potval = analogRead(pot); 
  potval = map(potval,0,1023,0,100);
  Serial.println("Potentiometer Reading: "); 
  Serial.println(potval); 
  lcd.setCursor(0,1);
  lcd.print("Pot Reading:"); 
  lcd.setCursor(15,1); 
  lcd.print(potval);
  delay(500);
  
}

Also, if I unhook the potentiometer all together the flexiforce affects the pot value being displayed....

Potentiometer is hooked up fine....

If you do not want to post pictures then just tell us how is it connected. Code side is ok. So must be something with wiring/power .

Here is a diagram I made

http://imgur.com/4OeAjL6

Enlarge it and you can make it out (due to limitations on CAD i used random arduino pins, ignore the numbers)

Otherwise...

Potentiometer -

pin 1 to GND bus pin 2 to arduino pin A1 pin 3 to 5V bus

Flexiforce -

1 pin to 5v as shown by tutorial 1 pin connected to both arduino pin A0 and through a resistor to GND as shown by tutorials

(tutorial = search up "how to hook up a flexiforce sensor")

Thread locked due to multiple cross-postings.

http://forum.arduino.cc/index.php?topic=314331

http://forum.arduino.cc/index.php?topic=314329.0

Unlocked again. However this still seems to be about pressure sensors.

Usually when one analog input modifies another the second one has too high a impedance (resistance). The A/D samples the input by charging or discharging a small capacitor. If the impedance is too high (>10K?) the capacitor will not reach the input voltage fast enough and some of the previous charge will be left on it. An easy way to reduce the problem is to read the same analog input pin twice and throw away the first reading. This gives the capacitor more time to reach the actual voltage.

Looking at your diagram, it looks like there could be something in the 5V line affected by the potentiometer prior to the flex sensor receiving voltage... I'm not an expert here, but perhaps having capacitors that each sensor draw from could resolve this by providing a "clean" and "true" 5v line with no affect to current?

My thought is the Pot is drawing current prior to the pressure sensor, so perhaps there is some kind of transient effect through the 5V line when the resistance is changed? Adding a capacitor in front of each sensor should give each sensor a "clean" 5V to work with and normalize your readings?

I could be way off, then again, I haven't had my coffee yet.... :D

My thought is the Pot is drawing current prior to the pressure sensor, so perhaps there is some kind of transient effect through the 5V line when the resistance is changed? Adding a capacitor in front of each sensor should give each sensor a "clean" 5V to work with and normalize your readings?

While this might be true, capacitor won't help.

@John

Thanks for your insight. The flexiforce pressure sensor recommends a 1 mega ohm resistor, connected to GND. Perhaps it is quite too large, however, the flexiforce itself carries a huge resistance too.

How would I go about reading a sensor twice and discarding the first? Just copy the code over again?

pressure = analogRead(flexi); //flexi = pin variable for the sensor
pressure = analogRead(flexi); // ??????
pressure = map(pressure,0,1023,0,100); 
Serial.println("Pressure Reading: "); 
Serial.println(pressure);

Something like this :

int readings[2] ;

void setup()
{
}

void loop()
{

for ( int i = 0, i < 2 , i++ )
{
readings[i] = analogRead(yourpin);
}

sensor_value = readings[1];

}

Thank you waski, I'll try it.

Unbelievable waski! It worked! So discarding the first value clears the leftover voltage or whatever they were talking about earlier on the thread, so now the potentiometer doesn't effect the pressure reading. Thanks! I'll post if I discover something else went wrong.

AYJCane:
How would I go about reading a sensor twice and discarding the first? Just copy the code over again?

pressure = analogRead(flexi); //flexi = pin variable for the sensor

pressure = analogRead(flexi); // ???
pressure = map(pressure,0,1023,0,100);
Serial.println("Pressure Reading: ");
Serial.println(pressure);

Yes. Exactly. There is no need for an array to store the two values. There isn’t even a need to store the first answer at all:

analogRead(flexi);  // start charging the input capacitor
pressure = analogRead(flexi); // finish charging the input capacitor and read the voltage

waski: While this might be true, capacitor won't help.

You're right, my bad. Read this thread before I had woken up so to speak. What I was thinking was something needs to be in place to eliminate any transients, voltage drop, variances -- essentially ensure that each sensor gets its own "clean and conditioned" power.