Button press input as Potentiometer output

Well I have an odd project I've been trying to figure out.

So far I've used two buttons to move a servo back and forth, one button would move the servo right, the other would move it left.

And I have this RC remote/transmitter that uses potentiometers as control inputs. I'd like to be able to use the two buttons to control the servo left and right but through the remote.

Basically each button will change a potentiometer output from the arduino if that makes sense.

I've literally bought the arduino micro about 3 hours ago and I've been messing with it and google for the last 3 hours trying to figure this out, but I don't have any idea of what I'm doing.

I would attach the code I was using to move the servo but I have lost it since then, and will try to update the post with it once I find it.

But please bear with me as I'm not all too good on coding and such, I haven't messed with it. I'm just looking for a bit of help since I'm only trying to do this one thing with it for now.

EDIT: I found the code I was using.

#include <Servo.h> 
 
Servo myservo; 
#define leftPin 2    //Active Low
#define rightPin 3   //Active Low
int pos = 90;
int delayPeriod = 50;  // increasing this slows down the servo movement

 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  myservo.write(pos); // center the servo
  pinMode(leftPin, HIGH);   // turn on pullup resistors
  pinMode(rightPin, HIGH);
} 
 
 
void loop() 
{ 
  if(digitalRead(leftPin) == LOW)  
  {                              
   // in steps of 1 degree 
   if( pos > 0)
      --pos;
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(delayPeriod);                      
  } 
  if(digitalRead(rightPin) == LOW)  
  {                              
   if( pos < 180)
       ++pos;
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(delayPeriod);        
  }
}

I have this RC remote/transmitter that uses potentiometers as control inputs. I'd like to be able to use the two buttons to control the servo left and right but through the remote.

If you want to use those actual buttons you will need to modify the RC transmitter hardware and have a spare channel to control. That should be quite easy but is probably not advisable if you can avoid it. In any case you would not need to use an Arduino to do it as you could connect the servo directly to the RC receiver.

What RC transmitter do you have ?

hondasarecool:
So far I've used two buttons to move a servo back and forth, one button would move the servo right, the other would move it left.

And I have this RC remote/transmitter that uses potentiometers as control inputs. I'd like to be able to use the two buttons to control the servo left and right but through the remote.

Basically each button will change a potentiometer output from the arduino if that makes sense.

In a word - NO

As I understand it you have two button switches connected to an Arduino - and you want to do something else. What, exactly?

Do you mean that you want to connect the R/C receiver to the Arduino and use the R/C transmitter to control the servos?

I have no idea how a "button will change a potentiometer output". Maybe you need to describe what you are thinking about in other words.

...R

Okay lets see if I can word this differently. Basically I have this quadcopter that using a potentiometer on the back of the remote tilts the camera. I wanted to try to have two buttons instead do this. Meaning one button would tilt the camera up and the other tilt it down. I was thinking if there was a way to translate those button inputs, so a 3 wire output that I can plug into where the adjusting potentiometer plugs into the remote.

In short I want to instead use two buttons as up and down in place of a potentiometer.

Don't know if that helps at all.

Your code right now should be able to drive a servo directly. The simplest solution is to hook a servo up to the Arduino, and mechanically connect that servo to the potentiometer on the back of the transmitter. A bit messy, but workable?

Or maybe this gives you some ideas: Digital Potentiometer -- The sample code just keeps incrementing the value that is written to the device. Instead, you would use your button up/down code to adjust the value.

so a 3 wire output that I can plug into where the adjusting potentiometer plugs into the remote.

Do you actually have an RC transmitter that allows you to plug in external controls ? As I asked previously, what RC transmitter do yo have ?

That link may help, though I'm surprised I hadn't thought of hooking the servo to the pot on the remote.

This is the one I'm trying to control. I know I CAN put a servo into the back of the remote to turn it but I'd rather not cut the back of the remote out. So instead of having the buttons turn a servo I'd like to instead have the buttons wired into it, but I'm not sure how.

Basically instead of outputting the command to the servo to move between 0 and 180 degrees of rotation, I want it to output the same way a Potentiometer does so that I can use that as the input on this one.

But I don't even know if that's even possible.

It's the standard original transmitter from dji. And many people have already replaced this same pot with a larger one to use a larger knob instead, and they all use a 5K pot.

Sounds like the digital pot I linked to in my previous post is just the answer. It's basically an electrically controlled trimmer pot. You would take the pot off of the transmitter board, run three wires from the board to the variable resistance pins of the digital pot, and then make the rest of the connections between the Arduino and the pot. The Arduino code can then send commands to the pot to change the resistance.

The link I gave above has some sample code. Here is another option that uses SPI instead of I2C: Digital Potentiometer - 10K - COM-10613 - SparkFun Electronics

Personally, I think SPI is easier to use and more robust than I2C: it is my preferred interface. While that page lists a 10k part, they are also available as a 5k part. That page doesn't have sample Arduino code to control it, but a Google search for "4131 Arduino" turned up lots of hits.

Another alternative: I just did a Google search on "up down digital potentiometer" and got some interesting hits. Rather than an SPI or I2C interface, there are digital pots that have discrete up/down inputs. These could be connected to switches directly, and no processor would be required. Of course, you will likely need to have some additional circuitry to debounce the switches: mechanical switches tend to bounce the contacts for a few milliseconds when they are activated, and this could cause the pot to make multiple steps for each button press. You might get away with a simple resistor/capacitor debounce circuit, or might need something more sophisticated.

Of course, this is the Arduino forum, so having a processor involved is the preferred solution. :smiling_imp: It would allow you to do any debouncing in software, and could let you get fancy with the button presses: for example long presses could automatically repeat the steps, pressing both buttons at the same time could go to a preset position, etc.

This is the one I'm trying to control. I know I CAN put a servo into the back of the remote to turn it but I'd rather not cut the back of the remote out. So instead of having the buttons turn a servo I'd like to instead have the buttons wired into it, but I'm not sure how.

Basically instead of outputting the command to the servo to move between 0 and 180 degrees of rotation, I want it to output the same way a Potentiometer does so that I can use that as the input on this one.

What does the pot you marked actually do ? What does it adjust when you turn it ?

- YouTube Here's a quick video I found (can't record mine since it's currently out of commission from a crash) that shows what the pot does.

And digital pots that have inputs? Where would I find those?

but of course this being an arduino forum (and since I just bought one) I'd love to be able to find a way to do it with it. Because it would be fun and I'd learn some stuff. Just not really sure how to do it.

hondasarecool:
Just not really sure how to do it.

Do a google search on "arduino digital potentiometer" and you will find a lot of reading to get you started. On the first page of results I saw several tutorials, including a video, that explain what they are and how to use them.

Sweet thanks. I'll look into that. Didn't even know a digital potentiometer was a thing.