line following robot with arduino hardware problem

hello guys,

After hours of research without any helping advice

i hope you can help me out.

I’m building a line following robot with these components:

Arduino duemillanove

2 motors (3V)

http://bit.ly/hpYOCW

4 QTI sensors from parallax (5V)

http://bit.ly/fyMSTQ

My code should be right, but the motors are not working properly.

In fact they are reacting to the black line, but they run way too fast

and sometimes take time till the start moving, so i couldnt even build

a proper test-parcour yet…

I believe that the mistake i made is that i didnt use a h-bridge-

is it possible to run them properly without a h- bridge? i already soldered all parts :frowning:

and maybe i got the wrong motors? should i use servos instead?

in our class we learned to run motors with a transistor and a “diode”…

or maybe i got the code wrong…

hope you can help me out, iam already pretty desperate…

const int motor1Pin = 9;    // 
const int motor2Pin = 11;    //
int sensorPin2 = 2;   //sensor 1
int sensorPin3 = 3;   //sensor 2
int sensorPin4 = 4;   //sensor 3
int sensorPin5 = 5;   //sensor 4           // 220 or 1k resistor connected to this pin

int sDigi2=0;  //digitale Werte für jeden Sensor
int sDigi3=0;
int sDigi4=0;
int sDigi5=0;
int x1=0;
int x2=100;  
int x3=150;
int x4=200;
int x5=250
;

long result = 0;


void setup()                    // 
{
   Serial.begin(9600);
   Serial.println("start");      // 
}
void loop()                     // 
{
   Serial.println( "-----------------");
   Serial.println( "-- sensor 1 ----");   
   Serial.println( RCtime(sensorPin2) );
   Serial.println( "-- sensor 2 ----");
   Serial.println( RCtime(sensorPin3) );
   Serial.println( "-- sensor 3 ----");
   Serial.println( RCtime(sensorPin4) );
   Serial.println( "-- sensor 4 ----");
   Serial.println( RCtime(sensorPin5) );
   Serial.println( "-----------------");
  // delay(5000);

//--------------------- if schleife fuer digitale zuweisungen  sDigi2  -----------------------------
   if(RCtime(sensorPin2) > 50) //SCHWARZ
     {
       sDigi2 = 1;
     }
   
   if(RCtime(sensorPin2) < 50) //WEISS
     {
       sDigi2 = 0;
     }

//--------------------- if schleife fuer digitale zuweisungen  sDigi3  -----------------------------
   if(RCtime(sensorPin3) > 50) //SCHWARZ
     {
       sDigi3 = 1;
     }
   
   if(RCtime(sensorPin3) < 50) //WEISS
     {
       sDigi3 = 0;
     }
     
//--------------------- if schleife fuer digitale zuweisungen  sDigi4  -----------------------------
   if(RCtime(sensorPin4) > 50) //SCHWARZ
     {
       sDigi4 = 1;
     }
   
   if(RCtime(sensorPin4) < 50) //WEISS
     {
       sDigi4 = 0;
     }
     
//--------------------- if schleife fuer digitale zuweisungen  sDigi5  -----------------------------
   if(RCtime(sensorPin5) > 50) //SCHWARZ
     {
       sDigi5 = 1;
     }
   
   if(RCtime(sensorPin5) < 50) //WEISS
     {
       sDigi5 = 0;
     }
 
     
//------------------- 0000--------------------------------------   

   if ((sDigi2 == 0) && (sDigi3 == 0) && (sDigi4 == 0) && (sDigi5 == 0))
     {
       analogWrite(motor1Pin, x1);
       analogWrite(motor2Pin, x1);
     }

//------------------- 1000--------------------------------------

   if ((sDigi2 == 1) && (sDigi3 == 0) && (sDigi4 == 0) && (sDigi5 == 0))
     {
       analogWrite(motor1Pin, x5);
       analogWrite(motor2Pin, x2);
     }

//------------------- 1100--------------------------------------   
   
   if ((sDigi2 == 1) && (sDigi3 == 1) && (sDigi4 == 0) && (sDigi5 == 0))
     {
       analogWrite(motor1Pin, x5);
       analogWrite(motor2Pin, x3);
     }

//------------------- 0110--------------------------------------   
   
   if ((sDigi2 == 0) && (sDigi3 == 1) && (sDigi4 == 1) && (sDigi5 == 0))
     {
       analogWrite(motor1Pin, x2);
       analogWrite(motor2Pin, x2);
     }


//------------------- 0011--------------------------------------   

   if ((sDigi2 == 0) && (sDigi3 == 0) && (sDigi4 == 1) && (sDigi5 == 1))
     {
       analogWrite(motor1Pin, x3);
       analogWrite(motor2Pin, x5);
     }

//------------------- 0001--------------------------------------   

   if ((sDigi2 == 0) && (sDigi3 == 0) && (sDigi4 == 0) && (sDigi5 == 1))
     {
       analogWrite(motor1Pin, x2);
       analogWrite(motor2Pin, x5);
     }

else    Serial.println( "-- FALSCHE ZUWEISUNG ----");

}

   long RCtime(int sensPin)
     {
      long result = 0;
      pinMode(sensPin, OUTPUT);       // make pin OUTPUT
      digitalWrite(sensPin, HIGH);    // make pin HIGH to discharge capacitor - study the schematic
      delay(1);                       // wait a  ms to make sure cap is discharged
      pinMode(sensPin, INPUT);        // turn pin into an input and time till pin goes low
      digitalWrite(sensPin, LOW);     // turn pullups off - or it won't work
       
        while(digitalRead(sensPin))
            {    // wait for pin to go low
             result++;
            }
      return result;                   // report results   
     }

thank you,

julia

Julia,

  • - The first thing I noticed when I looked at [what little Parallax offers in the way of information is that they switch two of the three wires to the sensor. It appears that your code switches only one wire.
  • - Whether you need an H-bridge depends on whether the Arduino has enough current capacity to drive the motors. It appears (if I'm reading the datasheet correctly) that your motor requires 290 mA. An Arduino digital output is [[rated](http://arduino.cc/en/Main/ArduinoBoardUno) as providing 40 mA. So, it appears that an H bridge (or some other means of controlling motor power with the Arduino's output) would be necessary.
  • - I suggest you read the [[I/O tutorial](http://arduino.cc/en/Tutorial/DigitalPins), particularly the discussion near the end about overloading pins.
  • - It would be very helpful if you posted a diagram or wire listing of your assembly. Without one of those, there's no way for us to tell what is wired where. For example, your code refers to two motor pins, but two motors have a total of 4 wires, so where are the other two motor wires connected?
  • - Which way does the robot move for each of the output settings?
  • - What is the physical arrangement of the four sensors on the robot?
  • - Although it probably will not affect this robot, I suggest you look at using [[if / else](http://arduino.cc/en/Reference/Else) statements for setting the digital variables for the sensors.
  • [/list]

    Have Fun,

    Eric](http://arduino.cc/en/Reference/Else)](http://arduino.cc/en/Tutorial/DigitalPins)](http://arduino.cc/en/Main/ArduinoBoardUno)](http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/qtilinesensorrev1.pdf)

    Hi Eric,

    thank you a lot for your answer!

    esklar81:

    1. The first thing I noticed when I looked at [what little Parallax offers in the way of information is that they switch two of the three wires to the sensor. It appears that your code switches only one wire.[/quote]

    I got the sensors in a kit similar to this: http://www.parallax.com/dl/docs/prod/ro … Follow.pdf

    I’m not sure what you mean with the wires, i plugged it in like that: one wire goes to the ground, one to 5v and one to the sensor digital input…maybe thats for measuring the temperature too?

    esklar81:

    1. Whether you need an H-bridge depends on whether the Arduino has enough current capacity to drive the motors. It appears (if I’m reading the datasheet correctly) that your motor requires 290 mA. An Arduino digital output is [rated as providing 40 mA. So, it appears that an H bridge (or some other means of controlling motor power with the Arduino’s output) would be necessary.[/quote]

    Thanks for the explanation, I just realised, that I got the wrong link, this is the motor I’m using:

    http://www.conrad.de/ce/de/product/2444 … XX-2025-22

    And concerning the motor, is it necessary, that i use a servo like most of the linefollowingrobots do?

    esklar81:

    1. I suggest you read the [I/O tutorial, particularly the discussion near the end about overloading pins.[/quote]

    thank you for the link,i really hope, that i haven’t destroyed the digital pins yet…

    esklar81:

    1. It would be very helpful if you posted a diagram or wire listing of your assembly. Without one of those, there’s no way for us to tell what is wired where. For example, your code refers to two motor pins, but two motors have a total of 4 wires, so where are the other two motor wires connected?[/quote]

    here is a link to some fotos and the wire list. imagine those distance sensors are the Qti sensors.

    http://img827.imageshack.us/g/bildschir … 0106u.png/

    esklar81:

    1. Which way does the robot move for each of the output settings?[/quote]

    for example:

    when the first and left sensor is black the robot turns left meaning the right motor gets more power then the left one

    esklar81:

    1. What is the physical arrangement of the four sensors on the robot?[/quote]

    the sensors are positioned in a semicircle (see on the fotos above) this is the robo:

    http://www.conrad.at/ce/de/product/1914 … Detail=005

    esklar81:

    1. Although it probably will not affect this robot, I suggest you look at using [if / else statements for setting the digital variables for the sensors.[/list]

    Have Fun,

    Eric[/quote]

    i’ve used if in the code, but i’m not sure which data i have to send to the motor, at the moment

    im sending from 0 to 250…

    thanks again,

    julia](http://arduino.cc/en/Reference/Else)

    ](http://arduino.cc/en/Tutorial/DigitalPins)

    ](http://arduino.cc/en/Main/ArduinoBoardUno)

    ](http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/qtilinesensorrev1.pdf)

    Jujulia:
    thank you a lot for your answer!

    You’re welcome!

    Jujulia:
    I got the sensors in a kit similar to this: http://www.parallax.com/dl/docs/prod/ro … Follow.pdf

    I’m not sure what you mean with the wires, i plugged it in like that: one wire goes to the ground, one to 5v and one to the sensor digital input…maybe thats for measuring the temperature too?

    I do not see any indication that tempertature is being measured. However, it appears that turning the sensor off between measurements is not necessary for taking measurements. They did it probably to reduce the current needed (Each sensor draws 50 mA for the LED plus an unspecified current for the detector.) to extend the battery life.

    Jujulia:
    Thanks for the explanation, I just realised, that I got the wrong link, this is the motor I’m using:

    http://www.conrad.de/ce/de/product/2444 … XX-2025-22

    And concerning the motor, is it necessary, that i use a servo like most of the linefollowingrobots do?

    I see no reason to believe you need to use a servo. I don’t even see how a servo could work, as a servo takes a control signal and sets its position based on that control signal. There are, however, things called, incorrectly, “continuous rotation servos” that are usually made by removing the internal position sensors from servos, so that the motor runs continuously, but without feedback. Strictly speaking, once the feedback mechanism is removed, the device is no longer a “servo”.

    Jujulia:
    thank you for the link,i really hope, that i haven’t destroyed the digital pins yet.

    If you assembled the circuit the way that is shown in the images to which you linked, the FETs should be protecting the DO pins from having too much current drawn from them. My concern was based on my (I hope, incorrect) understanding that you had connected the DO pins directly to the motors.

    Jujulia:
    here is a link to some fotos and the wire list. imagine those distance sensors are the Qti sensors.

    http://img827.imageshack.us/g/bildschir … 0106u.png/

    I cannot tell from the images where and how power is being supplied. Most importantly, how is power supplied for the motors? It is better to have a power supply for the motors that is separate from the power supply for the Arduino and the sensors. Separating the power supplies reduces the risk of motor noise interfering with the electronics. Also, the voltage regulators on the Arduino probably have enough capacity to power one sensor at a time, but not the motors.

    Jujulia:
    i’ve used if in the code, but i’m not sure which data i have to send to the motor, at the moment im sending from 0 to 250…

    0 to 250 is a valid range of arguments for the analogWrite function. Whether that’s appropriate for those motors depends on how you are supplying power to them and at what voltage. Based on your comments, in your original post, about the robot’s behavior, I suggest you reduce the speed values so that you can observe the behavior more easily as you develop the code.

    My suggestion that you consider if/else was because it is both shorter code and shorter execution time if you change:

    if(RCtime(sensorPin2) > 50) //SCHWARZ
         {sDigi2 = 1;}
     if(RCtime(sensorPin2) < 50) //WEISS
         {sDigi2 = 0;}
    

    to:

    if(RCtime(sensorPin2) > 50) //SCHWARZ
         {sDigi2 = 1;}
         else //WEISS
         {sDigi2 = 0;}
    

    the execution time is much shorter because you eliminate both a sensor measurement cycle and a comparison of the result of that measurement to your limit.

    BTW, from where did you get the “50” you are using as the limit? The limit value for determining whether a sensor is over white or over black needs to be determined for each robot, each set of “black” and “white”, the room lighting conditions, and (sometimes) separately for each sensor.

    Have Fun,

    Eric

    Hi Eric!

    I do not see any indication that tempertature is being measured. However, it appears that turning the sensor off between measurements is not necessary for taking measurements. They did it probably to reduce the current needed (Each sensor draws 50 mA for the LED plus an unspecified current for the detector.) to extend the battery life.

    I think i misread that, but your theory makes sense.

    I see no reason to believe you need to use a servo. I don’t even see how a servo could work, as a servo takes a control signal and sets its position based on that control signal. There are, however, things called, incorrectly, “continuous rotation servos” that are usually made by removing the internal position sensors from servos, so that the motor runs continuously, but without feedback. Strictly speaking, once the feedback mechanism is removed, the device is no longer a “servo”.

    So far, everyone gave me the advice to use a servo motor (especially for modelling),

    which like you said isn’t really a servo motor with the removal of the sensors.

    I heard it would be easier to handle… I received instructions on how to make a servo in a continuous rotation servo, but if it’s possible i rather stay with the DC motors because i already soldered the parts.

    If you assembled the circuit the way that is shown in the images to which you linked, the FETs should be protecting the DO pins from having too much current drawn from them. My concern was based on my (I hope, incorrect) understanding that you had connected the DO pins directly to the motors.

    The DO pins are connected with the transistor and the diode, like in this image:

    [<LINK_TEXT text=“http://img529.imageshack.us/img529/1585 … 10106u.png”>http://img529.imageshack.us/img529/1585/bildschirmfoto20110106u.png</LINK_TEXT>

    Uploaded with [ImageShack.us

    I think this is the right way for a DC motor.

    At the moment i use the power from the VIN pin, like in the example. When i plug the arduino to the computer how much volt does vin send to the arduino? Should i go with the 5V pin? I later will use a 4AA-battery. (each battery has 1.5 V) so it will be 6V, is this too much for the 5V sensors? and especially for the 3V-motors?

    I cannot tell from the images where and how power is being supplied. Most importantly, how is power supplied for the motors? It is better to have a power supply for the motors that is separate from the power supply for the Arduino and the sensors. Separating the power supplies reduces the risk of motor noise interfering with the electronics. Also, the voltage regulators on the Arduino probably have enough capacity to power one sensor at a time, but not the motors.

    Power is supplied threw the VIN pin when the computer is plugged in, but this is only temporary, because it should of course work wireless. So you would advice me to use a battery for the motors and another battery for the arduino and sensors…

    I would use the 5V pin from the arduino for the sensors and the VIN pin with 3V for the motors from 2 batteries, is this a good way? How can i provide the 5V with a battery?

    0 to 250 is a valid range of arguments for the analogWrite function. Whether that’s appropriate for those motors depends on how you are supplying power to them and at what voltage. Based on your comments, in your original post, about the robot’s behavior, I suggest you reduce the speed values so that you can observe the behavior more easily as you develop the code.

    When I reduce the speed it happens that the robo doesn’t move at all. I think i got the powersupply wrong or the ratio of the gear clogs the robo from moving…

    My suggestion that you consider if/else was because it is both shorter code and shorter execution time if you change:

    if(RCtime(sensorPin2) > 50) //SCHWARZ
    
     {sDigi2 = 1;}
    

    if(RCtime(sensorPin2) < 50) //WEISS
    {sDigi2 = 0;}

    
    to:
    
    
    

    if(RCtime(sensorPin2) > 50) //SCHWARZ
    {sDigi2 = 1;}
    else //WEISS
    {sDigi2 = 0;}

    
    the execution time is much shorter because you eliminate both a sensor measurement cycle and a comparison of the result of that measurement to your limit.
    

    thanks for the code, thats a good idea, especially if it effects the execution time.

    BTW, from where did you get the “50” you are using as the limit? The limit value for determining whether a sensor is over white or over black needs to be determined for each robot, each set of “black” and “white”, the room lighting conditions, and (sometimes) separately for each sensor.

    i measured the sensors and the data varies a lot. When moving over white surface the sensors show numbers that are very high (about 1000 a.s.o) when moving over black surface the numbers are very low (under 10 usually), that’s why i picked 50… is it better to map those numbers to a scale from 1 to 10 and than take 5 as number for comparising? Is this the reason why the robot works so imprecise?

    thanks a lot, you helped me the most so far

    claudia](http://imageshack.us)](ImageShack - Best place for all of your image hosting and image sharing needs)

    Jujulia:
    I think i misread that [text on shutting off sensors between readings], but your theory makes sense.

    Given the limitted current you have, I suggest you keep the sensors off most of the time and turn each one on only when you read it.

    Jujulia:
    So far, everyone gave me the advice to use a servo motor (especially for modelling), which like you said isn’t really a servo motor with the removal of the sensors.

    I heard it would be easier to handle… I received instructions on how to make a servo in a continuous rotation servo, but if it’s possible i rather stay with the DC motors because i already soldered the parts.

    The main concern I have now with keeping your motors is providing them the correct power. At the moment, you appear to be running 1.5 to 3 V motors at 5 V. That is likely to shorten the life of the motors, although using PWM should lessen the effect, as the average power and, therefore, the heating, is less.

    Jujulia:
    The DO pins are connected with the transistor and the diode, like in this image:

    I think this is the right way for a DC motor.

    Please provide the specifications or part number for the FETs you are using. (A link to a datasheet in English would be great, but if you give me a part number, I should be able to find one.)

    Jujulia:
    At the moment i use the power from the VIN pin, like in the example. When i plug the arduino to the computer how much volt does vin send to the arduino? Should i go with the 5V pin?

    If you are connecting through USB, that’s providing 5 V. What isn’t clear is how Vin is being powered, because that may depend on which Arduino you are using. The images you’ve provided appear to show a [Arduino Diecimila or earlier (later boards have automatic power source selection, your images show the selection jumper block), but there have been two generations of boards (Duemilanove and Uno) since then. Please let me know which board you have, so I can look at the correct power schematic.

    Jujulia:
    I later will use a 4AA-battery. (each battery has 1.5 V) so it will be 6V,

    Alkaline AA cells are 1.5 V, but NiCd and NiMH are 1.2 V. Which are you planning to use? You should review the power supply recommendations for whichever Arduino you have. The recent ones specify a minimum input voltage of 6 V and recommend a minimum input voltage of 7 V, when not being powered through USB.

    Jujulia:
    is this too much for the 5V sensors? and especially for the 3V-motors?

    You’ll need to check the data sheet for the sensors and, perhaps, the datasheets for the components from which the sensors are built to determine that. On a positive note, the Arduino has a 5 V regulator and it probably can supply one sensor at a time with regulated 5 V power. I do not, however, suggest trying to power more than one sensor at a time (or the motors at all) that way.

    Jujulia:
    Power is supplied threw the VIN pin when the computer is plugged in, but this is only temporary, because it should of course work wireless. So you would advice me to use a battery for the motors and another battery for the arduino and sensors…

    I would use the 5V pin from the arduino for the sensors and the VIN pin with 3V for the motors from 2 batteries, is this a good way? How can i provide the 5V with a battery?

    I don’t see any way to supply 3 V to Vin and get a 5 V Arduino to work. The Arduino’s internal power components take Vin and regulate it down to 5 V to power the Arduino’s internal circuits and, optionally, a small sensor power load. The separate power for motors would need to be supplied to the motors through the FETs (or H bridges, if you used them). I suggest an approximately 7 V (5 alkaline or 6 NiMH cells) supply to Vin to power the Arduino and the sensors and a separate 3V supply for the motors.

    Jujulia:
    When I reduce the speed it happens that the robo doesn’t move at all. I think i got the powersupply wrong or the ratio of the gear clogs the robo from moving…

    Changing the motors to a supply voltage that is within their specification (1.5 to 3 V, IIRC) may help with that.

    Jujulia:
    When moving over white surface the sensors show numbers that are very high (about 1000 a.s.o) when moving over black surface the numbers are very low (under 10 usually), that’s why i picked 50… is it better to map those numbers to a scale from 1 to 10 and than take 5 as number for comparising? Is this the reason why the robot works so imprecise?

    I don’t think mapping the numbers will help. I suggest you change the motor power supply first, then see if there’s still an erratic operation problem.

    Have Fun,

    Eric](http://arduino.cc/en/Main/ArduinoBoardDiecimila)

    hi eric,

    Given the limitted current you have, I suggest you keep the sensors off most of the time and turn each one on only when you read it.

    I got the sensorcode from the Arduino-library and that codelines are the only thing I really don’t understand in my code-

    the long RCtime-request.

    I thought the line “digitalWrite(sensPin, LOW)” would turn the pin low…

    The main concern I have now with keeping your motors is providing them the correct power. At the moment, you appear to be running 1.5 to 3 V motors at 5 V. That is likely to shorten the life of the motors, although using PWM should lessen the effect, as the average power and, therefore, the heating, is less.

    That’s true, I guess this is also the reason why they are running so fast. If it’s not possible to pull down the 5V to 3V with a resistor I rather go with a external powersupply just for the motors threw the FAT constellation (probably with 2 Batteries.)

    I need it for an exhibition, they should run about 5 hours for 5 days, so it should be quite stable.

    Please provide the specifications or part number for the FETs you are using. (A link to a datasheet in English would be great, but if you give me a part number, I should be able to find one.)

    Transistors:

    One transistor is called BUZ72A or BUZ 72A

    It also says VC818107 , A843 and L on the fet itself

    this is the datasheet:

    [

    Uploaded with [ImageShack.us

    The other transistor is called ION 10 GAA705, H15,

    but unfortunately i couldn’t find a description for this transistor.

    Diode

    One diode to the BUZ 72A is a IN4007

    this is the datasheet:

    http://www.datasheetarchive.com/Indexer … 66289.html

    I couldn’t find a description for the other diode on the diode it says:

    07 852 und IN

    If you are connecting through USB, that’s providing 5 V. What isn’t clear is how Vin is being powered, because that may depend on which Arduino you are using. The images you’ve provided appear to show a [Arduino Diecimila or earlier (later boards have automatic power source selection, your images show the selection jumper block), but there have been two generations of boards (Duemilanove and Uno) since then. Please let me know which board you have, so I can look at the correct power schematic.[/quote]

    I’m using the Arduino Duemilanove, I believe, that this is a newer version…

    Alkaline AA cells are 1.5 V, but NiCd and NiMH are 1.2 V. Which are you planning to use? You should review the power supply recommendations for whichever Arduino you have. The recent ones specify a minimum input voltage of 6 V and recommend a minimum input voltage of 7 V, when not being powered through USB.

    I would use 2 1.5V to provide 3 for the motor.

    I also have the option to use either a 910mAh akku with 4.2V maximum recharging voltage,

    Modelnr: SLPB593459H3

    http://bit.ly/htu1zZ

    or a E603048 with 900mAh 3.7V

    http://bit.ly/heygTP

    You’ll need to check the data sheet for the sensors and, perhaps, the datasheets for the components from which the sensors are built to determine that. On a positive note, the Arduino has a 5 V regulator and it probably can supply one sensor at a time with regulated 5 V power. I do not, however, suggest trying to power more than one sensor at a time (or the motors at all) that way.I don’t see any way to supply 3 V to Vin and get a 5 V Arduino to work. The Arduino’s internal power components take Vin and regulate it down to 5 V to power the Arduino’s internal circuits and, optionally, a small sensor power load. The separate power for motors would need to be supplied to the motors through the FETs (or H bridges, if you used them). I suggest an approximately 7 V (5 alkaline or 6 NiMH cells) supply to Vin to power the Arduino and the sensors and a separate 3V supply for the motors.

    OK i understand the circuit now, thank you! i will use a 7V for the arduino and sensors

    and a 3V through the FETS for the motors.

    i found akku packs, that usually have 7,2 V, is this adequate?

    for example: http://bit.ly/hJEvhA

    Changing the motors to a supply voltage that is within their specification (1.5 to 3 V, IIRC) may help with that.

    don’t think mapping the numbers will help. I suggest you change the motor power supply first, then see if there’s still an erratic operation problem.

    i will try that out. i’m just not sure about the diodes and transistors, now that I’ve seen that they don’t have the same name.

    They were provided so I never checked their specifications,

    and maybe they are just not right for the motors…

    thanks again,

    you helped me the most so far!

    julia](http://arduino.cc/en/Main/ArduinoBoardDiecimila)

    ](http://imageshack.us)](ImageShack - Best place for all of your image hosting and image sharing needs)

    Jujulia:
    I got the sensorcode from the Arduino-library and that codelines are the only thing I really don’t understand in my code- the long RCtime-request. I thought the line “digitalWrite(sensPin, LOW)” would turn the pin low…

    If the pin is in digital mode, that will set it low. If the pin is in analog mode, IIRC, that command turns off the pull-up. If you look at the Parallax site, the code there switches both the sense pin and the sensor’s power pin. (Your circuit has the sensor power pins wired directly to power. You do, however, need to make sure the Arduino can provide enough power to drive the sensors. If not, there’s always the option of using FETs to switch the sensor power.)

    Jujulia:
    That’s true, I guess this is also the reason why they are running so fast. If it’s not possible to pull down the 5V to 3V with a resistor I rather go with a external powersupply just for the motors threw the FAT constellation (probably with 2 Batteries.)

    If you look at the schematics of the MOSFET-based power controllers that SparkFun has released recently, you’ll see how they work. In your case, it may be as simple as connecting the side of the motor you have going to the power bus to the positive side of a ~3 V battery and connecting the negative side of that battery to the system’s ground.

    Jujulia:
    I need it for an exhibition, they should run about 5 hours for 5 days, so it should be quite stable.

    I doubt you’re going to find a reasonable battery that will provide 25 operating hours for the motors or even the sensors. If you can get 5 hours and recharge each night, is that workable for you?

    Jujulia:
    Transistors:

    One transistor is called BUZ72A or BUZ 72A It also says VC818107 , A843 and L on the fet itself this is the datasheet:

    The other transistor is called ION 10 GAA705, H15, but unfortunately i couldn’t find a description for this transistor.

    Diode

    One diode to the BUZ 72A is a IN4007 this is the datasheet:

    I couldn’t find a description for the other diode on the diode it says: 07 852 und IN

    I couldn’t find anything on the other two components.

    Jujulia:
    I would use 2 1.5V to provide 3 for the motor.

    I also have the option to use either a 910mAh akku with 4.2V maximum recharging voltage,

    Modelnr: SLPB593459H3

    http://bit.ly/htu1zZ

    or a E603048 with 900mAh 3.7V

    http://bit.ly/heygTP

    Those appear to be LiPo battery packs. Li-based batteries provide higher energy density than Ni-based batteries. However, the Li-based batteries require special chargers and are generally considered to present higher risks. Frankly, I think you’d be better served by standard NiMH batteries in holders. That way you could use readily available rechargeable cells and readily available chargers. Also, you could use the same cells (AA, for example) for the motors and the electronics. You would need holders for different numbers of cells for the two applications, but you could work from a common bucket of charged NiMH AA cells.

    Jujulia:
    OK i understand the circuit now, thank you! i will use a 7V for the arduino and sensors

    and a 3V through the FETS for the motors. i found akku packs, that usually have 7,2 V, is this adequate?

    for example: http://bit.ly/hJEvhA

    7.2 V is comfortably in the recommended input range for Arduino. (Basically, you need 5 V to run the electronics and need to allow ~ 1.5 V as the drop through the regulator. So, something slightly above 6.5 V is the target. The regulator will tolerate higher voltage, but the excess voltage will just be converted to heat, so why do that?

    Those appear to be sets of six AA cells, wired in series and wrapped in plastic. Unfortunately, 800 mAh is very low for capacity of an NiMH AA cell. Most are more than 2000 mAh. For example:

    [2500 mAh AA NiMH cells offered by SparkFun.. If you look at the bottom of that product page, you’ll see a few holders. I haven’t checked, but Conrad (which appears to be your preferred supplier) probably has an assortment of holders.

    Jujulia:
    i will try that out. i’m just not sure about the diodes and transistors, now that I’ve seen that they don’t have the same name. They were provided so I never checked their specifications, and maybe they are just not right for the motors…

    I suggest you try the hardware you have. The components that you did match to datasheets appear to be suitable. BTW, the diode is there to protect the FET, not to protect the motor. Diodes used for this purpose are called by many names, I usually call them [“fly-back” diodes. The FET is being used as a current switch. The PWM signal from the Arduino turn the FET on and off and the FET connects and disconnects the motor from ground.

    Jujulia:
    thanks again,

    you helped me the most so far!

    You’re welcome! I wasn’t aware I was competing with anyone in this. :wink:

    Have Fun,

    Eric](Flyback diode - Wikipedia)](2500 mAh NiMH Battery - AA - PRT-00335 - SparkFun Electronics)

    Hi julia,

    Eric did a great job helping you out but id like to offer a bit of advice as well.

    For your sensors, try reading all of your sensors at the beginning of your loop() and storing the values within a register. Then do all your comparing/calculation work with thous stored values. This will make things a lot easier because the values will not change on you in the middle of the loop.