Hello,
I am currently working on a university project using Arduino Uno.
The project includes 9 servos (servo1,servo2,etc) whose movement is controlled by 9 photoresistos (1,2,etc) respectively .The servos are attached to 9 straws which move vertically depending on the values read from the photocells which are translated to degrees for the servos.
1.I want the servos to be able to move simultaneously and independantly from one another.
2.When the straws reach their lowest position, AT THAT MOMENT I want the servos to pause for a few second and then
3.start moving to their initial position “at a lower speed” (meaning that i don’t want their return to their initial position to be instant/sudden)
My team and I have managed to form the code for the servos to be controlled by the photoresistors.We thought that by combining elements from codes (that can describe/control each of the above 1,2,3 respectively) would work, but nothing seems to be efficient.
This is the code we have formed thus far, to control the servos via the photocells:
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int val1;
int val2;
void setup()
{
Serial.begin(9600);
myservo1.attach(12);
myservo2.attach(11);
}
void loop()
{
val1 = analogRead(0);
val1 = map(val1, 40, 170, 0, 180);
myservo1.write(val1);
Serial.println(val1);
delay(0);
val2 = analogRead(1);
val2 = map(val2, 40, 170, 0, 180);
myservo2.write(val2);
delay(0);
}
In this forum, we have found the following codes:
1-For pausing the servos before returning to their initial position (sorry i could not find the original post):
#include <Servo.h>
Servo myServo;
int myServoPin=12;
void setup()
{
** Serial.begin(9600);**
** myServo.attach(myServoPin);**
}
void loop()
** {**
** // If it’s time to open the valve**
** myServo.attach(myServoPin);**
** myServo.write(0);**
** delay(2000); // Give the servo time to move**
** myServo.detach(); // Stop sending pulses so the servo doesn’t try to move**
** delay(2000); // Delay the rest of the 5 minutes**
** myServo.attach(myServoPin);**
** myServo.write(180);**
** delay(2000); // Give the servo time to move**
** myServo.detach(); // Stop sending pulses so the servo doesn’t try to move**
** }**
2-For controlling the speed when returning to the initial position (for which we have downloaded the corresponding library):
#include <VarSpeedServo.h>
VarSpeedServo myservo; // create servo object to control a servo
void setup() {
** myservo.attach(12); // attaches the servo on pin 9 to the servo object**
}
void loop() {
** myservo.write(180, 5, true); // move to 180 degrees, use a speed of 30, wait until move is complete**
** myservo.write(0, 30, true); // move to 0 degrees, use a speed of 30, wait until move is complete**
}
We need to note that we are THE ULTIMATE ROOKIES! We started working with Arduino only recently and the teachers in our class taught us the very basics!! So we might be thinking all this in the wrong way and overcomplicating things…We are open to all ideas!
Thanks in advance,guys!