element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum servomotor (arduino)
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 23 replies
  • Subscribers 393 subscribers
  • Views 2128 views
  • Users 0 members are here
  • ultrasonic_sensor
  • servo
  • arduino
Related

servomotor (arduino)

Former Member
Former Member over 11 years ago

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

  • Sign in to reply
  • Cancel
Parents
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago

    You only mention one sensor but you have it monitoring for someone within 50cm and also monitoring the servos, are you using 2 sensors ?

     

    or is the sensor monitoring for people close to it, If detected it starts the servos (4 with their own actions), but if the person / object moves out of range of the sensor the servos will stop what ever there doing and wait for a new presence to be detected by the sensor

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Robert Peter Oakes

    the ultrasonic sensor (and servos) are attached to the wall. when a person approaches 50 cm or less, servos start in march.

    Yes, the sensor is monitoring for people close to it, If detected it starts the servos (4 with their own actions), but if the person moves out of range of the sensor the servos will stop what ever there doing and wait for a new presence to be detected by the sensor.

     

    Le 6 oct. 2014 à 20:54, peteroakes <messages@element14.com> a écrit :

     

    You only mention one sensor but you have it monitoring for someone within 50cm and also monitoring the servos, are you using 2 sensors ?

     

    or is the sensor monitoring for people close to it, If detected it starts the servos (4 with their own actions), but if the person / object moves out of range of the sensor the servos will stop what ever there doing and wait for a new presence to be detected by the sensor

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • kidiccurus
    0 kidiccurus over 10 years ago in reply to kidiccurus

    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.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to kidiccurus

    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.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to Former Member

    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

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • kidiccurus
    0 kidiccurus over 10 years ago in reply to Former Member

    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.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Robert Peter Oakes

    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 ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to kidiccurus

    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?).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • kidiccurus
    0 kidiccurus over 10 years ago in reply to Former Member


    #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)); 
    } 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • kidiccurus
    0 kidiccurus over 10 years ago in reply to kidiccurus

    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.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to kidiccurus

    message d'Arduino :

    sketch_oct23a:49: error: redefinition of 'Servo towerpro'

    sketch_oct23a:4: error: 'Servo towerpro' previously declared here

    sketch_oct23a:50: error: redefinition of 'Servo futaba'

    sketch_oct23a:5: error: 'Servo futaba' previously declared here

    sketch_oct23a.ino: In function 'void setup()':

    sketch_oct23a:53: error: redefinition of 'void setup()'

    sketch_oct23a:6: error: 'void setup()' previously defined here

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to Former Member

    9V will be too high for the servos probably so unless you have a DC-DC converter or a 5V regulator it may be better to go with the 4*1.5V batteries

     

     

     

    Regards

     

     

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to Former Member

    9V will be too high for the servos probably so unless you have a DC-DC converter or a 5V regulator it may be better to go with the 4*1.5V batteries

     

     

     

    Regards

     

     

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube