Arduino video of turning and spinning motors

Here’s a video of my Arduino robot with some nextrox motors attached to Di servo servos. This is so it can turn and also move forward or backward.


Here’s the code:


#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

//for servo 0
#define MIN_PULSE_WIDTH_0 900
#define MAX_PULSE_WIDTH_0 1800

//for servo 1
#define MIN_PULSE_WIDTH_1 900+100
#define MAX_PULSE_WIDTH_1 1800+100

//for servo 2
#define MIN_PULSE_WIDTH_2 900-250
#define MAX_PULSE_WIDTH_2 1800-250

//for servo 3
#define MIN_PULSE_WIDTH_3 900-250
#define MAX_PULSE_WIDTH_3 1800-250

#define FREQUENCY 50
//50 for digital

//Motor A
const int motorPin1 = 9; // Pin 14 of L293
const int motorPin2 = 10; // Pin 10 of L293
//Motor B
const int motorPin3 = 6; // Pin 7 of L293
const int motorPin4 = 5; // Pin 2 of L293

//Motor C
const int motorPin5 = 14;
const int motorPin6 = 15;

//Motor D
const int motorPin7 = 16;
const int motorPin8 = 17;

void setup() {

pwm.setPWMFreq(FREQUENCY); // Analog servos run at ~60 Hz updates

//Set pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);

pinMode(motorPin5, OUTPUT);
pinMode(motorPin6, OUTPUT);
pinMode(motorPin7, OUTPUT);
pinMode(motorPin8, OUTPUT);


void turnServo(int channel, int angle) {
pwm.setPWM(channel, 0, pulseWidth(channel, angle));

void turnServosLeft() {
//turn servos to 0
turnServo(0, 0);
turnServo(1, 0);
turnServo(2, 0);
turnServo(3, 0);

void turnServosRight() {
//turn servos to 180
turnServo(0, 180);
turnServo(1, 180);
turnServo(2, 90);
turnServo(3, 90);

void setServosStraight() {
turnServo(0, 90);
turnServo(1, 90);
turnServo(2, 90);
turnServo(3, 90);

int pulseWidth(int channel, int angle)

if(channel ==0) {
else if(channel == 1) {
else if(channel == 2) {
else if(channel == 3) {

int pulse_wide, analog_value;
pulse_wide = map(angle, 0, 180, MY_MIN_PULSE_WIDTH, MY_MAX_PULSE_WIDTH);

analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
return analog_value;


void goForwardWithMotorA() {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);

void goForwardWithMotorB() {
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);

void goForwardWithMotorC() {
digitalWrite(motorPin5, LOW);
digitalWrite(motorPin6, HIGH);

void goForwardWithMotorD() {
digitalWrite(motorPin7, LOW);
digitalWrite(motorPin8, HIGH);

void goBackWithMotorA() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);

void goBackWithMotorB() {
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);

void goBackWithMotorC() {
digitalWrite(motorPin5, HIGH);
digitalWrite(motorPin6, LOW);

void goBackWithMotorD() {
digitalWrite(motorPin7, HIGH);
digitalWrite(motorPin8, LOW);

void goForwardWithDCMotors() {
//motor a

//motor b

//motor c

//motor d


void goBackWithDCMotors() {
//motor a

//motor b

//motor c

//motor d

void stopDCMotors() {

analogWrite(motorPin1, 0);
analogWrite(motorPin2, 0);
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 0);

analogWrite(motorPin5, 0);
analogWrite(motorPin6, 0);
analogWrite(motorPin7, 0);
analogWrite(motorPin8, 0);

void rightSideDCMotorsBackward() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);

void leftSideDCMotorsBackward() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);


void loop() {







Robot progress

Here are some pics of my project so far. I got some servo mounts from ServoCity and they are mounted in order to turn the other motors. They turn on carpet in tandem which is pretty cool. I am waiting on a 1/4 20 tap to connect the plexiglass to the 80 20 pieces.

Voltage Regulator for PCA9685 board and 7+ volt power supply

In my previous post I mentioned I had a problem with the servo controller board I was using.

I followed the instructions here:

It says to use a max of 6 volts.

It also says to use -2 x 18650 Li-on Batteries which equal over 7 volts.

Since the board started smoking when the servo was hitting against the wheel, I decided to try a couple different things.

-Write an email to the people who wrote the wiki
-Buy a voltage regulator. I searched Amazon for “Voltage regulator” and found this:
-Stop causing the servo to hit against the wheel by buying a new regulator that didn’t have the problem of moving without instructions.
-Bought a replacement servo controller board.

Magic orchid cloning stuff

Amazon recommended me “Keiki Power Pro Orchid Plant Cloning Paste” today. I like orchids.

I ran the site through and it got an A.

I bought it directly from the company instead of Amazon. I will let you know if it works.


Update 12/2/2018: It didn’t work for me.

It has a bit less memory than it used to, since some corrupted sectors had to be quarantined?

“…though it has a bit less memory than it used to, since some corrupted sectors had to be quarantined.”

Mars Rover Curiosity is switching brains so it can fix itself

What does that mean?

Which servo motor I’m using for my Arduino project

I purchased 2 different kinds of servo motors for my robot Arduino project.

One on Amazon:

Four on Ebay.

They both arrived quickly.

I tried using the four on Ebay first.

“4PCS Digital MG996R MG995 High Torque Metal Gear Servo For Racing Futaba JR RC”


Eventually the pwm servo driver board I was using started smoking. I sent the people who make the board, SunFounder an email:

“I bought a SunFounder PCA9685 16 Channel 12 Bit PWM Servo Driver for Arduino and Raspberry Pi  on Amazon for 11.99.

I followed the instructions here:


After awhile, the 9685 board started smoking. I was wondering what it could be? I was trying to adjust the min/max of the servo and noticed every time I restarted the power it would rotate a bit in one direction consistently. I think that’s a bug in the software. I Googled and found someone who had the same problem.


I also have this problem:



I was also wondering if the voltage from that wiki page could be too high?


I think without some help if I bought another 9685 board it would just start smoking too and be ruined.


It did work for awhile, but I tried running the example code where you could set the min and max and it knocked up against the metal not being able to move.


I attached a picture. The smoking came from the component to the left of the word power.”
I then bought a new SunFounder PCA9685 servo controller board and tried the one on Amazon. It did not move when I first gave it power, like the one from Ebay.


The ones on Amazon “ANNIMOS 20KG Digital Servo High Torque Full Metal Gear Waterproof for RC Model DIY, DS3218MG,Control Angle 270°” were 4 times more expensive than the Ebay MG 996R ones I found on Ebay, but the DS3218MG works better for my application.