Problem with potentiometer

I am using 3 potentiometer to control automatic sprinkler. The problem is that the 2 of this pot's aren't working properly. When I change their value in isn't going beetwen setted, but it is about max value. I checked with multimeter that the voltage on the input pins changes from 0-5V, so I guess that is correct. I changed pots beetween pins and exactly the same pots aren't working on diffrent pins, but the pot that was woking is still working on diffrent pin, so the adc is working probably. I run out of ideas what to do. Pls help. Using arduino pro mini 5V.

byte outputPin1 = 4;
byte outputPin2 = 5;
byte frequencyPin = A3;
byte durationTimePin = A2;
byte offsetTimePin = A4;

unsigned long time = 0;
unsigned long lastTime = 180;
int dayCount = 0;
int minCount = 0;

byte waitTime = 3;  //minut
byte frequency = 1;    //dni
byte durationTime = 2;    //minut*5
int offsetTime = 0;   //minuty

void setup() {

  pinMode(frequencyPin, INPUT);
  pinMode(durationTimePin, INPUT);
  pinMode(offsetTimePin, INPUT);

  pinMode(outputPin1, OUTPUT);
  pinMode(outputPin2, OUTPUT);

  Serial.begin(9600);
}

void loop() {

  while (millis()<=waitTime*60000 && dayCount == 0){   //First 3min for settings change

    frequency = analogRead(frequencyPin);
    frequency = map(frequency, 0, 1023, 7, 1);

    durationTime = analogRead(durationTimePin);
    durationTime = map(durationTime, 0, 1023, 12, 2);
    durationTime = durationTime*5;

    offsetTime = analogRead(offsetTimePin);
    offsetTime = map(offsetTime, 0, 1023, 16, 0);
    offsetTime = offsetTime*60;

    Serial.print(180 - millis()/1000);
    Serial.print("   Podlewać co: ");
    Serial.print(frequency);
    Serial.print(" dni przez: ");
    Serial.print(durationTime);
    Serial.print(" min zaczynając za: ");
    Serial.print(offsetTime);
    Serial.println(" min.");
  }

Help is not possible with so little information.
Show a block diagram of how you have the potentiometers wired. What are the resistance values of each potentiometer?

  • Make that 60000UL to ensure the calculation is correct to start with.
  • Don't pinMode() analog pins.

(neither of the above will have anything to do with your pots not reading right).
Your pots are suspect, from your description. What value resistance are they? Do you have access to an ohmmeter? A photo of one of the pots might illuminate a problem.

Simply your program (for troubleshooting). Print the raw A/D counts immediately after each analog read.

Get rid of millis and add a delay of 5 seconds or so. (again for troubleshooting.)

Report the results + what Arduino board are you using and how do you have the potentiometers electrically connected.

Hello bartek_bawer

Tell us the entire story about this control function.

I managed to solve the problem. For some reason the values that are read, by potentiometers are set byte. After changing it to int it all worked.

well, your byte problem might have been noticed, but your problem description said the ADC was working. Too bad.

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