Robot build!!
We will build a robot that is small, driven by two wheels and riding on a skid in front. That keeps things simple and makes it quickly responsive. The Arduino UNO will be the processor on the bot, and our bot will be simple. Basically two wheels, two whisker type sensors, a motor driver, 4 AA batteries and the UNO.
The method of mounting the motors depends on whether you bought a platform or if you are constructing your robot out of “found parts”, maker style. If you bought a platform, follow its build sequence. If you are going maker style, then follow these instructions…
First we will do some measurements to align the motors. Mount your chosen wheel on the motor geared shaft. We will mount the motors to the bottom of our bot board. Place the motor on the board so that the wheel is even with the back edge (one of the 5″ edges) of the board. Take a pen or pencil and mark the board along the body of the motor/gear assembly. This mark shows where to place the motors relative to the board end.
Here is a photo of my wheels:

And here are the motors:

Now if you have a square, use it and draw a line across the board from side to side at the mark. If you do not have a square (get one when you can. or get a drawing right angle triangle), then here is a way to make one for temporary use. Get an unwrinkled piece of typing or copier paper. Carefully pull the short edges together then holding them even, press toward the closed end, until you get a good solid fold. This will make a stronger edge. Press it down tight until it creases sharply. Now hold the paper or square on your board with the fold or square along the mark and across the board. Carefully line up the one edge of the paper or the other side of the square with the edge of the board. Lightly draw your pencil or pen along the edge across the board:


Voila, you have a nice mark for aligning the two motors. Lay the motors along this mark so that the wheels are clear of the board edge on each side by about 1/10 inch. This will make sure the wheels turn freely when driven by the motors. Make two cross marks on the line along each motor. See the photos to follow this process. Very close to the motor on the opposite side of the motor make two marks. Repeat for the other motor. When you lift the motors away, you should have 4 marks on each side. In a few minutes we will drill some holes there, but first lets do some more layout.
Place the battery holder on the board, clear of the marks, making sure it fits on the board without going over either edge, it can cover the area for the motors if necessary. Holding it firmly mark each of the holes in it using a pen or pencil. The motors will mound under the board, and the motors below the board.
Now we need to find the center of the board at the opposite end from the motors. The easiest way is to measure it with a ruler. If you don’t have a ruler, use your paper. Again make a line across the board using the square or paper to make it exactly perpendicular to the edge of the board, just as you did with the motors, but this time the line will be neear the middle of the long edge of the board. It doesn’t have to be exact, just close. See the photo to get the idea. Now, from one corner of the board, using your straight edge on your paper or square, draw a diagonal line to the corner formed by the middle line and the opposite edge of the board. Do that 4 times so you have two large X’s on the board. Connecting these X’s with a straight line and continuing through to the edge of the board, you have now found the exact center line of your board. About 1/2 inch from the front of the board, make a cross line on that central line. This is where the skid will go.
The motor mount holes:

My battery box is unlikely to match yours, but you can see how to mark it easily.
Now we’re ready to make some holes. Drill a 1/10″ hole at each of the 8 marks for the motors. Drill a 1/10″ hole at the marks to mount the battery box. Check the size of the screw for your skid and make a hole just big enough for it at the center line tick 1/2 inch from the forward edge of your board.
Now measure and cut 2 each 8″ of red wire and 2 each of 8″ of black wire. Solder one red and one black wire to each terminal on one motor. Repeat for the other. On the board, drill a 1/4 inch hole between the two motors and halfway toward the closest end of the board. This is where the motor wires will go up to the motor driver.
So far we have been working on the bottom of the board. Turn it over, and place the battery box on the board, and using 4 bolts if there are that many holes, bolt the battery box down to the top of the board. Put the screws in through the battery box and down through the board, and put washers and nuts on them and screw them snug, but not tight yet. Place the motor driver board on back end over where the motors will be and even with the back of the board. Mark the through the holes of the motor driver board. Note that it may cover the hole for the motor wires. That’s ok. Turn the board back over. Cut two more 8″ pieces of wire. Place one motor in its correct place. Thread one piece of the wire through the holes on each side of the motor. This is solid core wire if you bought what I mentioned. So now it can be used to hold the motor in place. Thread the second piece of wire through the other two holes next to the motor and twist its ends to hold the motor snugly in place. Repeat the process for the other motor. Your motors may need some bracing, so you can use toothpicks or other small wood to help position the motors. If the motors do not remain square with the edge of the board, cut the wires, and glue a toothpick or larger piece of wood just next to the holes, cut to just a bit longer than the distance between the holes so it will brace the motor in place. You can use hot melt glue or wood glue for this. If you use wood glue, sit the board aside for one day to make sure the glue is dry. Then reinstall the motors. The toothpicks should now keep the motors aligned properly. If not, you may need to add two more toothpicks to each side to make the braces a bit higher.

Now use the needle nose pliers and tighten all four wires. Tight, but not until the wire breaks. If a wire does break, just replace it and do it again. When all four are tight, your motors are mounted. On each motor lightly twist the two red and black wires together to make a red/black pair, then thread both pairs through the 1/4 inch hole .
To mount the driver board, we will need some stand-offs. I never had you buy any because we can make them. Cut 4 strips of paper about 1/4″ wide and about 1″ long. Coat one side of each with glue or mix a pinch of salt with 1 tablespoon of flour and add water just until it is pasty, and use that. Roll the strips into tubes just wide enough to pass the #2 screws through. Set them aside to dry tonight.

So, how do we mount the UNO to our robot? If the screws you have are long enough, you can just bolt it over the top of the battery box using the screws. If you got the 1″ screws, you are all set. If not, then you can use the wire binding trick through the holes in the UNO to bind it over the battery box. Put two on one side, but leave it loose for now until we get the battery’s in.
Now we mount our drawer pull. Put the pull on the bottom of the board, and use its screw to mount it through the hole near the front of our board. If it is too short for the board to be level when sitting on the wheels, make a stand-off for it, too, just like we did for the motor driver mount. I couldn’t find my drawer pull, so I made a skid from a furniture glide and positioned it on a block of wood. Here is a photo;

Sitting on its two wheels and skid it’s starting to look like a robot, isn’t it?
Now we need to add a few more components. At each front corner of the board, measure 1/2″ in and 1/2″ back. Mark the spot, and gently drill a small hole to start the screw eyes. Put one in each, turned parallel to the front of the board. Strip an 8″ piece of wire, and wrap the end around one screw. Pull the wire tight and twist the other end around the opposite screw eye. Like this:

The piano wire I’m using is 0.039″. The size is not too critical, but really fine wire will bounce too much. Too stiff will not move easily enough to make contact without changing the robot’s course. Starting 3″ back from the screw eyes, measure the length to about 1/2 inch in front of the farthest forward piece of your robot, including the skid. Add 3.5″. On my robot, this will be 4.5″+3.5″ or 10.5″. It is better to be long than short, so I’ll make mine 11″. Cut two pieces of the stiff piano wire to match this length. Put a masking tape flag on each wire at the measurement point that goes through the eyes, in my case 4.5″. Like this:

Measure 2.5 inches back from the screw eyes and in line with them i.e. 1/2 inch from the edge of the board, mark an x for the hole to hold the whisker in place. Drill a 1/10″ hole for the screws on each side.
Now carefully bend a circle in the end of the wire that will go through the screw eyes, that we will use to mount these whiskers to the board. It should be just a little bigger inside than the #2 screws. This will take up about 1/2 inch of your wire, give or take your bending accuracy. Now at the middle of your tape flag, bend the wire 90 degrees such that the wire can lay on the table with both the circle and the bend laying flat on the table. Twist the circle using your pliers until this is true. About 1/4 inch along the wire from the circle, bend it up about 15 degrees so that if you press down on the circle, the L of the wire rises off the table far enough that 2.5″ from the circle, the wire will be high enough to pass through the screw eyes without touching. The more accurate you get this, the easier the next steps will be. For the second whisker, lay it down so the angle is opposite the first one. Thus one will be the right whisker and the other the left. Repeat the bends for this wire, too.
OK, good whisker bend? Remove the tape and clean the wire with alcohol or light sanding. Now thread the end of the wire through the screw eye. Cut a piece of wire, I prefer white for right and yellow for left, about 6″ long each. We can trim them once things are working. Strip one end for about 1/2 inch. Bend the wire to form a closed loop around a #2 screw, cut the end of the loop so it will be flat under the screw. Put a washer on the screw, then the wire, then a washer. This makes sure the wire will be held well. Now put the screw through the loop in the whisker making sure that the right whisker is on the right side so that when it is pushed flat, the wire passes cleanly through the screw eye:

Now put the screw as follows: screw, washer, signal wire, washer, whisker wire, and through the board. Apply the nut on the bottom of the board and screw it down really snug, but not tight yet. On top of the board, check that the whisker goes cleanly through the eye, adjust as necessary to get it right in the center. Now tighten the screw. The whisker will likely now touch the screw eye at the top of the eye, but we can fix that later.

Your robot should now look something like this:

Cut a 5″ piece of black wire and strip both ends about 1/2 inch. Slip one end under the middle of the wire between the two screw eyes bend it over the wire tightly. Solder it to the wire. What we have made is a contact sensor. The whisker is in the middle of the eye, not touching. When the robot hits something, the wire will bend and touch the eye, grounding the pin just like our push button did earlier. Then we program our robot to back up and turn away from that side before taking off again.
Finally we need a power switch. You either had or purchased one. Regardless of how you got it, you need to mount it to the board. If it is a slide switch, it is easiest to put standoffs on screws and bolt it down after soldering the wires on it. Connect the red battery wire to one terminal at one end of the switch, and then cut a 6″ red wire and connect it to the terminal that is shorted when the switch is turned on. This is the same process for the toggle switch. For the toggle switch, you can just drill a hole in the board big enough to pass the screw part of the toggle through and fasten it with the supplied nut. You mount the switch where the battery wire can reach but in a place that doesn’t interfere with the wheels or whiskers, neither the switch, its screws, nor its wires can touch the wheels or whiskers. Here is mine:

Time to wire it all up!!
First the motor driver. Wire both sides of the motors to the side closest to the motor. Red to the front, black to the back and strip the wires about 1/4″ and unscrew the two screws on the sides of the motor driver. Place the stripped ends of the wire into the block. Look carefully the hole is near the bottom. The wire should bottom out in the hole with almost all the stripped wire inside the hole. Then tighten the screw. When that is done, the wires should look something like this:

Coil the wires a bit and put them under the driver board. Connect the black battery wire ( if it is twisted to the red wire, just untwist it a bit to reach) to the center of the three-hole block by the same process. Connect the red wire from the switch to the Left terminal of the three so it looks like the second photo. You can tape the wires down or coil them a bit to clean up the bot.
Make sure the switch is in the off position. Measure from the left terminal on the motor driver to the positive connection on the battery box to be sure. You can use an ohm meter if you have one, or the wire from an LED and resistor on your bread board via 5V through the switch like we did for checking the pushbutton earlier. Once you know for sure which is off, mark that position on the board near the switch. Switch off. Insert the batteries in the box. Tape two layers of making tape on the bottom of the Arduino just to prevent any sharp points from making contact with the batteries. Fasten the Arduino over the batteries.
We are about to add the brain to our robot! Yay! Brain surgery!!!
You need 8 male to female jumpers to connect the Arduino to the motor driver. One male-female jumper for the 5v. and one to one of the ground pins on the motor driver to ground on the Arduino.
Fasten the ENA and ENB to pins 9 and 10 respectively. Then in1 to 8, in2 to 11, in3 to 12 and in4 to 13. Left whisker to 2 and right whisker to 3.
Brain surgery done. Double check all connections. We don’t want to mis-connect anything or burn up one of our components.
Connection check list:
Connections:
motor driver:
[] left motor red to OUT4 screw terminal
[] left motor black to OUT3 screw terminal
[] right motor red to OUT1 screw terminal
[] right motor black to OUT2 screw terminal
[] Switch red to Vcc screw terminal
[] Battery black to GND screw terminal
[] Arduino ground to GND via male to female jumper
[] Arduino vin to 5v via male to female jumper
[] ENA to 9 via male to female jumper
[] in1 to 8 via male to female jumper
[] in2 to 11 via male to female jumper
[] in3 to 12 via male to female jumper
[] in4 to 13 via male to female jumper
[] ENB to 10 via male to female jumper
Whiskers
[] Left to arduino pin 2 via solid #22 wire
[] Right to arduino pin 3 via solid #22 wire
[] Screw eyes connected together by stripped #22 wire then a black #22 solid wire to arduino ground
Switch
[] Battery red wire to one pole of the switch. (the other already connected to Vcc on the motor driver.
Connections on the Motor driver:

From the OSEPP webpage: https://www.osepp.com/electronic-modules/breakout-boards/92-osepp-motor-driver-module
First we will load a simple program to run the motors, and we will put the robot on something so the wheels are not touching ground or anything. What a revolting development… My motors will not drive with 6v applied, nor will the 5v actually reach 5v. The specification for the motor driver says it should work:

From the OSEPP webpage: https://www.osepp.com/electronic-modules/breakout-boards/92-osepp-motor-driver-module
And I have 6v, but the 5v only reaches 4.65 no load. It might be that my motor driver has been damaged somehow, but I don’t have another. I’ll order another, but in the mean time I will just check if adding another battery will do the job. Always check the specs and double check your connections.
Here is the code. Note the #defines to check out the whisker operation, and the wheel test which will do a little dance without engaging the whiskers. If neither of these is defined, the robot code will run sensing the whiskers. When the left whisker is hit, the bot backs up and turns right. If the right whisker is hit the bot backs up and turns left. Note that if something is dead ahead and too small, the bot will just run into it. If you tie a piece of thread between the whiskers, then the bot will sense something straight ahead as well.
And here are two videos. First is the wheel test:
wheel test Dance
And a first run sort of bouncing off things in my lab:
First Run
Personality is next…
/*****************************************************************/
// SimpleBot
/*****************************************************************/
// 4 September 2017 by H.L.Howell
/*
Copyright 2017 H.L.Howell
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// to run the whisker test only uncomment the following line:
//#define WhiskerTest
// The wheel test can be run with the bot suspended so that you
// can just check that the wheels run forward and backward. If you put
// it on the floor in an open space, it will do a little dance.
// to run the wheel test only uncomment the following line:
//#define WheelTest
// test your bot to verify the 90 degree value
// for my bot at speed 200, it takes about 990ms.
#define turn90 990
#define Lwhisker 2
#define Rwhisker 3
#define Ren 9
#define Len 10
#define in1 8
#define in2 11
#define in3 12
#define in4 13
void backNleft(){
// back up for 1 second then turn left
long backtime;
backtime=millis();
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
while((millis()-backtime)<1000); // backing up for 1 second without stoppint interrupts
backtime=millis(); // get the time we start the turn
digitalWrite(in3,LOW); // this stops the left wheel
digitalWrite(in4,LOW); // but the right wheel is still going backwards turning right
while((millis()-backtime)<turn90); // turning
digitalWrite(in1,LOW); // and now going forward.
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
}
void backNright(){
// back up for 1 second then turn left
long backtime;
backtime=millis();
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
while((millis()-backtime)<1000); // backing up for 1 second without stoppint interrupts
backtime=millis(); // get the time we start the turn
digitalWrite(in1,LOW); // this stops the left wheel
digitalWrite(in2,LOW); // but the right wheel is still going backwards turning right
while((millis()-backtime)<turn90); // turning
digitalWrite(in1,LOW); // and now going forward.
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
}
void setup() {
// put your setup code here, to run once:
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(Lwhisker, INPUT_PULLUP); // pulls the pin to 5v through a 10K resistor
pinMode(Rwhisker, INPUT_PULLUP); // pulls the pin to 5v through a 10K resistor
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
int l,r;
l=digitalRead(Lwhisker);
r=digitalRead(Rwhisker);
Serial.print(“l=”);Serial.print(l);Serial.print(” r=”); Serial.println(r);
analogWrite(Len,200);
analogWrite(Ren,200);
#ifdef whiskertest
Serial.print(“whiskers L:”);
Serial.print(l);
Serial.print(” R:”);
Serial.println(r);
delay(300);
#endif
#ifdef WheelTest
Serial.println(“Forward both”);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
analogWrite(Len,200);
analogWrite(Ren,200);
delay(2000);
Serial.println(“Rev right”);
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
delay(2000);
Serial.println(“Rev LEFT”);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
delay(2000);
#endif
#ifdef WheelTest
#else
#ifdef WhiskerTest
#else
// normal operation
if ((l)&&(r)){ // Nothing blocking
Serial.println(“straight”);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
}
if (l==0){// left blocked This will also be the default when both are triggered.
Serial.println(“back & left”);
backNleft(); // backup and turn left
}
if (r==0){
Serial.println(“back & right”);
backNright(); // backup and turn left.
}
#endif
#endif
}