4 pots for 1 analog output

Hi everyone,
I am in the middle of a project. Following are my requirements.

  • To use 4 pots(10K), to control one analog output.
    Basically, i am using 2 potentiometer joysticks(2-axis), which has one pot in each axis.so 2x2=4pots.

I am getting analog inputs from 4 pots using arduino 5V and getting analog inputs (A0,A1,A3,A4) from 0~1023. then I map it from 0~1023 to 0~255.
I want that every time any joystick is moved, it should change analog output on pin 9.
What it is doing is that it is changing output from only one potentiometer (analog input) at a time, while all inputs are serially monitored to be varying. Also each pot individually work for pin 9 but does not work collectively.
Need Suggestions.
P.S : I need 0~255 to have 0~5V signal for a driver circuit, and I have used certain IF conditions to switch relays with each direction the joystick is moved to. e.g val>128 is right direction, so relay X is on from pin 2, while 0~5v signal is sent from pin 9 to driver circuit.

Posting your sketch might help readers know what you're doing and make suggestions....

safyan:
I am in the middle of a project. Following are my requirements.
I want that every time any joystick is moved, it should change analog output on pin 9.

What it is doing is that it is changing output from only one potentiometer (analog input) at a time, while all inputs are serially monitored to be varying. Also each pot individually work for pin 9 but does not work collectively.

Your 'requirements' are too vague to implement. Unless your sketch has lots of comments that provide a detailed specification you should say EXACTLY what you want the sketch to do.
From your description there appears to be a programming error in your sketch. Since you did not include your sketch I can't provide any more detail. I suggest you post your sketch, describe what you intended it to do, and describe what it is doing differently from what you intended.

How do you decide which pot impacts the PWM for pin 9? I think it would be difficult to move a joystick and not have both pots change value at the same time. How do you decide which value to have pin 9 represent then?
And then you have 4 other outputs also that are controlling relays when the analog inputs are certain levels?

Hi,

I want that every time any joystick is moved, it should change analog output on pin 9.

From your sketch do you want to digitalWrite or analogWrite.
analogWrite outputs a PWM signal, not a DC voltage level.
What model Arduino are you using?
You setup is very brief, where are your input and output declarations.
Like pinMode(9, OUTPUT);
pinMode(UpRight, OUTPUT);
?
What are all the relay outputs for?
Thanks. Tom... :slight_smile:

Thanks for your interest Tom.

I want 5V output at extreme positions, and that can only be achieved by either giving 255 or digital high. As far as I know, analog pins can also be used as digital write.

Model is UNO.
pins are declared at the top. while you do need to declare analog out as pinmode. simply using analogWrite declares them as output.
the relays are certain outputs i want to use while in the respective direction.

Hi
Did you write this sketch all at once or in stages?
Do you have a sketch with just detecting any joystick movement?

All you have to do is poll each analog input and store its value, comparing it with the previously polled value.
If the difference between the the values is greater than a set value, then turn on output 9.
Get that working then continue with your relay driving.

Note that sampling analog inputs sequentially can be a problem with input values of one input influencing the values on the next.
Why?
The controller only has ONE ADC, it switches the ADC from input to input to read them.
The input of the ADC has a series resistor and a small capacitor between the ADC and gnd.
When sampling, if you change inputs there is the chance of the previous input level still being on the capacitor, making the next value inaccurate.
The trick is to read the input twice, and not use the first analogRead.
This will guarantee that the value read is true from the input selected.

Tom.... :slight_smile:

I have written this code in stages.
in my code, I am calling output() in every IF loop.
In Output(), i am using analogWrite (9,X);
this X is changing accurately as I require from every loop to change it. but its only giving output from val3. even if I change the sequence. using other joystick first. resetting and using some other direction of joystick. it does not simply give any analog out, while digital outputs in those respective loops also work(e.g pin2,3 etc).

Hi,
Okay, where are you storing the value from the analogRead from A0 to compare with the next analogRead from A0, so you can compare and thus detect that the joystick has moved?

Tom... :slight_smile:

I am serially monitoring all the analogRead values and they are seen to be changing.
what ever value the internal variables have, they do not matter until and unless it goes in that loop.

Hi,
So you are detecting if the joysticks move into differently defined regions, ie a matrix?
With joystick centered the centre of the matrix is indicated.

Tom... :slight_smile:

Yes, and that specific region gives digital output too on their respective pins while giving analog output on pin 9.
e.g turning right give digital output on 2 and analog output on 9(0~255). turning right gives digital output on 3 and similarly analog output is changed on 9(0~255). and so on

Hi,

I am serially monitoring all the analogRead values and they are seen to be changing.

Yes they are changing in the serial monitor, but how does the program detect movement and D9 HIGH?

Tom... :slight_smile:

Hi,
How do your regions map to 4 pot outputs, can you supply a diagram of regions and limits of pot values?

Tom... :slight_smile:

I have posted the code in this thread, you can see in that how have I separated the regions.

Hi,
If val2 is on the centre, making pin 9 LOW.
What happens if val3 is also at the extreme, pin 9 HIGH.

Tom... :slight_smile:

well it goes into the loop which has value changing, X does change.

I have deleted the ones giving LOW output to pin 9.
now all the joysticks works fine and they do change analog output. but the output should be 0 in the centre. while it stays on some random value at idle condition.
what should be condition for that?

safyan:
I have posted the code in this thread, you can see in that how have I separated the regions.

I'm sorry but I can't find your sketch anywhere in this thread. Could you post it again?

Thanks all, I had it figured out. it was stuck in a loop.