I am working on a project that uses the arduino uno to take control of a joystick potentiometer. I have soldered wires onto the pot, and connected them to an analog pin and gnd of the uno. I have confirmed that by applying a voltage, I am able to get my computer to think that the joystick is pushing to the right. This involved adding a voltage to the pot, but to make the joystick appear to be in the opposite direction, I need to apply a negative voltage, or somehow drain the power away. Does anyone know of a solution to this using Arduino or any other electronic components? Thanks.
In what way is the Uno taking control of the potentiometer ? Have you simply soldered the analogue output pin and ground from the Arduino to the pot leaving the connections to the PC in place or have you connected it in some other way ?
The analogue output from the Arduino will always be 5V above ground. The PWM on/off duty cycle ratio makes the voltage appear to vary but it is really just being turned on and off for varying lengths of time.
The Arduino on its own can not produce a voltage which is negative with respect to ground. For that you will need external circuitry but that is not something that I know much about beyond possibly using an H bridge circuit which allows the polarity of its output to swing +/- depending on its inputs. Others with more knowledge of electronics than me will no doubt be able to comment, but it is important to understand how you have things connected at the moment.
The uno is connected in parallel to the pot. The original connections to the pc have been left in place.
A port pin capable of PWM signals can be used to generate a small negative voltage, using a couple of diodes and capacitors. I've attached a schematic. This circuit will generate about -3V from a 5V Arduino, as about 1.4 V are lost to the diodes. The size of the capacitors is not critical, but depends on the PWM frequency and you may need to use larger ones (e.g. 10 - 20 uF). The allowed current draw is small and cannot exceed a few milliamperes.
Naturally, the port pin you use must be initialized to PWM (which could be AnalogWrite), with a duty cycle of about 50%.
Thanks very much for this. I have constructed the circuit and tested it. I found that by altering the duty cycle, I can get voltages ranging from -3.99V to 0.32V at the junction connecting C1 and D1. I think this may not be quite what I am looking for though. The joystick voltages are 1.35V, 0.8V, and 0.29V for left, center, and right joystick positions respectively. I was aiming to apply a negative voltage to these to manipulate the final voltage value read by the joystick. Is there a better way of achieving this?
Look up an Op-Amp Amplifier. You'll need a separate Power supply to get negative voltage for your negative supply (You will be limited to the range of outputs based on your power supplies), but it will basically let you scale any input to an appropriate output.
As suggested by mirith, a simple operational amplifier circuit will scale 0-5 V from AnalogOut to any desired values. You will need a bipolar power supply for the op amp (at least +/- 5V).
The attached circuit is a difference amplifier with gain 1, that compares the port output voltage (0-5) to 2.5 V derived from +5 V by the voltage divider R3/R4. It will output -2.5V to 2.5V as the port outputs 0-5V. Just about any op amp will work, for example the LM324. To modify this circuit for other output voltages, look up the design principles by googling "difference operational amplifier circuit".
Two words: Digital Potentiometer.
That's what you want. Use a DS1844 chip. It's 4 channels (4 digital potentiometers in one). It's like 4 potentiometers that are microcontroller-controlled. You can use SPI or i2c to talk to the chip.
Despite what you may think, most analog joysticks are NOT using negative voltage. Each axis of an analog joystick is connected to an analog potentiometer. A potentiometer is like a resistor that will vary between a minimum and maximum resistance. 10k pots seem to be the most common.
What I would do is rewire the joysticks so that the pots on the joysticks are read from the Arduino, and the Arduino then outputs a value to the DS1844 for each of the axis, and the 3 pins for each of the channels on the DS1844 axis is connected to the original circuit. Now your joystick is read by the Arduino and output is fed to the original circuit for your digital potentiometers, and at any time you want, you can choose to ignore the joysticks and take control from your sketch. You're inserting the Arduino as a middle man between the joystick and the original circuit. I've done this to hack RC transmitters with great success.