Multiple Servos on Heliostat

I am building a heliostat that uses photoresistors mounted on a base moved by two servos and uses two more servos for controlling the position of a mirror.

The tracker portion of the servo worked just great! But when I added the two mirror positioning servos they fail to respond. I am sure they are wired right because if I hook them to the tracker servo control lines they follow the position of the tracker servos perfectly.

Here is the code –

// This is the first working program for the Heliostat.  It tracks light in the horizontal
// plane (azmuth) and vertical (elevation) plane 
// 
#include <Servo.h> 
 
Servo azservo;  // create servo object to control a servo 
Servo elservo; 
Servo azmirservo;
Servo elmirservo;

int lfldrpin = 2;  // analog pin used to connect the left LDR
int rtldrpin = 3;  // analog pin used to connect the right LDR
int topldrpin = 4;
int botldrpin = 5;
int lfval;    // variable to read the value from the analog pin 
int rtval;    //variable for right LDR
int topval;
int botval;
int tol =50; //tolerance difference
int azpos =100; //set initial azmuth near mid point
int elpos = 6;  //set inital elevation low
int elmir;
int azmir;

//int DEBUG = 1;
void setup() 
{ 
   // if (DEBUG) {Serial.begin(9600);} // if we want to see LDR values
   Serial.begin(9600);
   azservo.attach(9);  // attaches the azmuth servo on pin 9 to the servo object 
                        // so hook control line (white) to pin 9
   elservo.attach(10); // same as above but for elevation servo on 10                     
   azmirservo.attach(5);
   elmirservo.attach(6); 
} 
 
void loop() 
{ 
  azservo.write(azpos);  // set azmuth to center
  elservo.write(elpos);  // set elevation initial point
  azmirservo.write(azmir);
  elmirservo.write(elmir);
  lfval = analogRead(lfldrpin);            // reads the value of the LDRs (value between 0 and 1023) 
  rtval = analogRead(rtldrpin);
  topval = analogRead(topldrpin);             
  botval = analogRead(botldrpin);
  Serial.print("Left: ");
  Serial.print(lfval);
  Serial.print("  Right: ");
  Serial.print(rtval);
  Serial.print(" Elpos ");
  Serial.print(elpos);
  Serial.print("  Azpos  ");
  Serial.print(azpos);
  Serial.print(" Elmir ");
  Serial.print(elmir);
  Serial.print(" Azmir ");
  Serial.println(azmir);
  // ck and position left right servo (azmuth)
  if (abs(lfval-rtval)> tol)
   {if (lfval > rtval){ azpos=azpos-1;
                        if(azpos<2){azpos=2;}
        } //  Pin 3 is right LDR
    if(rtval>lfval) {azpos = azpos + 1;
              if(azpos>178) {azpos=178;}
    }
    azmir=azpos/2;
  }
    
 // ck and position up down servo (elevation)   
 
    if (abs(topval-botval)> tol)
   {if (topval > botval){ elpos=elpos-1;
                        if(elpos<2){elpos=2;}
        } //  Pin 3 is right LDR
    if(botval>topval) {elpos = elpos + 1;
              if(elpos>178) {elpos=178;}
    }
    elmir=elpos/2;
  }
    delay (50);
}

I am sure it is some dumb coding mistate but I am having no luck finding it.

Many thanks in advance for any assistance.

Bill
On a bayou in Mississippi

I'm not certain about this (because I only have one servo), but I think the "Servo" library is limited to controlling only two servos, on pins 9 and 10. You seem to have four servos in all.

Many thanks!! Once again I failed to RT*M. Your comment got me thinking deeper than my code and it was clearly stated at:

http://arduino.cc/en/Reference/Servo

I can be so major stupid at times.

Back to the drawing board.

I have a Pololu SSC003 servo controller. I guess I'll have to learn how to talk to it.

Many thanks.

Bill

Glad to hear that you've understood the trouble! You may be able to drive the other two servos in software, using a software-generated variable-length pulse. A servo pulse is simply a pulse of about 1ms length, repeating about 50 times per second, and varying the pulse length will change the servo position.

Just been searching for this kind of thing. In case you're still interested, I modified some C++ code for the arduino to track the sun. Just requires an RTC and some set co-ordinates then it'll tell you where the sun is! Squeeeee!

http://www.mowcius.co.uk/suntrackercode.html

Accuracy of at least 0.5deg

Mowcius

Hi, We are also trying to build a heliostat and really interested in the ardruino code.

@mowcius: I tried to reach you by mail but the adress is invalid. And the link on your site gives me an error as well. Could you please contact me on zininzelfdoen.nl or place the code on your site?

Thanks!

Inge

Occurs to me...

IF the servos will hold their position when signal lost....

You could(?)....

Put the two wires to the first pair of servos (ones pointing it at the sun) on one pair of output contacts of a DPDT relay.

Put the other servos' wires on the other set of output contacts

Wire the "common" contacts from the relay to the outputs of the Arduino.

Then...

The servos for pointing the thing at the sun could be "served" just, say, once per 5 minutes, and for 4minutes, 50 seconds between "point at sun" updates, the Arduino could control the servos which position the mirror.

=== If I've understood your design right, you use one pair of servos to get the think pointing at the sun, and then a second pair to move a mirror, which always has sun coming at it from a "known" relative-to-mirror direction? The point being, I am still guessing, to bounce the sun off in a new direction?

Why not just attach the mirror to the first set of servos?

@mowcius: I tried to reach you by mail but the adress is invalid. And the link on your site gives me an error as well. Could you please contact me on zininzelfdoen.nl or place the code on your site?

Yeah I am having real issues here. I will try get the site sorted as soon as I can.

Mowcius