Saturday, 20 September 2014

UNDERSTANDING ARDUINO AND PROGRAM CONNECTIONS


I am gonna explain how the connections are going to be made in an arduino based on your program.
SINCE i have already posted a one sensor program i would like to explain the connections based on that code.



ONE SENSOR CODE
void setup()
{
pinMode(4,OUTPUT); //enable a
pinMode(8,OUTPUT); //enable b
pinMode(2,OUTPUT); //motor A
pinMode(3,OUTPUT);//motor A
pinMode(10,OUTPUT);//motor b
pinMode(9,OUTPUT);//MOTOR B
pinMode(5,INPUT);
pinMode(6,INPUT);
Serial.begin(9600);
}
void loop()
{
  digitalWrite(4,HIGH);
  digitalWrite(8,HIGH);
  int lsen,rsen;
  lsen=digitalRead(5);
  rsen=digitalRead(6);
  Serial.println(lsen);
  if((lsen==HIGH)&&(rsen==LOW))
  {
    right();
  }
  else if((rsen==HIGH)&&(lsen==LOW))
  {
    left();
  }
  else if((rsen==HIGH)&&(lsen==HIGH))
  {
    Stop();
  }
}
  
  void right()
  {
  digitalWrite(2,HIGH);
  digitalWrite(3,LOW);
  }
  void left()
  {
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
  }
  void Stop()
  {
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(10,LOW);
    digitalWrite(9,LOW);
  }


REFER PREVIOUS POST TO DOWNLOAD THE CODE...!!!

before getting into the connections you must know how a DC motor works .

For a DC motor as the above diagram depicts when you supply a potential difference on the coil of the motor it generates a torque in either clock-Wise or anti clock wise direction.For example consider it has a torque in clock-wise direction and if you wish to have a anti-torque then it would be better to change the direction of the flow of current.
So in order for the ROBOT to move forward or backward both the wheels has to rotate in the same direction.If the ROBOT has to take a left or right turn then two turns are possible

TYPES OF TURNS A WHEELED ROBOT CAN MAKE

1)90 degree turn
2)Fast angled turn

1) If you need your ROBOT to get a 90 degree turn then you must rotate one wheel in clockwise and another wheel in anti-clockwise direction. 

2)if you need a fast angled turn then it is desired to stop either wheel and run the next wheel.

HOW TO TAKE A LEFT TURN or RIGHT TURN


If you wish your robot to take a left turn with 90 degree turn then it is desired to have a anti-clock torque with the left wheel and clockwise torque with the right wheel.
similarly if your robot wants to take a fight 90 degree turn then it must be vise-verse.

if you wish your robot to make a fast angled left turn then it is desired to stop the left motor and run the right motor and if you wish your robot to take a right turn then it must have a reflecting effect.


BASIC UNDERSTANDING

so from the above topics you must know that you need to control the polarities of the motor using the arduino.So when you need your robot to take a left turn you must give the possible potential difference to the motor and achieve the task.


No comments:

Post a Comment