Tutorial, Arduino 4x4 Robot

6,125 Views
Blog entry by online123 on Sun, 2014-08-17 02:59  
online123's picture

Many people ask me about making a small robot. The truth is it's a bit of a difficult question to answer as there are many ways to do it and of course many different types of robots. In most cases, type robots are typically mounted drive servomotors or DC motors. This is what I am going to show you today, a robot with four-wheel drive with DC motors. The idea here is not to make a big intelligent robot that is able to bring us breakfast in bed (although it would be milk!), But the basis for creating a small robot with four-wheel drive based on Arduino that I could be the basis for a more complete and intelligent robot, including various types of sensors such as distance, GPS or telemetry. 
 
It is a very basic tutorial that everyone can do easily and in no time. After having the base, we can add more complexity. Of course do not hesitate to leave your comments, questions and suggestions!
 

Tutorial, Arduino 4x4 Robot 

As I said before, this little tutorial aims to provide a basis of locomotion for a robot, with its chassis, engines, engine driver and Arduino. Say it is the fundamental part for a robot can move. Once we have a system which are able to control (forward, backward and turns), we can go including some additional sensors depending on the type of robot you want. At this point, and depends largely on the imagination of each, which can range from a simple robot to circulate with predetermined and fixed patterns to a complete robot can avoid obstacles using distance sensors or GPS guided. 
 
Without further ado, we begin! 
 
The key parts to a robot of these characteristics are:
1. chassis 
2. Programmable control system (Arduino) 
3. Motor Controller 
4. Food 
5. Connections 
 

the chassis 

Of course, we can make a frame as either wood, PVC or other light materials, but need more time and planning. Also, do not always know exactly what components are to be used with their respective dimensions and possible drawbacks that arise. Then if we choose to build the chassis from scratch, we need tools and often not at hand. In my case, I chose to use a ready-made chassis is also compatible with Arduino Duemilanove or Arduino UNO new. This case is very sturdy and is made of aluminum, includes four DC motors with built 6V gearbox, wheels, screws, add platform for sensors, power switch, battery box and some wires 5xAA. With him we have practically solved mechanical part and we can spend the next phase of the project.
 

Programmable control system (Arduino) 

Obviously, we need something that allows us to program the robot at will. Since the chassis and has holes for screwing a USB Arduino, I used that model. In my case it is an Arduino Duemilanove, but you can also use an Arduino UNO or Sparkfun Arduino Pro 328, because the characteristics are the same and the code is fully compatible.

Motor Controller 

An Arduino can not directly manage DC motors, since the maximum current that is capable of providing its output pins is 20mA scarce. Therefore, we need a motor controller which is able to support the load of the engine. This driver will be managed in turn by the Arduino. We always select a controller with engines powerful enough to us to go to use. The four motors included with the chassis work to 6 V and consume about 300 mA at full load. Since we have four engines, we get a total consumption of approximately 4 x 300 = about 1.2 Amps.
A good candidate because of its size and its performance is the dual H-bridge driver based on the popular L298 driver. With two outs, has enough power (25W) to feed the four engines. Wait ... how two outputs? but if we have four engines, then how do? 
 
Well do not worry, because even though this driver only has two outputs, each will use to power the motors in pairs. Group the motors so that the two corresponding to the left of the chassis pararelo be wired and the same for the two corresponding to the right of the chassis motors. With this, we can connect the two left to output engines and the two right engines to output B, as shown in the image:
We must pay attention to how cableamos engines because as you can see, each pair is in the opposite direction, so we cross the wires to rotate in the same direction when we feed. Before continuing, it is advisable to apply tension once wired to check the direction of rotation.
 

Food !

The food is simple because we have a base 5 AA batteries which give us a total of 7.5 volts. This shall be sufficient to power the motors and our Arduino. The atronillada leave the base chassis from the bottom.
Meanwhile, assemble the Arduino and the motor controller in place. Use metal brackets with screws, as we give you a safe and reliable installation.
 

Connections 

Then cableamos all well placed with the length of the cables just do not bother. Notice that when wiring the motors in groups of two, only have four wires, which are those that go to the controller.
Do not forget to solder the wires to the ignition switch. The chassis includes one of three contacts, but I preferred to ride one of six.
After connecting the motor to the controller, it's time to connect the Arduino. In the above image is not shown, but do not forget to also contact the power wires coming from the switch! Iran VMS and connected to GND. 
 
The connections to the Arduino will be as follows: 
 
Arduino PIN 8 -> I1 
Arduino PIN 9 -> I2 
Arduino PIN 11 -> EA 
Arduino pin 6 -> I3 
Arduino PIN 7 -> I4 
Arduino PIN 10 -> EB 
These are the control signals are also used as the PWM pin can then vary the motor speed. Also you will need to connect the output of the controller marked as + 5V pin of the Arduino out as VIN. This causes the engine controller to provide power to the Arduino board. Do not forget also to unite the masses with the GND pin.
I used prototype cables male / female to make it easy:

source Code 

Not much to say about the source code. I made a small set of functions that let you move forward or backward at the speed and direction you want. At the start of the program in the Setup () function I set the pins as outputs and then in the main loop in the Loop () function, I've put a forward sequence for two seconds, kick for another two seconds, turn left and giroderecha two second well. Then the program starts again. It's a good way of doing the first tests and see how the robot behaves. Notice that for rotation needed to rotate the left side as opposed to the right. It is the same system that the tanks. With different speeds we can rotate more or less as needed.
 
  1. /********************************************************************************************* 
  2.  
  3.   Tutorial: Robot 4x4 con Arduino 
  4.   Autor: Oscar Gonzalez - 16 Octubre 2010 
  5.   http://blog.bricogeek.com/noticias/tutoriales/tutorial-robot-4x4-con-arduino/ 
  6.  
  7.  ********************************************************************************************/  
  8. #define MOTOR1_CTL1  8  // I1  
  9. #define MOTOR1_CTL2  9  // I2  
  10. #define MOTOR1_PWM   11 // EA  
  11.   
  12. #define MOTOR2_CTL1  6  // I3  
  13. #define MOTOR2_CTL2  7  // I4  
  14. #define MOTOR2_PWM   10 // EB  
  15.   
  16. #define MOTOR_DIR_FORWARD  0  
  17. #define MOTOR_DIR_BACKWARD   1  
  18.   
  19. void setup()  
  20. {  
  21.   // Setup pins for motor 1  
  22.    pinMode(MOTOR1_CTL1,OUTPUT);  
  23.    pinMode(MOTOR1_CTL2,OUTPUT);  
  24.    pinMode(MOTOR1_PWM,OUTPUT);  
  25.      
  26.   // Setup pins for motor 2  
  27.    pinMode(MOTOR2_CTL1,OUTPUT);  
  28.    pinMode(MOTOR2_CTL2,OUTPUT);  
  29.    pinMode(MOTOR2_PWM,OUTPUT);     
  30. }  
  31.   
  32. void setSpeed(char motor_num, char motor_speed)  
  33. {  
  34.    if (motor_num == 1)  
  35.    {  
  36.       analogWrite(MOTOR1_PWM, motor_speed);  
  37.    }     
  38.    else  
  39.    {  
  40.       analogWrite(MOTOR2_PWM, motor_speed);  
  41.    }  
  42. }  
  43.   
  44. void motorStart(char motor_num, byte direction)  
  45. {  
  46.     
  47.    char pin_ctl1;  
  48.    char pin_ctl2;  
  49.      
  50.    if (motor_num == 1)  
  51.    {  
  52.       pin_ctl1 = MOTOR1_CTL1;  
  53.       pin_ctl2 = MOTOR1_CTL2;  
  54.    }     
  55.    else  
  56.    {  
  57.       pin_ctl1 = MOTOR2_CTL1;  
  58.       pin_ctl2 = MOTOR2_CTL2;       
  59.    }  
  60.     
  61.    switch (direction)  
  62.    {  
  63.      case MOTOR_DIR_FORWARD:  
  64.      {  
  65.        digitalWrite(pin_ctl1,LOW);  
  66.        digitalWrite(pin_ctl2,HIGH);            
  67.      }  
  68.      break;   
  69.             
  70.      case MOTOR_DIR_BACKWARD:  
  71.      {  
  72.         digitalWrite(pin_ctl1,HIGH);  
  73.         digitalWrite(pin_ctl2,LOW);            
  74.      }  
  75.      break;           
  76.    }  
  77. }  
  78.   
  79. void motorStop(char motor_num)  
  80. {  
  81.    setSpeed(motor_num, 0);  
  82.    if (motor_num == 1)  
  83.    {  
  84.      digitalWrite(MOTOR1_CTL1,HIGH);  
  85.      digitalWrite(MOTOR1_CTL2,HIGH);       
  86.    }  
  87.    else  
  88.    {  
  89.      digitalWrite(MOTOR2_CTL1,HIGH);  
  90.      digitalWrite(MOTOR2_CTL2,HIGH);       
  91.    }  
  92. }  
  93.   
  94. void loop()  
  95. {  
  96.   // Start motors!  
  97.   motorStart(1, MOTOR_DIR_FORWARD);    
  98.   setSpeed(1, 200);  
  99.   motorStart(2, MOTOR_DIR_FORWARD);        
  100.   setSpeed(2, 200);  
  101.     
  102.   delay(2000);  
  103.     
  104.   motorStart(1, MOTOR_DIR_BACKWARD);    
  105.   setSpeed(1, 200);  
  106.   motorStart(2, MOTOR_DIR_BACKWARD);        
  107.   setSpeed(2, 200);  
  108.     
  109.   delay(2000);  
  110.     
  111.   motorStart(1, MOTOR_DIR_FORWARD);    
  112.   setSpeed(1, 140);  
  113.   motorStart(2, MOTOR_DIR_BACKWARD);        
  114.   setSpeed(2, 140);    
  115.     
  116.   delay(2000);  
  117.     
  118.   motorStart(1, MOTOR_DIR_BACKWARD);    
  119.   setSpeed(1, 140);  
  120.   motorStart(2, MOTOR_DIR_FORWARD);        
  121.   setSpeed(2, 140);    
  122.     
  123.   delay(2000);    
  124.     
  125. }  

__________________________________________________________________________________________

Comments

Add a new comment

Login or register to post comments