How to assemble 3 servo motors in one program code ?

Hi !! I need your help !!

Actually, I have a Project : The Intelligent Aquarium, so for that, there is needed to changing the water and feed the fish and a variation of a light … So i’m in a final stage, I should assemble all these programs for execute it in whole but
How i can assemble 3 servo motors in one program code ?

I already tried,but nothing worked !! (Just the servo motor for feed will working, the warterchanging servo wont working … :frowning: )

#include <Servo.h> 
 
Servo waterchanging;  // create servo object to control a servo 
Servo feed;               // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 


void setup() 
{ 
  waterchanging.attach(9); // attaches 2 servo on pin 9 to the servo object
  feed.attach(6);   // attaches the servo on pin 6 to the servo object 
  

} 
 
 
void loop() 
{ 
  { 
  {                                  
    feed.write(50);              
    delay(20);                      
  } 
  delay(1000);
     
  {                                
    feed.write(0);             
    delay(20);                       
  } 
   delay(21600000);  waits 6 hrs to restart the servo 
  }
 
 
{
    // goes from 0 degrees to 90 degrees 
  {                                  // in steps of 1 degree 
    waterchanging.write(90);              // tell servo to go to position in variable 'pos' 
    delay(20);                       // waits 20ms for the servo to reach the position 
  } 
   delay(15000);
     // goes from 90 degrees to 0 degrees 
  {                                
    waterchanging.write(0);              // tell servo to go to position in variable 'pos' 
    delay(20);    
    // waits 20ms for the servo to reach the position 
  } 
delay(50400000); // waits 2 weeks to restart the servo 
} 

  }

Plz Help me !!

servo_motors.ino (1.33 KB)

Your code doesn't compile, so how do you know it doesn't work?

Please use code tags when posting code.

Yes! The program has been compiled !!

The code you posted (badly) doesn't compile. I don't even need a compiler to tell me that, even through the obscuring fog of excess braces.

hmm .. If I say one part of the program doesn't work, that means it has been already compiled ..

Obviously the program that I published "badly" seems "bad" because I'm a beginner, I'm a new in this Forum .. I try to learn !

If I say one part of the program doesn't work, that means it has been already compiled ..

And if I say "the code doesn't compile" that means it doesn't upload, which means it doesn't run, therefore it cannot be said to work or not work.

Even if it did compile, you haven't said by what criteria you deem it to not work.

Obviously the program that I published "badly" seems "bad" because I'm a beginner, I'm a new in this Forum .. I try to learn

So read the clearly-posted guidelines.

   delay(21600000);  waits 6 hrs to restart the servo

Which compiler likes this line?

Your code has about 14000 curly braces. It needs exactly 4:

#include <Servo.h> 

Servo waterchanging;  // create servo object to control a servo 
Servo feed;               // a maximum of eight servo objects can be created 

int pos = 0;    // variable to store the servo position 

void setup() 
{ 
  waterchanging.attach(9); // attaches 2 servo on pin 9 to the servo object
  feed.attach(6);   // attaches the servo on pin 6 to the servo object 
} 

void loop() 
{ 
  feed.write(50);              
  delay(20);                      
  delay(1000);
  feed.write(0);             
  delay(20);                       
  delay(21600000);  // waits 6 hrs to restart the servo 

  // goes from 0 degrees to 90 degrees 
  waterchanging.write(90);              // tell servo to go to position in variable 'pos' 
  delay(20);                       // waits 20ms for the servo to reach the position 
  delay(15000);
  // goes from 90 degrees to 0 degrees 
  waterchanging.write(0);              // tell servo to go to position in variable 'pos' 
  delay(20);    
  // waits 20ms for the servo to reach the position 
  delay(50400000); // waits 2 weeks to restart the servo 
}

I hope your fish don’t starve in the two weeks you aren’t feeding them.

Yep! You're right !! I agree with you ..

Infact, the servo motor for the food, work successfully, but the servo motor for the waterchanging doesn't work !

And if I put the waterchanging program, instead of the feed program .. the waterchanging program work successfully!

Infact, the servo motor for the food, work successfully, but the servo motor for the waterchanging doesn’t work !

Did you wait 6 hours to see?

Did you wait 6 hours to see?

O.o Nope !! After 6 hrs the servo motor will be open .. to feed the fish

O.o Nope !! After 6 hrs the servo motor will be open .. to feed the fish

How?

void loop() 
{ 
  feed.write(50);              
  delay(20);                      
  delay(1000);
  feed.write(0);             
  delay(20);                       
  delay(21600000);  // waits 6 hrs to restart the servo

The servo to feed the fish will operate as soon as loop() runs. NOTHING, NADA, ZIP, ZILCH will then happen for 6 hours.

After 6 hours, the water servo should turn, wait for 15.02 seconds and then turn again. Then, NOTHING for another 2 weeks.

Get rid of the stupidly long delay()s. Move one servo. Wait 2 seconds. Move it back. Wait 10 seconds. Move the other servo. Wait 2 seconds. Move it back. You should be able to see both servos move in the time it took me to post this rant.

Ohh !! :D

I already tried that and it works !!! I don't know how i can do a stupid mistake like that !!

Anyway Thanks for ur support !! :D

Hi !! I’m actually in a Project , trying to make a Intelligent Aquarium, with changing the water with the servo motors, then to feed the fish also with the servo motor and take the temperature … etc …
so I have all these program but I would like to assemble these programs together !

I already tried but just the servo motors program has worked :frowning: . Plz help me !

Code of Webserver to show the temperature and the photos :

#include <SPI.h>
#include <Ethernet.h>
float temp = 0;
int sensorValues = 0;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0xDE, 0xFE, 0x6 };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        
          if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
           client.println("Refresh: 5");
            client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
   
          }
                
            
  float reading = analogRead(sensorValues);
  float voltage = reading * 5.0 / 1024;
  float temp = (voltage) * 100;
  
  client.println("<div align='center'>");
  client.println("<table border='20' width='70%'>");
  client.println("<center><h2>VOTRE AQUARIUM !</h2></center>");
  client.println("<center></center>");
  client.println("<tr>");
  client.println("<td><h3>TEMPERATURE </h3></td>");
  client.print("</td><td>");
  client.print(temp);  
  client.println(" *c");
  client.println("<META HTTP-EQUIP=\'Refresh\' CONTENT=\'5\'>");
  client.println("</td></tr>");
  client.println("<tr>");
  client.println("<td><h3> PHOTO <h3></td>"); 
  client.println("<img src='c:DSC07965.JPG'>");
   
          break;
         
        }

          // you're starting a new line
          currentLineIsBlank = true;
        } 

          // you've gotten a character on the current line

        


    // give the web browser time to receive the data
delay(1);
    // close the connection:
    client.stop();
    
  }
}

Code of servo motors to water changing and to feed the fish :

#include <Servo.h> 

Servo waterchanging;  // create servo object to control a servo 
Servo feed;               // a maximum of eight servo objects can be created 

int pos = 0;    // variable to store the servo position 

void setup() 
{ 
  waterchanging.attach(9); // attaches 2 servo on pin 9 to the servo object
  feed.attach(6);   // attaches the servo on pin 6 to the servo object 
} 

void loop() 
{ 
  feed.write(50);              
  delay(20);                      
  delay(1000);
  feed.write(0);             
  delay(20);                       
    
delay(5040000); //waits 2 weeks to restart the servo 
  // goes from 0 degrees to 90 degrees 
  waterchanging.write(90);              // tell servo to go to position in variable 'pos' 
  delay(20);                       // waits 20ms for the servo to reach the position 
  delay(15000);
  // goes from 90 degrees to 0 degrees 
  waterchanging.write(0);              // tell servo to go to position in variable 'pos' 
  delay(20);    
  // waits 20ms for the servo to reach the position 
  delay(2160000); // waits 6 hours to restart the servo 
}