Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Yun Jin Yonggledel임동교이하늘
Published © GPL3+

Innovation Lab #19: Motor Drive Motor

A Bongilcheon High School Innovation Lab project.

BeginnerShowcase (no instructions)10 minutes780
Innovation Lab #19: Motor Drive Motor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino DC Motor
×1
Arduino Motor Drive Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Motor Drive_Motor forward

Arduino
The car goes forward.
int AIA = 5;   
int AIB = 6;   
int BIA = 9;
int BIB = 10;
int spe = 200;
 
void setup() {
  pinMode(AIA, OUTPUT); 
  pinMode(AIB, OUTPUT);
  pinMode(BIA, OUTPUT); 
  pinMode(BIB, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  forward();
  delay(1000);
} 


void forward() {
  analogWrite(AIA, 0);
  analogWrite(AIB, spe);
  analogWrite(BIA, 0);
  analogWrite(BIB, spe);
}

Motor Drive_Motor backward

Arduino
The car goes backward.
int AIA = 5;   
int AIB = 6;   
int BIA = 9;
int BIB = 10;
int spe = 200;

void setup() {
  pinMode(AIA, OUTPUT); 
  pinMode(AIB, OUTPUT);
  pinMode(BIA, OUTPUT); 
  pinMode(BIB, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  backward();
  delay(1000);
} 

void backward() {
  analogWrite(AIA, spe);
  analogWrite(AIB, 0);
  analogWrite(BIA, spe);
  analogWrite(BIB, 0);
}

Motor Drive_Motor forward / backward / stopped

Arduino
The car went forward and went backward and stopped.
int AIA = 5;   
int AIB = 6;   
int BIA = 9;
int BIB = 10;
int spe = 200;

void setup() {
  pinMode(AIA, OUTPUT); 
  pinMode(AIB, OUTPUT);
  pinMode(BIA, OUTPUT); 
  pinMode(BIB, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  forward();
  delay(1000);
  backward();
  delay(1000);
  stopp();
  delay(1000);
} 


void forward() {
  analogWrite(AIA, 0);
  analogWrite(AIB, spe);
  analogWrite(BIA, 0);
  analogWrite(BIB, spe);
}

void backward() {
  analogWrite(AIA, spe);
  analogWrite(AIB, 0);
  analogWrite(BIA, spe);
  analogWrite(BIB, 0);
}

void stopp() {
  analogWrite(AIA, 0);
  analogWrite(AIB, 0);
  analogWrite(BIA, 0);
  analogWrite(BIB, 0);
}

Credits

Yun Jin Yong
6 projects • 10 followers
Contact
gledel
100 projects • 116 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
Contact
임동교
0 projects • 12 followers
Contact
이하늘
5 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.