Hello, I am looking for a program to monitor 4 servomotors by a detector ultrasonic HC-SR04 (external power supply). The movement of each servo is different.
I am totally beginner.
Thank you to all
Hello, I am looking for a program to monitor 4 servomotors by a detector ultrasonic HC-SR04 (external power supply). The movement of each servo is different.
I am totally beginner.
Thank you to all
Thank you for your attention.
Servo movement may be random but different:
eg 20-160 °, 30-150 °, 40-140 ° continuous return at different speeds.
As long as the person is at least 50 cm from the wall, servos operate and stop when the person leaves the wall.
If necessary, I will modify the value of angles.
For now that I have the servos are Futaba S3003 and Tower Pro MG995
Le 8 oct. 2014 à 21:35, kidiccurus <messages@element14.com> a écrit :
element14
servomotor (arduino)
réponse de Samuel Doye dans Arduino - Afficher la discussion complète
I did not know where and when you wanted the servos to move. If you give me a list of positions in degrees and times for each servo then I will code it in for you, or if you have existing code I can modify it for you. The only thing to note is that it should start and end in the same place. Also what servos are you using, in case I need to look up a data sheet.
Répondre à ce message en répondant à cet e-mail, ou voir le message sur element14
Commencer une nouvelle conversation dans Arduino sur element14
**************************Disclaimer**************************
The contents of this e-mail and any file transmitted with it are confidential and intended solely for the individual or entity to whom they are addressed. The content may also contain legal, professional or other privileged information. If you received this e-mail in error, please destroy it immediately. You should not copy or use it for any purpose nor disclose its contents to any other person. The views stated herein do not necessarily represent the view of the Company.
Please ensure you have adequate virus protection before you open or detach any documents from this transmission. The Company does not accept any liability for viruses.
Premier Farnell plc
150 Armley Road
Leeds
LS12 2QQ
Telephone +44 (0) 870 129 8608
Fax +44 (0) 870 129 8610
Registered in England
Company Number 876412
Registered Office: Farnell House, Forge Lane, Leeds LS12 2NE
#define echoPin 12 #define trigPin 13 #include <Servo.h> Servo towerpro; Servo futaba; void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); towerpro.attach(9); futaba.attach(10); towerpro.write(90); futaba.write(30); randomSeed(analogRead(0)); } void loop() { start: long duration, distance; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); // delayMicroseconds(1000); - Removed this line delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance < 4) { // Change value 4 to change trigger distance goto start; } if (distance >= 200 || distance <= 0){ Serial.println("Out of range"); } else { Serial.print(distance); Serial.println(" cm"); } delay(100); towerpro.write(random(0,180)); futaba.write(random(0,60)); delay(random(250,2000)); } #define echoPin 12 #define trigPin 13 #include <Servo.h> Servo towerpro; Servo futaba; void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); towerpro.attach(9); futaba.attach(10); towerpro.write(90); futaba.write(30); randomSeed(analogRead(0)); } void loop() { start: long duration, distance; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); // delayMicroseconds(1000); - Removed this line delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance < 4) { // Change value 4 to change trigger distance goto start; } if (distance >= 200 || distance <= 0){ Serial.println("Out of range"); } else { Serial.print(distance); Serial.println(" cm"); } delay(100); towerpro.write(random(0,180)); futaba.write(random(0,60)); delay(random(250,2000)); }
Try this, attach the futaba servo to pin 10 and the tower pro to pin 9. Make sure analogue pin 0 is NOT connected to anything, it is required to set up the random number generator. If you need the code modifying or it doesn't work, please post.
Wonderful !
For the other two servo I place on pin 7 and 8 or 11 and 12 ?
For supply of servos I plug how?
Again thank you.
I Would suggest you use a separate 5v for the servo power, the arduino regulator will not be happy driving 4 servos
Connect the servo +v pins to the power supply
connect the ground (0v) of the servo supply to the gnd pin on the arduino,
connect the 0v of the servo supply to all the servos
the pwm pins are connected as indicated above
THat at should get you running nice and reliably
Oh, sorry, I made a mistake, I thought you only had 2 servos. Please just tell me how many of each type of servo you have so I can alter the progran accordingly. I agree that you should be using an external PSU for that many servos. Also, a quick request, when we get this working could you please post a video, I really want to see this cool piece of art that you have made.
Thank You.
I have either a battery of 4 x 1.5 V or an AC / DC power adapter, model TSL-0901, output 9V DC 1000mA.
Which is best ?
For now I have 2 Tower Pro servos and 2 Futaba servos (Do you know larger models at a reasonable price?).
For now I'm trying to solve the practical and technical problem. I attack the artistic part in January. Once the installation is finished I will post a photo or video (how?).
#define echoPin 12
#define trigPin 13
#include <Servo.h>
Servo towerpro;
Servo futaba;
Servo towerpro2;
Servo futaba2;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
towerpro.attach(9);
futaba.attach(11);
towerpro2.attach(10);
futaba2.attach(12);
towerpro.write(90);
futaba.write(30);
towerpro2.write(90);
futaba2.write(30);
randomSeed(analogRead(0));
}
void loop() {
start:
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 20) { // Change value 20 to change trigger distance
goto start;
}
if (distance >= 200 || distance <= 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(100);
towerpro.write(random(0,180));
futaba.write(random(0,60));
towerpro2.write(random(0,180));
futaba2.write(random(0,60));
delay(random(250,2000));
}
Ok, all your servos should now work. The tower pro servos go to pins 9 and 10 and the futaba servos to pins 11 and 12. As for power, I recommend a high power usb charger or even a pc psu. If you cut open a usb cable then the red wire is power and the black wire ground. Make sure you do not use tis on a pc as it will require too much power and may damage your usb ports. For testing purposes you might be able to use the Arduino to supply power if you only hook up 1 servo at a time.