Hello. First year engineering student here and I really need help with Arduino programming.
There's this assignment where we need to produce a water control system using Arduino and valves. The servo I have right now is the Hitec 785-HB with 3.5 rotation and I'm having trouble to control it.
Can someone enlighten me and explain (with example if possible) how do I control it to a certain angle.
I intend to control the mass flow of the water like;
Mix angle 0
Max angle 90 (valve restriction)
Therefore like
50% mass flow is 45 degree
75% mass flow is 67.5 degree and so forth
Is it possible to control the servo in that manner?
I really appreciate your help.
ErianZandin:
Mix angle 0
Max angle 90 (valve restriction)
Therefore like
50% mass flow is 45 degree
75% mass flow is 67.5 degree and so forth
If you only need 90 degrees of movement why not use a regular servo rather than a sail winch servo ?
With a regular servo you can just do servo.write(45) or servo.write(68). Or you can use servo.writeMicroseconds() for finer control.
With a 3.5 turn servo the full range 1000 microsecs (0 deg) to 2000 usecs (180 deg) will have to cover the full 1260 degrees of movement - so 45 degrees would equal 1035 usecs. This is only approximate because each servo will be a little different and you will need to experiment to get the right values.
Below is some info on your servo which has some unique features. Bottom is some servo test code you can use to determine the command values to use to position your servo.
// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.
#include <Servo.h>
String readString; //String captured from serial port
Servo myservo; // create servo object to control a servo
int n; //value to write to servo
void setup() {
Serial.begin(9600);
myservo.writeMicroseconds(1500); //set initial servo position if desired
myservo.attach(7, 500, 2500); //the pin for the servo control, and range if desired
Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded
Serial.println();
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
// attach or detach servo if desired
if (readString == "d") {
myservo.detach(); //detach servo
Serial.println("servo detached");
goto bailout; //jump over writing to servo
}
if (readString == "a") {
myservo.attach(7); //reattach servo to pin 7
Serial.println("servo attached");
goto bailout;
}
n = readString.toInt(); //convert readString into a number
// auto select appropriate value
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
myservo.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
myservo.write(n);
}
bailout: //reenter code loop
Serial.print("Last servo command position: ");
Serial.println(myservo.read());
Serial.println();
readString=""; //empty for next input
}
}