This week we are going to build out car chassis — finally.
Now we switch over and focus on a small mechanical build instead of electrical. I love building things! And with instructions in Chinese, what could possibly go wrong?
The presentation that I cover can be downloaded here as well.
Step 1: Introduction & What I’ve Built
Final update on my desk light temperature project, it turned out great. I 3D printed a case and everything.
Step 2: Disassemble & Parts Review
Oops… Sometimes I wonder why I try to plan ahead. In this video, I completely disassemble the car because I lost the video that I shoot when I originally put it together.
Step 3: Chassis Assembly
Grab a screwdriver and maybe a small pair of pliers and let’s begin.
Step 4: The Wiring
The wiring is not too difficult, but there are some steps you need to follow. Let’s get the wiring all organized. If you want, you can grab some zip-ties or some tape to hold the wires in place.
Step 5: Attaching Bluetooth & First Test!
The Bluetooth module will get installed on the analog header pins, it is important that you plug it in correctly.
Step 6: Writing The Code
And now the fun part. Or the hard part. It all depends on if you like to write code! (Code is below the video if you want to just copy and paste it. No one will know.
#include <SoftwareSerial.h>
#include <AFMotor.h>
const int rxPin = A0;
const int txPin = A1;
SoftwareSerial mySerial(rxPin, txPin); // RX, TX
AF_DCMotor mLeft(3);
AF_DCMotor mRight(2);
void setup() {
Serial.begin(9600);
Serial.println("Goodnight moon!");
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
mLeft.setSpeed(255);
mRight.setSpeed(255);
mLeft.run(FORWARD);
mRight.run(FORWARD);
delay(1000);
mLeft.run(RELEASE);
mRight.run(RELEASE);
}
void loop() {
if (mySerial.available()) {
char command = mySerial.read();
Serial.print("cmd: ");
Serial.println(command);
if (command == 'f' || command == 'F') {
Serial.println("forward");
mLeft.setSpeed(255);
mRight.setSpeed(255);
mLeft.run(FORWARD);
mRight.run(FORWARD);
} else if (command == 'b' || command == 'B') {
Serial.println("backward");
mLeft.setSpeed(255);
mRight.setSpeed(255);
mLeft.run(BACKWARD);
mRight.run(BACKWARD);
} else if (command == 'l' || command == 'L') {
Serial.println("left");
mRight.setSpeed(255);
mRight.run(FORWARD);
} else if (command == 'r' || command == 'R' ) {
Serial.println("right");
mLeft.setSpeed(255);
mLeft.run(FORWARD);
} else if (command == 'e' || command == 'E' ) {
mRight.setSpeed(255);
mRight.run(BACKWARD);
mLeft.setSpeed(255);
mLeft.run(FORWARD);
delay(2000);
mRight.setSpeed(255);
mRight.run(FORWARD);
mLeft.setSpeed(255);
mLeft.run(BACKWARD);
delay(2000);
mLeft.setSpeed(0);
mRight.setSpeed(0);
} else if (command == 'm' || command == 'M' ) {
mRight.setSpeed(255);
mRight.run(FORWARD);
mLeft.setSpeed(255);
mLeft.run(FORWARD);
delay(500);
mRight.setSpeed(255);
mRight.run(BACKWARD);
mLeft.setSpeed(255);
mLeft.run(BACKWARD);
delay(500);
mLeft.setSpeed(0);
mRight.setSpeed(0);
} else if (command == 'w' || command == 'W' ) {
for (int i = 0; i<5; i++) {
mRight.setSpeed(255);
mRight.run(BACKWARD);
mLeft.setSpeed(255);
mLeft.run(FORWARD);
delay(100);
mRight.setSpeed(255);
mRight.run(FORWARD);
mLeft.setSpeed(255);
mLeft.run(BACKWARD);
delay(100);
}
mLeft.setSpeed(0);
mRight.setSpeed(0);
} else if (command == '0' || command == 'O' || command == 's' || command == 'S' ) {
Serial.println("stop");
// Stop
mLeft.setSpeed(0);
mRight.setSpeed(0);
}
}
}
Step 7: Wrap Up
Yeah, now tweak the code and build something cool with your car chassis!
Links to the other video lessons: