Go Down

Topic: Servo Motor Code/Set Up (Read 1 time) previous topic - next topic

webers5

My group and myself are looking for help with our foundation digital design class. We are required to program a stuffed animal to interact with the audience and we are having trouble making a code and wiring up to a bread board for a servo motor. If anyone has any tips it would be great!

AWOL

You mean like an R/C servo?

There's a library handles all of that.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

tomswell

I'm a newbe but find servo action very rewarding ... here's a snipit of early code that as I remember works
the IR sensor is from Pololu.com > Sharp GP2Y0A02

//two position servo
#include <Servo.h>
#define SENSOR 5
int IRvalue = 0;
Servo myservo;  // create servo object
void setup()
{
  pinMode (2 , OUTPUT);             // sensor active indication LED 
  myservo.attach(9);                   // attaches the servo on pin 9 to the servo object
  myservo.writeMicroseconds(600);// assure servo starts in correct position
  delay(400);
  // Serial.begin(9600); used to see actual SENSOR values
}

void loop()
{
  delay (4000);
  IRvalue = analogRead (SENSOR)/100;// look at sensor and pause ... divide X 100 for simpler numeric reference
  // Serial.print("IRvalue ="); // text
  // Serial.println(IRvalue);// IRvalue with line feed
  // for testing
  if (IRvalue < 8){ // sensor normally 10  delay(2000);// delay before action
    delay(200);

    digitalWrite(2,HIGH); // light up led indicating sensor activated
  }
  else{
    delay (200);
    digitalWrite(2,LOW); // no sense active
  }
if (IRvalue < 7) {                            //sensor output went below 10
    delay(2200);                               // wait for the servo to reach the position
    myservo.writeMicroseconds(1200);  // tell servo to go to  active position in'
                                                  // be carefull to not enter inappropriate values as it may cause servo to jamb
                                                   //some do some don't
delay(1200);                                    // wait for the servo to reach the position
    myservo.writeMicroseconds(600);      // tell servo to return to passive position
    delay(100);
  }
}

AWOL

The smiley is a way of telling you to post code using the # icon on the editor's toolbar.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy