Potentiomer as alternative to multiple switches on an analog input.

I'm new to this Arduino thing...so forgive me if there's anything wrong with the code or my concept. Any suggestions or alternate ways to do the same thing would be great.

I'm working on a project that will need to read and store a number of values ( as integers -- milliseconds from 0 to 1000 or so) to be used in a photo delay trigger. I decided in needed 10 values for the various delays so I was simply going to have a bunch of pots to allow me to dial in the values I wanted, read these as the sketch ran, and use them in the delay loops. So I realized I'd use up all those ports which I didn't really want to do.

In my testing of this POT vs switches idea, I've found it to be much easier than having to deal with the odd-ball values that the switch/voltage divider schemes come up with. It's just a nice clean 0-10 set of values.

  1. I want to have a pot let me set the delay value .. from 0-1023
  2. I want to store the values in Eprom once they are selected.

I've set up a 10k pot from +5v to gnd, and the wiper on an analog pin. and a second 10k pot from +5v to gnd, and the wiper on another analog pin. There's also a 'save setting' SP/NO pushbutton switch connected to a digital port.

When the menu select pot is at '0' (basically grounded) the sketch decides that is not in 'programming mode'. As soon as the pot moves out of 0 ohms the program will start reading it and decided at what point the wiper is at giving values from 0 to 1023.

(code tags added by moderator)

int menuSelectPot = 0;       // pot wiper connected to analog pin 0

int valueSelectPot = 0;       // pot wiper connected to analog pin 1

int saveSettingSwitch = 8;  // switch to 'capture' the current setting if the 
                                        // menu is on.

int myMenu=0;                  // value to store which menu is currently selected 

int settingValue = 0;          // variable to store the read value

void setup()
  pinMode(menuSelectPot, INPUT);  
  pinMode(valueSelectPot, INPUT);  
  pinMode(saveSettingSwitch, INPUT);  

void readSettings()
// for now this is just a dummy function 
// it will read the 10 stored settings
// from eProm and put them in an array
// and store them as integers in an array of 10 positions

void loop()

  //read the pot -- values will be from 0 to 1023
  //convert to values from 0 to 10 simply by dividing by 100
  myMenu = analogRead(menuSelectPot)/100;   

  //display the results on the lcd...


void doMenuDisplay(int menu)
  if (menu > 0 )
    lcd.print("Menu is ON: "); 

    // ... at this point 2 things will happen...
    //show the value on the screen 
    settingValue = analogRead(menuValuePot);   
    lcd.Print('Menu #');
    lcd.Print("   Value:");

    //check to see if we have pushed the save setting button
    if (digitalRead(saveSettingSwitch)==HIGH)
    // save the value to an eprom location
    //  not coded yet .... 
    delay(500);   // just to give us time to insure the setting is saved and our
                        // finger is off the save button.
    // will probably put a status message on the lcd to confirm save of the setting

    lcd.Println('Menu OFF');



Could also just go with a mechanical rotary encoder with detents. Uses 2 inputs also. Example http://www.digikey.com/product-detail/en/ACZ16NBR1E-15FD1-24C/102-1785-ND/1923380

Lot more solid feel for positions.

I would go with a button or two and the potentiometer.
With a long press go to your menu (menu=1) then longpresses save your set values from the potentiometer.So you dont have to build delays to set the pot, just let it scan as long as youre in menu for example and the buttons sets the right time when to save… short presses switch between your values, for that just a little variable that counts and is coded to write to the right position.
And after ten there is automatically menue exit or waiting for a long pressed button else it will start with first value.

If you use 2 or more buttons you can build a nice menue with |menu| buttons for example the gets really user friendly :slight_smile:

If you already got this idea, than its fine, if havent looked to deep to your code yet :slight_smile:
Just thought how i would get your idea done :slight_smile: