Robot arm to push buttons

What i want to do is code something simple thing that an arm that extends out forward and pushes a button, then retracts. With a couple other arms to push other buttons, it would be to control the speed of a fan or on/off. The fan controller is to create "wind" in my grow room, even tho its osscilating, in the real world, its not windy all the time. So for that id like to have something that says

pick a number between 1 and 10
assign that number to the time to wait while the fan is powered off
turn fan off
wait assigned time
pick another random number between 5 and 20
assign number to time to wait while
turn fan on
wait
loop

Code wise, i could do it in python very easily, but not on the arduino, id need some help

Also is like to control the on/off of a surge protector. So i can make a homemade "timer" and power down my massive cisco switches on a schedule. It would probably use the same script, and possible since I have two arduinos now

How do i go about this?

The simplest way is to use the servo library and just use servos to push the buttons if you cannot modify the fan to just connect to the buttons directly.

Or just use a power switch tail or similar to turn the fan on and off under Arduino control - or drop the requirement for randomness and just use an ordinary domestic digital timer.

Using servos etc to push physical buttons strikes me as potentially quite difficult to make reliable - the problem seems much more feasible from the electrical side.

For the code, first go into the examples that come with your IDE and choose from 2. Digital->BlinkWithoutDelay

Learn that, every line of code until it makes sense and ask what you need to.
It is how to make things happen on time and most all of it is comments, not code.

  • Note: on most Arduinos, there is already an LED on the board
    that's attached to pin 13, so no hardware is needed for this example.

I make a small but important change to the example though. Time variables should all be unsigned, not signed variables. With unsigned long the rollover won't make a difference except to limit the longest interval you can measure to 49.7-some days. With signed long the rollover will either screw things up or the code gets messy.

/* Blink without Delay
 
 Turns on and off a light emitting diode(LED) connected to a digital  
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.
 
 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.
 
 
 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen

 modified to use unsigned long for TIME variables 15 Apr 2013
 
 This example code is in the public domain.

 
 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// constants won't change. Used here to 
// set pin numbers:
const int ledPin =  13;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
// next line changed 15 Apr 2013
unsigned long previousMillis = 0UL;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
// next line changed 15 Apr 2013
unsigned long interval = 1000UL;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the 
  // difference between the current time and last time you blinked 
  // the LED is bigger than the interval at which you want to 
  // blink the LED.
// next line NOT changed 15 Apr 2013, they got that one right 
  unsigned long currentMillis = millis();

// next line changed 15 Apr 2013, > changed to >=
  if(currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Short Version for easier viewing:

// BlinkWithoutDelay --- public domain code 
 
const int ledPin =  13;          // the number of the LED pin
int ledState = LOW;             // ledState used to set the LED

unsigned long previousMillis = 0UL;        // will store last time LED was updated
unsigned long interval = 1000UL;           // interval at which to blink (milliseconds)

void setup() 
{
  pinMode(ledPin, OUTPUT); // the pin will start as LOW by default
}

void loop()
{
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis >= interval) 
  {
    previousMillis = currentMillis;   
    ledState ^= 1;
    digitalWrite(ledPin, ledState);
  }
}