Devices & Components
Arduino Uno Rev3
TB6612 1.2A DC/Stepper Motor Driver Breakout Board
linear actuator with 12V DC motor, Mini Electric Linear Actuator Stroke 2"–Force 4.5 lbs–12V | High-Speed 1.97"/sec–Weight 0.15KG Ideal for Intelligent Range Hood, Fan Blades, Cabinets, Window Opener, Robotics, Home Automation
12V DC Power Supply with DC terminal connector, SHNITPWR 4V - 12V Power Supply 10A 120W AC to DC Adapter DC 4V 4.5V 5V 6V 7V 8V 9V 10V 11V 12V Voltage Adjustable Universal Power Converter Transformer 100-240V AC In with 14 Tips & Polarity Converter
Hardware & Tools
Digilent Screwdriver
Software & Tools
Arduino IDE
Project description
Code
Linear_Actuator_DC_Motor
c_cpp
This is Arduino code that you can upload in the Arduino IDE interface that controls the motor.
1/****************************************************************************** 2linear_actuator_DCmotor12V 3Modified By: Bo Bomwan, November 2022 4NOTES: This code works for either 1 motor, or 2 motors. In this code, I have it controlling only 1 motor (no pins are connected for the 2nd motor). 5 6TestRun.ino 7TB6612FNG H-Bridge Motor Driver Example code 8Michelle @ SparkFun Electronics 98/20/16 10https://github.com/sparkfun/SparkFun_TB6612FNG_Arduino_Library 11 12Uses 2 motors to show examples of the functions in the library. This causes 13a robot to do a little 'jig'. Each movement has an equal and opposite movement 14so assuming your motors are balanced the bot should end up at the same place it 15started. 16 17Resources: 18TB6612 SparkFun Library 19 20Development environment specifics: 21Developed on Arduino 1.6.4 22Developed with ROB-9457 23******************************************************************************/ 24 25// This is the library for the TB6612 that contains the class Motor and all the 26// functions 27#include <SparkFun_TB6612.h> 28 29// Pins for all inputs, keep in mind the PWM defines must be on PWM pins 30// the default pins listed are the ones used on the Redbot (ROB-12097) with 31// the exception of STBY which the Redbot controls with a physical switch 32#define AIN1 5 33#define AIN2 4 34#define PWMA 10 35#define STBY 9 36 37#define BIN1 7 38#define BIN2 8 39#define PWMB 6 40 41 42// these constants are used to allow you to make your motor configuration 43// line up with function names like forward. Value can be 1 or -1 44const int offsetA = 1; 45const int offsetB = 1; 46 47// Initializing motors. The library will allow you to initialize as many 48// motors as you have memory for. If you are using functions like forward 49// that take 2 motors as arguements you can either write new functions or 50// call the function more than once. 51Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY); 52Motor motor2 = Motor(BIN1, BIN2, PWMB, offsetB, STBY); 53 54 55void setup() 56{ 57 //Nothing here 58} 59 60 61void loop() 62{ 63 64 //Use of the drive function which takes as arguements the speed 65 //and optional duration. A negative speed will cause it to go 66 //backwards. Speed can be from -255 to 255. Also use of the 67 //brake function which takes no arguements. 68 motor1.drive(255,1000); 69 motor1.drive(-255,1000); 70 motor1.brake(); 71 delay(1000); 72 73} 74 75 76// Drive in direction given by sign, at speed given by magnitude of the 77//parameter. 78void drive(int speed); 79 80// drive(), but with a delay(duration) 81void drive(int speed, int duration); 82 83//currently not implemented 84//void stop(); // Stop motors, but allow them to coast to a halt. 85//void coast(); // Stop motors, but allow them to coast to a halt. 86 87//Stops motor by setting both input pins high 88void brake(); 89 90//set the chip to standby mode. The drive function takes it out of standby 91//(forward, back, left, and right all call drive) 92void standby(); 93 94//Takes 2 motors and goes forward, if it does not go forward adjust offset 95//values until it does. These will also take a negative number and go backwards 96//There is also an optional speed input, if speed is not used, the function will 97//use the DEFAULTSPEED constant. 98void forward(Motor motor1, Motor motor2, int speed); 99void forward(Motor motor1, Motor motor2); 100 101//Similar to forward, will take 2 motors and go backwards. This will take either 102//a positive or negative number and will go backwards either way. Once again the 103//speed input is optional and will use DEFAULTSPEED if it is not defined. 104void back(Motor motor1, Motor motor2, int speed); 105void back(Motor motor1, Motor motor2); 106 107//Left and right take 2 motors, and it is important the order they are sent. 108//The left motor should be on the left side of the bot. These functions 109//also take a speed value 110void left(Motor left, Motor right, int speed); 111void right(Motor left, Motor right, int speed); 112 113//This function takes 2 motors and and brakes them 114void brake(Motor motor1, Motor motor2); 115
Downloadable files
Wiring Diagram
This is a Fritzing wiring diagram that shows you how to connect the wires (jumper wires) to the parts of this project.
Wiring Diagram

Comments
Only logged in users can leave comments