Servo rotation direction?

I've got a project I'm working on here:

I've hooked a servo to a set of louvers that are to open and close depending on input from a temp sensor. I got it all hooked up, but due to space restrictions I was limited in servo placement. Now I found that the servo spins the wrong way! How can I make it rotate the opposite direction?

Here is the code I'm currently using:

// Controlling a servo position using a temperature sensor
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
// edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7
// edited again 7-4-2010 by crenn to simplify the code a little
// edited yet again 7-5-2010 by crenn to add features

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

//Constants
const unsigned char CONTROL = 7;            // digital pin used to detect if the system is on or off
const unsigned char temps = 0;            // analogue pin used to connect the temp sensor
const unsigned char MAX_VAL = 10;

//Main global varibles
char trigger = 0;                  // varible used to store the control pin value
unsigned int val;                              // variable to read the value from the analog pin

unsigned int updateAvgtemp(){
      static int history[MAX_VAL]={0};
      static unsigned char lastHist=0;
      static unsigned char numHist=0;
      unsigned int temp=0;
      unsigned char counter=0;
      unsigned char arcount=0;
      history[lastHist] = analogRead(temps);
      if(numHist<MAX_VAL)
            ++numHist;
      arcount=lastHist;
      ++lastHist;
      if(lastHist>=MAX_VAL)
            lastHist=0;
      temp=0;
      counter=0;
      do{
            temp+=history[arcount];
            arcount--;
            if(arcount>MAX_VAL)
                  arcount=(MAX_VAL-1);
            counter++;
      }while(counter < numHist);
      return (temp/numHist);
}

void setup()
{
  pinMode (CONTROL, INPUT);                  // sets the control pin to input
  myservo.attach(9);                        // attaches the servo on pin 9 to the servo object
  digitalWrite(CONTROL, LOW);            // ensure internal pullup resistor is disabled.
}
void loop()
{
  trigger = digitalRead(CONTROL);                  // read input of pin CONTROL  and store it
  if (trigger == HIGH){                                    // reads if pin CONTROL, if true, do this:
    val = updateAvgtemp();                        // read the value of the temp sensor (value with range of 1024)
    val = map(val, 350, 700, 5, 175);            // scale it to use it with the servo (value between 75 and 105)
    myservo.write(val);                                    // sets the servo position according to the scaled value
  }
  else {
    myservo.write(50);                                    // sets servo position to 50 if above statment is false
  }
  delay(125);                                                // wait 25ms for the servo to move to it's new position and also 100ms until it gets the new value
}

could I just swap the (5, 175) to (175, 5) in the val=map section? :-/

could I just swap the (5, 175) to (175, 5) in the val=map section?

It probably took you longer to post the question than it would have to have tried doing it.

I see no reason why it would not work, but then I don't know what your hardware setup looks like. If the louvers move in the wrong direction as the temperature goes up and down, changing the map call is the way to fix it.

If I were at home and not at work I would have tried it lol. The louvers are supposed to be at position 50 (closed) when the computer is off (no voltage on pin 7). When the computer is on (5v to pin 7) it will run the loop, and the hotter the temp sensor gets the more it will open the louvers. Currently it sits at it's position 50 with no voltage to pin 7. When I apply voltage it tries to close them further instead of opening them.

here is a vew of the current setup from the bottom side

louvers closed

and opened

When I apply voltage it tries to close them further instead of opening them.

In that case, the change to the "to" range of the map function will take care of the problem.

Or, you could leave the map function as is, and move the servo to (180 - current output of map). If the current output is 5, move the servo to 180 - 5 = 175. If the current output is 175, move the servo to 180 - 175 = 5.

Thanks a ton! I'll try that when I get home tonight!

got it. I had to change the base servo setting, move the servo arm on the servo and swap the code. it works beautifully now!