Pages: [1]   Go Down
Author Topic: Servo Motor Code/Set Up  (Read 1649 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You mean like an R/C servo?

There's a library handles all of that.
Logged

"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.

95060
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 < smiley-cool{ // 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);
  }
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26348
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The smiley is a way of telling you to post code using the # icon on the editor's toolbar.
Logged

"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.

Pages: [1]   Go Up
Jump to: