Motor Control

02/11/2015

Motor Control, to control the left and right motors for our robotics project we need to create five functions, the code for each functions is described further down:

  • forward()
  • backward()
  • left()
  • right()
  • stop()

At the beginning of our code we initialised six variables to pin number on our Arduino, these pins are wired to an h-bridge motor shield for controlling our motors:

  • pinRB = 3;  // Wired to IN3 on the Motor shield
  • pinRF = 2;  // Wired to IN4 on the Motor shield
  • pinLB = 7;  // Wired to IN1 on the Motor shield
  • pinRB = 4;  // Wired to IN2 on the Motor shield
  • ENA = 5;    // Wired to ENA on the Motor shield
  • ENB = 6;    // Wired to ENB on the Motor shield

ArduinoUnoSmd Motor shield

This code controls the movement of our Roverbot moving forwards:

This code controls the movement of our Roverbot moving backwards:

 

This code controls the movement of our Roverbot moving left:

This code controls the movement of our Roverbot moving right:

This code controls the movement of our Roverbot by stopping it: