First Robot – Arduino Project

I built a simple robot to learn about controlling motors with a micro controller unit. The cat was not impressed.

Parts list

  • Arduino Uno – generic
  • Motor controller module – Osepp Motor Driver MTD-01 (there are many others available) based on L298 Integrated Circuit chip
  • Robot kit – consists of electric motor with gearbox and wheel (x2) and chassis, caster wheel, AA battery box and hardware (from Gowoops sold at amazon.com about $12)
Gowoops Car Chassis Kit at Amazon

  • Power bank to power Arduino
  • AA batteries to power motors
  • double sided foam mounting tape to hold electronic modules to chassis
  • jumper cables, USB cables
  • computer with Arduino development environment software

Assembly and programming

The diagram above is an example of how to wire an Arduino, motor controller module, and electric motors.

This excellent web site tutorial explains everything so I’ll just direct you there: https://dronebotworkshop.com/dc-motors-l298n-h-bridge/

Notes

  • The two electric motors in my kit run at different speeds. This is a low cost proof of concept project.
  • Double sided foam mounting tape is a quick and easy way to hold the electronic modules to the chassis.
  • There are a lot of resources on the internet, use your favorite search engine to zero in on what you need.
  • Another excellent resource: http://www.sharetechnote.com/html/Arduino_MotorBasics.html
  • Why a motor controller module? The Arduino does not output enough power to drive these electric motors. The Arduino GPIO outputs are 5V and 20mA maximum. These electric motors require more voltage (volts or V) and more current (mA or milliAmps). The motor controller module accepts lower power pulse width regulated signals from the Arduino and outputs the higher voltage and current required by the electric motors. The source of the higher power comes from the AA batteries in this case. The voltage is controlled to control motor speed and the polarity is reversed to reverse the motor direction.

Sketch (Arduino calls programs sketches) for reference:

/*  
  L298N Motor Demonstration
  L298N-Motor-Demo.ino
  Demonstrates functions of L298N Motor Controller
  
  DroneBot Workshop 2017
  
Welcome to the Workshop!
*/ // Motor A int enA = 9; int in1 = 8; int in2 = 7; // Motor B int enB = 3; int in3 = 4; int in4 = 5; void setup() { // Set all the motor control pins to outputs pinMode(enA, OUTPUT); pinMode(enB, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); } void demoOne() { // This function will run the motors in both directions at a fixed speed // Turn on motor A digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Set speed to 200 out of possible range 0~255 analogWrite(enA, 200); // Turn on motor B digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Set speed to 200 out of possible range 0~255 analogWrite(enB, 200); delay(1000); // Now change motor directions digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); delay(1000); // Now turn off motors digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } void demoTwo() { // This function will run the motors across the range of possible speeds // Note that maximum speed is determined by the motor itself and the operating voltage // Turn on motors digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // Accelerate from zero to maximum speed for (int i = 0; i < 256; i=i+5) { analogWrite(enA, i); analogWrite(enB, i); delay(20); } // Decelerate from maximum speed to zero for (int i = 255; i >= 0; i=i-5) { analogWrite(enA, i); analogWrite(enB, i); delay(20); } // Now turn off motors digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } void demoThree() { // This function will run the motors in opposite directions at a fixed speed // Turn on motor A digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // Set speed to 200 out of possible range 0~255 analogWrite(enA, 200); // Turn on motor B digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Set speed to 200 out of possible range 0~255 analogWrite(enB, 200); delay(1000); // Now change motor directions digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); delay(1000); // Now turn off motors digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } void loop() { demoOne(); delay(1000); demoTwo(); delay(1000); demoThree(); delay(1000); }

Leave a Reply

Your email address will not be published. Required fields are marked *