2 wire servo

Hi guys
im really new to this and i want to build my first robot.
So i bought a arduino uno and a couple of servo's + wheels but these servo's only have 2 wires instead of 3 (in most build descriptions). How do i connect my servo so that they can be controlled. (i want to build a obstacle avoid robot) using the Hc-sr04)

Hope you guys can help me

What part number is the servo, can you post a link to the data sheet for it?

It could be that the case ( is it metal? ) acts as a ground. Or it could be that it is not a servo at all and is just an ordinary motor.

Can you post a picture of it, not more than 1000 pixels wide.

Also servos do not rotate continuous ( unless modified ) so they are of little use for your application.

ahh sorry it is a motor and it is this one:

You can control that motor with most motor drive shields or separate H-bridge driver circuits.

These people have a lot of drivers

Hi Wouter,
Yes those are motors not servos, as Grumpy-mike says, you can drive them with just about any motor driver/shield these using the L293/298 are OK, just remember you lose about 2V's across the output transistors, so need at least 4 x AA's. A FET based one is better as the lose is very small, try the Pololu DRV8833 based module, I find this fine.

Beware of the cheap Chinese shield that offers a lot for it's money (It's about the only one with 2xL293's), it's really weird!! only works with it's own library... But there are some good cheap chinese boards too. In fact a lot of my stuff comes from China.

So first get this bit sorted, let us know what you have and I'm sure we can help you more, you could take a look at some of my early bots here: www.melsaunders.co.uk

What part of the world are you in? I might have a few useful links...

Hope it helps, regards.

Mel.

PS. The attached shows an home-made shield(RED) with Pololu DRV8833 driver(GREEN) (Bottom Left).

Hi guys thanks for all the information. Im really new to this.
i bought a arduino uno the hc-sr04 and the 2 motors + wheels.
Im from the Netherlands.

Wouter

Hi guys sorry for the late update but i had to wait on some parts

This is what i have so far. it kinda works. Sometimes it seams not to see the objects right in front of him and crashes into them any way. I also added my code i hope you guys can check it out for me?

(sorry the jumperwire cable set i orded doesn't have black wires for the ground.

#include <AFMotor.h>
#define trigPin 18
#define echoPin 19
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #1, 8KHz pwm
AF_DCMotor motor3(3, MOTOR34_64KHZ); // create motor #3, 8KHz pwm

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  motor1.setSpeed(255); // set the speed to 200/255
  motor3.setSpeed(255); // set the speed to 200/255
}

int CheckDistance()
{
  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;
  
  return distance;
}

void MotorForward(int delaytime)
{
  motor1.run(FORWARD);
  motor3.run(FORWARD);
  delay(delaytime);
}
void MotorBackward(int delaytime)
{
  motor1.run(BACKWARD);
  motor3.run(BACKWARD);
  delay(delaytime);
}
void MotorRelease()
{
  motor1.run(RELEASE);
  motor3.run(RELEASE);
  delay(1000);
}

void MotorLeft()
{
  motor1.run(FORWARD);
  motor3.run(BACKWARD);
  delay(600);
}

void MotorRight()
{
  motor1.run(BACKWARD);
  motor3.run(FORWARD);
  delay(500);
}

void loop() 
{
  int testDistance = CheckDistance();
  
   Serial.print(testDistance);
   Serial.println(" test");
   
  if (testDistance >= 30 || testDistance <= 0){
    Serial.println("Out of range");
    //go forward and check range again
    MotorForward(700);
    MotorRelease();
  }
  else 
  {
    Serial.print(testDistance);
    Serial.println(" cm");
    //object in path, reverse and turn to avoid
    MotorBackward(600);
    MotorRelease();
    MotorRight();
    MotorRelease();
    MotorForward(600);
    MotorRelease();
    MotorLeft();
    MotorRelease();
    
  }
   
  delay(500);
}

Thanks for all the help

Hi wouter-,
That's the very motor shield I was thinking of!! If you're using a UNO then where are pins 18 & 19 (according to the code) that you use for the HCSR04? In your picture they seem to be connected to A4 & A5? these are usually used for the i2c interface, or analogue inputs, BUT can be digital too.

I am just wondering how secure some of your wiring is!! Perhaps at this time you don't want to solder anything, so just make sure that everything is connected right and tight!

 digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line [b][u] 10 uS could be too long, adding to the result.[/b][/u]
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

My code is this:

        const int pingPin=7, EchoPin=8;
	long duration;

	// The SRF005 is triggered by a HIGH pulse of 2 or more microseconds.
	// Give a short LOW pulse before to ensure a clean HIGH pulse:

	pinMode(pingPin, OUTPUT);
	pinMode(EchoPin, INPUT);  

	digitalWrite(pingPin, LOW);
	delayMicroseconds(2);
	digitalWrite(pingPin, HIGH);
	delayMicroseconds(2);         
	digitalWrite(pingPin, LOW); 
	duration = pulseIn(EchoPin, HIGH);
	delay(100);

I find this works very well, with no problems.

What is your power supply? 4 x AA's at least for that shiled!

Well there's something to work on, get back to us.

Regards

Mel.

Thanks for the reply! I really like the motor shield and i get my motors to work with it! so thanks!
Yes i use the A4 and A5 for the Hc SR04 this because the digital pins cant be used without soldering.
I borrowed a code from some one on the internet but i cant find the website anymore.

How can i refer to the a4 and 5 pins? or is it better to use other pins.

You are completely right that my wiring is a bit wierd but i orded headers and i'm waiting for those.

I will try your code thank you!

currently i use a 9v battery for the shield. the uno doesn't seem to require a own powersource.

i also changed the robot a bit it is now way smaller and doesn't use the breadboard anymore.

Wouter

Hi wouter-,
You can just refer to A4 & A5 as just that! it's just the same as saying D2 or D8, etc.

#define trigPin A4
#define echoPin A5

The only other thing that bothers me is that 9v battery! What kind of battery is it? Please tell me it's NOT one of these tiny squarish things!! These just can't supply the current your motors need, OK perhaps for driving a Uno that's not doing a lot, but completely uselss for motors, servos and relays that demand more current, they die very quicky, as their designed for low current use.

As I said this shield seems to get data from the Uno, sends it to a shift register and outputs it to the L293's etc in a serial/bit format which is why you have to use their AFmotor.LIB So will you have to modify the LIB if you change pins, could be!! AS time goes on I think you will see the limits of this shield and hopefully move on to something else.

Please get back to us, so we can help.

Regards

Mel.

Thanks i will try that! :smiley: sometimes it is easier then i expect :wink:

it is a Panasonic Alkaline 9 v battery ( 6lf22) it seems to drive the motors just ok. i used the battery to test my motors.

Hopefully this shield will work for my experiments to get a hang of Arduino and i can always buy a better one if i need it.

Thanks again for all the help

Wouter

I finaly got my order
I added the headers and a kill switch.


Wouter