user84598: I am trying to automate a existing system that uses Joystick as its input to move the Motors in x&y directions. I actually want to emulate arduino to exactly do what the joystick is doing by just emulating the joystick through arduino. Joystick has 4 wires
1- 5Volt
2- Ground
3- x-axis
4- Y-axis
Actually i want arduino to map in such a way that it's only two digital pins are used to connect with joystick cable 3 & 4 and process inputs exactly in such a way that system thinks that as it is the input from the joystick. I just don't want to mess with the electronics of the existing system. That's why just trying to hack into joystick.
UPDATE: i have checked the Joystick for simple voltage and Resistance Measurements.
It seems like it is 1KOhm Pot.

user67540: Maybe "DS3502 I2C Digital 10K Potentiometer" will work. I am interested to hear if it really works as a joystick pot replacement because I have never used it.

user84600: Based on your wiring information, this looks like an analog joystick. You specified using two digital output pins to emulate the joystick to the target device.
The way to do this is to use PWM and a simple resistor-capacitor filter to convert the digital output to an analog 0-5v signal.
Here is some information about PWM:

Arduino and PWM The Arduino IDE has a built in function
“analogWrite()” which can be used to generate a PWM signal. The
frequency of this generated signal for most pins will be about 490Hz
and we can give the value from 0-255 using this function.
analogWrite(0) means a signal of 0% duty cycle.
analogWrite(127) means a signal of 50% duty cycle.
analogWrite(255) means a signal of 100% duty cycle.
On Arduino Uno, the PWM pins are 3, 5, 6, 9, 10 and 11. The frequency
of PWM signal on pins 5 and 6 will be about 980Hz and on other pins
will be 490Hz. The PWM pins are labeled with ~ sign.

Here is a tutorial on converting the PWM signal to an analog voltage level:

The RC filter is a simple circuit element used to convert a pulsed
signal to a flatter signal. The key concept is that the capacitor
shunts the varying voltage to ground, producing a DC voltage.


84598: <p>I am trying to automate a existing system that uses Joystick as its input to move the Motors in x&amp;y directions. I actually want to emulate arduino to exactly do what the joystick is doing by just emulating the joystick through arduino. Joystick has 4 wires
1- 5Volt
2- Ground
3- x-axis
4- Y-axis</p>
<p>Actually i want arduino to map in such a way that it's only two digital pins are used to connect with joystick cable 3 &amp; 4 and process inputs exactly in such a way that system thinks that as it is the input from the joystick. I just don't want to mess with the electronics of the existing system. That's why just trying to hack into joystick.</p>
<p>UPDATE: i have checked the Joystick for simple voltage and Resistance Measurements.
It seems like it is 1KOhm Pot.</p>
 67540: <p>Maybe &quot;DS3502 I2C Digital 10K Potentiometer&quot; will work. I am interested to hear if it really works as a joystick pot replacement because I have never used it.</p>
 84600: <p>Based on your wiring information, this looks like an analog joystick. You specified using two digital output pins to emulate the joystick to the target device.</p>
<p>The way to do this is to use PWM and a simple resistor-capacitor filter to convert the digital output to an analog 0-5v signal.</p>
<p><a href="https://create.arduino.cc/projecthub/muhammad-aqib/arduino-pwm-tutorial-ae9d71" rel="nofollow noreferrer">Here</a> is some information about PWM:</p>
<blockquote>
<p>Arduino and PWM The Arduino IDE has a built in function
“analogWrite()” which can be used to generate a PWM signal. The
frequency of this generated signal for most pins will be about 490Hz
and we can give the value from 0-255 using this function.</p>
<p>analogWrite(0) means a signal of 0% duty cycle.</p>
<p>analogWrite(127) means a signal of 50% duty cycle.</p>
<p>analogWrite(255) means a signal of 100% duty cycle.</p>
<p>On Arduino Uno, the PWM pins are 3, 5, 6, 9, 10 and 11. The frequency
of PWM signal on pins 5 and 6 will be about 980Hz and on other pins
will be 490Hz. The PWM pins are labeled with ~ sign.</p>
</blockquote>
<p><a href="https://www.instructables.com/Arduino-RC-Circuit-PWM-to-analog-DC/" rel="nofollow noreferrer">Here</a> is a tutorial on converting the PWM signal to an analog voltage level:</p>
<blockquote>
<p>The RC filter is a simple circuit element used to convert a pulsed
signal to a flatter signal. The key concept is that the capacitor
shunts the varying voltage to ground, producing a DC voltage.</p>
</blockquote>
