I am excited to share the details of my custom PCB that acts as a Motor Drive Shield for an Arduino Nano - a versatile platform that empowers you to control two DC motors, one servo, attach an HC-05 Bluetooth module, and an ultrasonic sensor. With this shield, you'll unlock a realm of possibilities for your projects, from robotic marvels to smart gadgets. I used it to upgrade my Bluetooth RC Tank, and I intend to build more robot cars and vehicles with it.
This PCB can be used to upgrade your RC or Obstacle avoidance car, as you can connect everything on it and reduce the number of wires. You can also build a new Bluetooth-controlled car for example, and place the PCB in a 3D-printed car. These project ideas are just the tip of the iceberg. With the Arduino Nano Motor Shield at your disposal, your imagination is the only limit.
Follow along as we guide you through the supplies needed and the step-by-step process of assembling this powerful and compact PCB.
Step 1: Fabricate the PCBI have attached the design. You can use it as is, or change it as you wish. Once you have finalized your design, export the Gerber files and zip them in a folder. Then head to NextPCB's website to place your order.
This project was successfully completed because of the help and support from NextPCB -Reliable Multilayer PCB Manufacturer. NextPCB is one of the most experienced PCB manufacturers in Global, has specialized in the PCB and assembly industry for over 15 years.
Order high-quality, reliable PCB starting at $1.9, multilayer starting at $6.9:
https://www.nextpcb.com/pcb-quote
Enjoy free PCB assembly for 5 boards:
https://www.nextpcb.com/pcb-assembly-quote
DFM free online PCB Gerber viewer:
https://www.nextpcb.com/free-online-gerber-viewer.html
Step 2: Code and ControlsWhile you're waiting for the PCBs to arrive, have a look at the connections. You can follow the schematics or the annotations on the PCB, but it might look a bit chaotic at first glance so let me guide you through.
L293D Connections
Each In# controls the corresponding Out#. That way you can control which way is the motor rotating.
In1-->D10
In2-->D9
In3-->D6
In4-->D5
It is very simple to control the motors, you just have to identify which In# corresponds to Left Forward for example, and write it in your code like the example below.
int lb =5;
int lf = 6;
int rf = 9;
int rb = 10;
void setup() {
pinMode(lf,OUTPUT); //left motor fwd
pinMode(lb,OUTPUT); //left motor bwd
pinMode(rf,OUTPUT); //right motor fwd
pinMode(rb,OUTPUT); //right motor bwd
//loop to keep going forward
void loop()
{
digitalWrite(rf,HIGH);
digitalWrite(lf,HIGH);
digitalWrite(rb,LOW);
digitalWrite(lb,LOW);
}
You can write your own functions for easier control, or have it listen to a BT port. You can check out my other project for more details on that
Servo
The servo is connected to D3 on the nano. You can use the Servo.h library to control it. An example code could look like:
include <Servo.h>
Servo myservo;
int pos = 0;
int lb =5;
int lf = 6;
int rf = 9;
int rb = 10;
void setup() {
pinMode(lf,OUTPUT); //left motor fwd
pinMode(lb,OUTPUT); //left motor bwd
pinMode(rf,OUTPUT); //right motor fwd
pinMode(rb,OUTPUT); //right motor bwd
myservo.attach(3);
for (pos = 0; pos <= 180; pos += 1)
myservo.write(0);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(90);
delay(1000)
//loop to keep going forward
void loop()
{
digitalWrite(rf,HIGH);
digitalWrite(lf,HIGH);
digitalWrite(rb,LOW);
digitalWrite(lb,LOW);
}
Similarly, you can control the servo with BT commands.
Ultrasonic Sensor
As noted on the PCB, Trig goes to D8 and Echo to D7. There's a lot of documentation online on how to use it. Here is an example:
// Pins
const int trig= 8;
const int echo= 7;
// Variables
int distance;
long duration;
void setup()
{
pinMode(trig, OUTPUT); // sets the trig as output
pinMode(echo, INPUT); // sets the echo as input
Serial.begin(9600); // sets the serial communication
}
void loop()
{
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH); // Sets the trigPin on HIGH state for 10 micro seconds
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = duration * 0.034 / 2; // Reads the echoPin, returns the travel time in microseconds
Serial.print("Distance in cm: "); // prints the distance in centimeters on the serial monitor
Serial.println(distance);
}
Step 3: Assemble PCBOnce the PCBs arrive, and you have all of the required components for the assembly, power up your soldering iron and start putting everything together. The PCB is annotated so everything should be straightforward. The only two things you need to make sure you get right(as annotated on the picture) are:
- The L293D drive has a mark on one of its corners. Make sure that the mark is on the top left.
- Nano's digital pins should be on the right OR VIN should be on the bottom left (whichever is easier to remember)
Now that your shield is ready, you can start attaching your motors, servos, BT module, etc. I suggest you start with just the two DC motors and get the code right to control them. Then you can start adding components or figure out how to control your shield with the Bluetooth module and a phone app.
Step 5: ConclusionI really enjoyed designing and building this shield. I hope it proves to be useful to you and your projects.
Thanks for reading,
Yiannis
Comments
Please log in or sign up to comment.