Adjustable Timer

HI there, I'm pretty new to arduino,and electronics so if anyone could help me out,it would be greatly appreciated. I want to make an adjustable timer (15 to 30 minute) I would like the adjustment to be done with a potentiometer having all the way left =15 minutes all the way right = 30 minutes this timer would run 1 relay,.... push a button and the realy would go closed for desired time,and then open.And stay that way until you pushed the button again. My thoughts are to get it going with my arduino then build a circuit with an attiny chip. I dont know how to make the potentiometer adjust the time.I havent seen any sketches on the web for time adjustment.I think i could use part of another sketch for the button to turn it on. Can this be done? Also could anyone show me a sample sketch? Any info is welcome,if you can think of an easier way let me know! Thank you very much, Andy

Basically i want to set the timer for anywhere from 15 to 30 minutes hit the start button,and power the relay for the desired time after time elapses relay shuts off and waits untill i push the button again goes through the same thing and waits for me to hit the button again. I know i could probably buy a timer that would do this like a christmas light timer or somthing like it,but what fun is that? Thanks, AndyFinck

I am pretty new to Arduino myself but I suppose you could run the potentiometer as a voltage divider and read the voltage using one of the Analog ports. In theory you should be able to get a voltage from 0-5 volts by using the potentiometer as a voltage divider. Make sure you have a 10M resistor connected from the analog port you want to use to ground because at least with my board when I try to run a positive circuit and get down to 0 volts (aka no reading) my boards analogs loves to read some crazy numbers unless i hook a 10M resister on it so I get a true 0 volt ground when the potentiometer reaches 0 volts.

After you got that on a breadboard and tested you ought to be able to assign your readings according to your time specs. Aka lets say 5 volts (1023 in code unless you remap it) = 15 minutes and 0 volts (0 in code) = 30 minute timer. You can keep this fully adjustable with a little bit of math conversion or you could assign specific cut offs for lets say every 30 seconds added. That's up to you.

Oh, and FYI I found that designing your initial circuit makes it a lot easier to write the code. Or at least for me. I have been building circuits, writing the code, then working out any issues rather then write a couple hundred lines of code only to find out I need to rewrite half of it because I was wrong on the hardware side of things or part of the hardware didn't react as i expected it to.

Search the playground for stopwatch, that will get you the counting down part. Then Review AnalogRead in the reference section - that will read the pot for you. Review Button in the Learning section.

Loop will be pretty simple. Read the pot see if the button was pressed. If it was, go thru loop reducing the "time" left every pass thru until done.

Pseudocode:

define variable, pinModes, internal pullup on button, etc.
void loop()
if (time_running == 0){  // not started yet
coundowntime = ((analogRead (pot) * conversion_factor))+15000) // make this whole multiples of 1000
if (digitalRead (button) == 0){
time_running = 1  // button was pressed (to ground)!
turn on relay}
}
if (time_running == 1){
//countdowntime = countdowntime - 1000
if (countdowntime == 0) {
time_running = 0
turn off relay}
else{
delay (1000)  // lazy way, better to keep track of elapsed millis() - but its late, I'm going to bed!
}
} // end loop