For simple servo setups, a 7805 regulating chip can have the output voltage increased using a small diode on the chip ground pin like below. There is a noticable servo performance improvement between 5v and 5.7v

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

I Haven't got any sensors to detect obstruction if that's what you mean. I have added code to make the sweep of the servo adjustable so the door closes slowly. I'm hoping that should be enough.

At the minute I have the hardware mostly finished. The main thing I need is a replacement servo arm as I managed to strip the teeth from the plastic one that the servo came with. A metal one is ordered. The power baluns are done and the servo mounting enclosure.

What I would like to do is fine tune the starting and finishing position of the servo.

Is it possible to use a potentiometer to adjust a value BUT have the adjusted value saved even when the pot is removed?

Is it possible to use a potentiometer to adjust a value BUT have the adjusted value saved even when the pot is removed?

That is certainly doable. You could have something as simple as a button (could even use one already on the project) that, when held down for a while, begins a subroutine that lets you use the pot to set the starting position, press button again to save value to EEPROM, set finish position with pot, press button again to save to EEPROM.

You can also have the subroutine change the appropriate pins to an input instead of an output, that way you wouldn't have a pin set as an input all the time and not really doing anything, although I doubt it would have any unintended results anyway.

Your code would simply load the start and finish values from the EEPROM on power up. Note the first time the device powers up the contents of the EEPROM could be random values, so be mindful of that.

You can make two local Long variables to store when a button is first pressed. The button would wait a certain period of time before entering the subroutine (which wouldn't actually need to be a function). Some boolean values could be used to control when settings are saved and when settings should be read from the stored values...

I've attached some code that verifies OK, but I haven't actually tested whatsoever. I think it would run pretty well though, although it would be great if others would give it a glance. The code doesn't have to block whatsoever waiting on the buttons to be held down long enough.

The pin value constants are all set to 0, so that would need to be changed. The EEPROM locations would also need to be set according to your needs (not sure if you're storing anything else). Also there is no software debounce for the buttons, hardware debounce would be preferable or adding a "readPin(int pin)" type of method that could handle a software debounce.

The code should allow for a button to be held for five seconds, the value of the potentiometer adjusting the value for the position, and then having that value saved to EEPROM when the button is pressed again. An LED will glow indicating that a position is being adjusted, and then turn off when the position is stored.

I've tried to comment a bunch to explain things, but feel free to correct or ask about it!

EDIT: It was really annoying downloading the attachment so I included the code in the post

//These variables store the positions for open and closedint positionOpen;int positionClosed;//These variables store the locations in EEPROM where the saved positions are storedconst int positionOpenLocation = 0;const int positionClosedLocation = 0;//These constants just store the pin valuesconst int setOpenValuePin = 0;const int setClosedValuePin = 0;const int potPin = 0;const int LEDPin = 0;//These values are used to store a button press and to check and see if it's still pressed for the required timelong buttonOpenTime = 0;long buttonClosedTime = 0;//These booleans keep track of when a button has been pressed, time stored, and we haven't registerred a low yetboolean buttonOpenPressed = false;boolean buttonClosedPressed = false;//These booleans control what parts of the loop execute, ensuring we're not setting both at the same time, etcboolean settingOpen = false;boolean settingClosed = false;//How long you want to have to hold the buttons down, in msconst long buttonHoldTime = 5000;

void setup(){

pinMode(LEDPin, OUTPUT);

//Read the stored values from memory, allows values to persist after power failure or reset//You only want these next two lines after the values have been saved at least once//or else your sevo might go to some random locationpositionOpen = EEPROM.read(positionOpenLocation);positionClosed = EEPROM.read(positionClosedLocation);}

void loop(){

//If you're not currently setting the closed value, and the setOpen value is at HIGHif(!settingClosed && digitalRead(setOpenValuePin) == HIGH){ //if this is the first read of a high set the buttonOpenPressed to true and record the time if(!buttonOpenPressed){ buttonOpenPressed = true; buttonOpenTime = millis(); //if the button's been pressed and you've been held down longer than the buttonHoldTime, set settingOpen to true }else if(buttonOpenPressed && millis() - buttonOpenTime > buttonHoldTime){ settingOpen = true; buttonOpenPressed = false; digitalWrite(LEDPin, HIGH); }}

//if you're setting the open positionif(settingOpen){ //Read the potentiometer position and store it, dividing by 4 because of the EEPROM's storage size positionOpen = analogRead(potPin) / 4;}

if(!settingOpen && digitalRead(setClosedValuePin) == HIGH){ //if this is the first read of a high set the buttonClosedPressed to true and record the time if(!buttonClosedPressed){ buttonClosedPressed = true; buttonClosedTime = millis(); //if the button's been pressed and you've been held down longer than the buttonHoldTime, set settingClosed to true }else if(buttonClosedPressed && millis() - buttonClosedTime > buttonHoldTime){ settingClosed = true; buttonClosedPressed = false; digitalWrite(LEDPin, HIGH); }}

No I'm not storing anything else... I think. I'm not at home at the minute but when I am I'll post the code I'm using. It's pretty basic compared to what's possible I'm sure but I've been learning as I go along.

Thanks for taking the trouble to put that bit of code together. I already have a load of momentary buttons and a couple of pots so if we can get it working that makes it easier for anyone who wants to do something like this themselves.

Although your particular use may be niche, I could certainly envision someone doing something similar with blinds in a house that could be raised and lowered at the appropriate times to help block the sun. Who knows, it's always amazing the ways people adapt each other's ideas for their own projects.