AUTHOR: Kevin Shin
Your show and tell can be about anything you accomplished other than research. This is about an action realized.
<aside> ❓ Tutorial: Clearly explain the necessary information and actions to arrive at an outcome
</aside>
Initial Goal:
Realized Outcome:
Outline/Framework/Recipe/Steps
Wire up a breadboard according to the wire diagram below. Pin assignment on the Arduino is important for the code to work properly. Test and connect DC power.
Example Code - Spins motors both direction & variable speed
// Each motor requires power (VCC, GND) & 3 pins
// Motor A connections - Arduino Pin Assignment
int enA = 9;
int in1 = 8;
int in2 = 7;
// Motor B connections - Arduino Pin Assignment
int enB = 3;
int in3 = 5;
int in4 = 4;
void setup() {
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT); // Controls speed for motor A
pinMode(in1, OUTPUT); // Direction for motor A
pinMode(in2, OUTPUT); // Direction for motor A
pinMode(enB, OUTPUT); // Controls speed for motor B
pinMode(in3, OUTPUT); // Direction for motor B
pinMode(in4, OUTPUT); // Direction for motor B
// Turn off motors - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop() {
directionControl(); // the motor will alternate between Clockwise & CounterClockwise
delay(1000);
speedControl();
delay(1000);
}
// This function lets you control spinning direction of motors
void directionControl() {
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
analogWrite(enA, 255);
analogWrite(enB, 255);
// Turn on motor A & B
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(2000);
// Now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000);
// Turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
// This function lets you control speed of the motors
void speedControl() {
// 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++) {
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}
// Decelerate from maximum speed to zero
for (int i = 255; i >= 0; --i) {
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
}
// Now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
To implement Arduino to listen on the I2C