Thimble Learning Platform
Back to full view

Wi-Fi Bot - Part 1

Introduction

Demonstration and instructions on how to assemble and program the Thimble WiFi Bot Kit. Be sure to check out the further learning section for even more.

Objectives

  • Learn how to use a soldering iron and solder through-hole components
  • Learn to program an Arduino (or compatible microcontroller)
  • Assemble and program your own Thimble WiFi Bot
  • Learn how to control DC motors
  • Electrical Assembly

    Gather Materials 

    Gather the materials below and get ready to build the Thimble WiFi Robot! As you follow through our tutorial, please know that we see this as a living document. If you discover anything unclear in the instructions, let us know and we will do our best to fix it as fast as we can. Each page of every module on our learning platform has a section for discussion at the bottom of it, so please use that to let us know about anything that is unclear. We believe strongly in the philosophy of empathy-driven development, and if something is unclear to you, it is likely unclear to others.

    Our tutorials are meant to be a fun way to explore the world of electronics. We have included not only instructions, but also some theory, history, and challenges for you to explore on your own. If you only want to build the robot, you can skip over these discussions and links, but we encourage you to spend some time exploring and discussing all the resources we included here.

    Introduction video
    This 1 minute video introduces the Thimble WiFi robot.

    Parts

    All Parts x Qty
    WiFi-Bot v2.0 PCB x 1
    Laser Cut Platform x 1
    Laser Cut Motor Mounts x 2
    Laser Cut Rotary Encoders x 2
    Motors x 2
    Wire (For Motors) x 1
    Wheels x 2
    Caster x 1
    Terminal Blocks x 3
    Female Headers 1x4 x 3
    Photointerruptor (Optical Switch) x 2
    Ultrasonic Module (HCSR04) x 1
    WiFi Module (ESP8266) x 1
    Stackable Headers x 4
    Breadboard x 1
    Battery Holder (4XAA) x 1
    Batteries (4xAA not included) x 1

    Tools you'll need

    Soldering Iron
    Solder Wire
    Wire Strippers/Cutters
    Flush Diagonal Cutters
    Hot Glue Gun
    Solder Sucker (optional)
    Solder Wick (optional)

    Getting Started Assembling the PCB 

    We've found most people prefer following along in the tutorial step by step, clicking on the videos and images that accompany each video to look at more detail. However, some people may prefer to watch the entire assembly process first.

    Complete Assembly Instructions Video
    This ~25 minute video shows the entire process of assembling the WiFi robot.

    Assembling the PCB

    The first thing to do is un-box your kit and lay the components out on the table. We'll start by assembling the printed circuit board (PCB). In the Arduino world, PCBs are commonly referred to as "shields."

    How to Use a Soldering Iron
    A short instructional video to learn how to use a soldering iron safely and properly.

    The PCB comes with all of the surface mount parts (highlighted in the photo below) pre-soldered to the board.

    We'll start by inserting the stackable headers into the PCB and using solder to tack them into place. These headers allow us to insert the PCB into the Arduino (or Arduino-compatible board) while still allowing us access to the sockets on top of the Arduino in order to add additional circuitry.

    Once you’re done putting in all the headers on both sides of the PCB, carefully flip the PCB over. Use your fingers to keep the headers intact as you flip it over so they don’t fall out. This can be a little tricky at first but you’ll get the hang of it.

    Start soldering video clip
    Bare, unpopulated Thimble WiFi Bot PCB
    Through hole parts to be populated
    Surface mount parts
    Insert the stackable headers into the PCB
    Insert the 10-pin stackable header into the PCB
    Insert the 10-pin stackable header into the PCB
    Insert the 8-pin stackable header into the PCB
    Insert the 8-pin stackable header into the PCB
    Insert the rest of the stackable headers and flip the board over
    Tack headers in place

    Now we're ready to start soldering! As mentioned before, start by using solder to tack the headers in place (only solder one pin for each header). Grab your soldering iron and solder wire. Place the soldering iron on the top right pin; slowly push solder wire into the pad and soldering iron tip. Solder should start to flow as you push it (solder should resemble a little dot or joint).

    Using a Solder Sucker
    Make a mess while soldering your pins? The solder sucker has you covered. Learn how to clean up your solder joints with this video.

    At this point, all headers should be soldered firmly onto the PCB. If you have made it this far, give yourself a firm pat on the back. You have soldered more than most people do in their lifetime. :-D

    Warning

    You may want to wait to solder the green terminal blocks until after you have soldered all of the other headers (black pieces) to the board. The terminal blocks are slightly taller and may make it more difficult for you to hold the pieces in place when soldering on a table top.

    Now it’s time to solder the other through-hole components onto the PCB. Using your hands, take the little green connectors (aka terminal blocks) and attach them together. There is a little notch that will allow each green connector to slide into one another.

    The three green terminal blocks
    Slide each terminal block together to form one unit
    Insert the terminal blocks into the PCB
    Flip the PCB over
    Use solder to tack the terminal blocks in place
    Place two 4-pin stackable headers onto the PCB
    Place two 4-pin stackable headers onto the PCB
    Carefully flip over PCB board and tack the two 4-pin headers in place. You can use tape to hold these headers in place
    Flip the board back over and tack the 2x4 header in place. This will connect to the WiFi module ESP8266
    The last part - the final 4-pin header. This holds the ultrasonic module in place

    Once you have all the parts tacked in place, flip the board over and you're ready to solder all of the pins. Again, remember to be careful to make sure there are no solder bridges. A solder bridge is where two or more pins have solder touching. This is bad as it results in an electrical short (both pins will have the same voltage). Depending on the circuit, this can cause damage if we apply electricity. However, again, if you find yourself in this situation, don't dismay - it can be fixed! Just scroll up and watch the video about using a solder sucker and solder wick.

    Flip the board over and solder all of the pins
    Flip the board over and solder all of the pins
    Inspect your solder joints
    Once you have soldered all of the electrical pieces in place, do a careful visual inspection to double check for and fix any shorts. Then give yourself a serious high five! This is great progress! Next, we're ready to solder the motors and move on to the mechanical assembly of the robot!

    Connecting the Motors 

    For the electrical connection of the motors, you'll need two sets of two wires and the wire cutters. We use the black and white wires included in the kit, but you can use the color of your choice.

    Grab the piece of wire you need and gently strip the ends of the wire with your wire cutters.

    Solder wires onto the motors
    Grab the piece of wire you'd like to use
    Strip the ends of the wire with your wire cutters

    Place the wire through the copper contacts of the motor on both sides. Then solder the wire onto the joint. Repeat for the other motor. Make sure the wire has some flexibility to it and wrap it around the motor so it will not rip the copper contact off the motor. You may want to use some hot glue here (after it is soldered) to provide some strain relief and ensure the wire will not rip.

    Solder the leads of the motor
    Solder wires to both motors

    Now you're ready for the last part of assembling the robot - the mechanical assembly.

    Mechanical Assembly

    Attaching the Arduino 

    We'll start by attaching the stand-offs and nuts to the wood platform. This is where the Arduino will be mounted. Make sure to tighten the nuts and standoffs tight so they do not loosen or fall off while driving the robot.

    Mounting the Arduino Video
    Place each standoff through the holes in the laser cut platform
    And use a nut to secure it in place

    Place the Arduino board onto the wood platform and screw it in to place with the screws. Make sure all the nuts connecting the stand-offs are nice and tight.

    Use a screwdriver and screw to secure the Arduino in placeUse a screwdriver and screw to secure the Arduino in place

    Motor Mounts 

    Grab the motor mounts (two laser cut wood pieces) and mount the motors to the WiFi Bot using the M3 screws and nuts.

    Once you have the motor mounted onto the motor mount, you can connect it to the wood platform.

    Mounting the Motors Video
    Grab the motor mount
    Align the motor so that the nub sticks through the motor mount
    Insert screw with the head of the screw touching the plastic of the motor
    Insert the bottom side screw as shown
    Insert the nut as shown and partially tighten it
    Insert the top side screw
    Insert the screw as shown
    Insert the top side nut as shown and tighten it
    Place the motor onto the platform. You may have to apply a small amount of force to fit the mount onto the platform.
    The motor and mount secured to the platform
    Repeat these steps for the second motor and tighten the screws and nuts

    Attaching the WiFi Bot PCB and the Arduino 

    Align the stackable header pins on one side of the PCB so they slide into their respective sockets on the Arduino. Then slowly line up the pins on the other side. Look for any pins that aren't aligned into the sockets. Push them into place with your finger and start to apply pressure until all pins are secured into the sockets on the Arduino board. Be very delicate. It may take some time to push these into place, but you'll get it.

    Attaching the WiFi Bot PCB and the Arduino Video
    Align the stackable header pins on one side of the PCB so they slide into their respective sockets on the Arduino
    Align the stackable header pins on other side of the PCB so they slide into their respective sockets on the Arduino
    Once the pins are aligned, push the WiFi Robot PCB into the Arduino

    Attaching the Wheels 

    Now the robot is starting to take shape! Line the slot of the wheel with the motor. Press the wheel firmly onto the motor. Make sure the wires coming from the robot are out of the way of the wheels (If not, you'll have a tangled mess and may accidentally rip the wires off of the motors).

    Attaching the Wheels Video
    Line the slot of the wheel with the motor
    Press the wheel firmly onto the motor
    The wheel is now attached
    Repeat for the other wheel
    Nice job! The robot is starting to look complete

    Attaching the Batteries 

    Mechanically, there are a couple more components left to assemble. The battery pack and wheel caster. The guide will start with the battery pack, but if you'd rather do it in a different order, go for it.

    The battery pack is secured to the robot with Velcro. One side goes on the battery pack, the other onto the robot laser cut platform.

    Attaching the Batteries Video
    Pull apart the two pieces of Velcro
    Pull apart the two pieces of Velcro
    Peel the tape off of one piece of Velcro
    And place it on the wood platform
    Velcro on wood platform
    Grab the other piece of Velcro
    Peel the label, and place it in the middle of the bottom side of the battery pack
    Place the battery pack on the robot. Note: make sure the battery pack wires are facing the back of the robot

    Attaching the Caster Wheel 

    The caster wheel goes onto the bottom side of the front of the robot. We'll secure it using the glue gun. If you don't have a glue gun available, you can find other creative ways to secure the caster to the robot (screws, double-stick tape, or other adhesives).

    Use the glue gun to glue the caster into place. To do this, glue four small dots of glue onto the four holes on the wheel caster. The glue will dry in 30-45 seconds.

    Once the glue has dried, you can flip it the robot over and proceed to the next step.

    Attaching the Caster Wheel Video
    Place the caster in the front-middle part of the robot
    Use glue gun to glue the caster into place
    Use glue gun to glue the caster into place
    Almost there!

    Final Electrical Connections 

    Battery Holder

    Your robot is almost complete! The only thing you have left to do is make the electrical connections to give it power. We’ll focus on the battery pack wires first.

    Use your wire cutters to strip the tips of the electrical wires coming out from the battery pack. First, loosen all the screws securing the connectors on the six green terminal blocks. Then, strip the wires on the battery pack. Place the red wire from the battery pack into the VIN+ slot on the Thimble PCB and tighten the connector with your screwdriver after the wire has been inserted to secure it in place. Place the black wire from the battery pack into the VIN- slot on the Thimble PCB and tighten the connector on the terminal block to secure it in place.

    Final Electrical Connections Video
    The battery holder wires
    Use your wire cutters to strip the tips of the electrical wires coming out from the battery pack
    Strip the red wire
    Using your screwdriver, loosen the connectors in the six green terminal blocks.
    Loosen all 6
    Insert the red wire from the battery pack into VIN+, the 2nd terminal block
    Tighten the screw to secure the wire in place
    Strip the battery holder's black wire
    Insert the black wire from the battery pack into VIN-, the 1st terminal block
    Tighten the screw to secure the black wire in place
    The red and black wires from the battery holder are secured

    Motors

    Now that the battery pack wires are in place. We’ll focus on the motor wires.

    Even though there are two sets of black and white wires stemming from the motors, we’ll focus on one set first. Make sure that they’re out of the way of the motors. Since you have quite a bit of wire, you will need to cut them with the wire cutters. Make sure you give yourself enough wire so that it reaches the green terminal blocks.

    Let’s start with the left motor (the left motor if you’re looking at the robot from the front)

    Using your wire cutters, cut the black and white wires. Leave enough wire so that they’ll reach the terminal blocks. Strip the black and white wires. Place the white wire into third terminal block on the PCB. (next to the red wire). Place black wire into fourth terminal block on the PCB.

    Repeat these steps for the right motor. Note: For the right motor wires,  place the white wire into the fifth terminal block. And place the black wire into the sixth terminal block and screw the connectors in to secure wires in place.

    Grab the left motor's wires
    Cut the black and white wires from the left motor. Leave enough slack to insert the wires into the terminal blocks
    Strip the wires
    Place the white wire into third terminal block on the PCB
    Place black wire into fourth terminal block on the PCB
    Tighten the connectors down so both wires are secured
    Repeat these steps for the right motor.
    All terminal block connections completed
    Insert the ESP8266 WiFi Module
    All electrical connections are completed

    Woo-hoo! Congratulations! You have completed building the WiFi-robot!  Now you’re ready to program your WiFi-robot! Let’s move onto the programming tutorials.

    Make the robot move!

    Now that everything is assembled, let's get to work making the robot move!

    We'll start off with a short discussion on the motors and the motor driver integrated circuit (IC) that is used to control them. If you'd rather just get the robot moving, skip ahead to the Let's code it section.

    Physically, the motor driver is shown in the picture below.

    The motor driver on an unassembled WiFi-bot PCBThe motor driver on an unassembled WiFi-bot PCB

    How does all of this work? 

    What is an IC?

    The motor driver we're using is an integrated circuit (IC). The invention and development of the transistor and IC is what launched the semiconductor industry and won Jack Kilby his Nobel Prize in Physics. If you're interested in learning more about how ICs are manufactured, check out the YouTube videos below:

    This first group of videos gives an overview of the entire process.

    A very brief, high level overview from Intel
    Global Foundries Sand to Silicon video
    An overview of the entire process from a TV program about Texas Instruments
    Demonstration of IC packaging solutions available from Quik-Pak

    The second group of videos look at already manufactured ICs and use mechanical mills and chemical processes to "decap" (remove the packaging) of the ICs and view them under a microscope.

    Zooming into an IC using a DSLR camera and Scanning Electron Microscope
    Looking at an IC under a microscope
    Decapping an IC to look at what is inside

    If you want to take a very deep dive into the world of semiconductors and ICs, there are a number of excellent university courses available online covering solid state chemistry, IC design or from MIT, manufacturing, and packaging.

    The motor driver

    This motor driver is the TB6612FNG, manufactured by Toshiba. This link brings you to the datasheet for the motor driver. In case you're unfamiliar, datasheets are provided by chip manufacturers to explain the function of the device. As indicated in the datasheet, the TB6612FNG is a dual DC motor driver that can take a power supply voltage of up to 15V to drive 2 DC motors with at a continuous 1.2A output current and a peak current of 3.2A for a single 10ms pulse.

    The table below shows the pin function, number, and symbol for each pin of the IC.

    Chip Pin Number Arduino Pin Number Label Input/Output (I/O) Function
    1, 2 Wifi-Robot MotorA 1 AO1 Output channel A ouptut1
    3, 4 -Vin (GND) PGND1 Power Power Ground 1
    5, 6 Wifi-Robot MotorA 2 AO2 Output channel A output2
    7,8 Wifi-Robot MotorB 2 BO2 Output channel B output2
    9, 10 -Vin (GND) PGND2 Power Power Ground 2
    11, 12 Wifi-Robot MotorB 1 BO1 Output channel B output1
    13, 14 +Vin VM2/3 Power Motor supply (2.5-13.5V)
    15 11 PWMB Input channel B PWM input
    16 13 BIN2 Input channel B input 2
    17 12 BIN1 Input channel B input 1
    18 -Vin (GND) GND Power Logic Ground (Tied on PCB to PGND1 and PGND2 as well)
    19 6 STBY Input When HIGH, allows H-bridges to function (and drive the motors). When LOW, H-bridges are disabled.
    20 IOREF (+5V) VCC Power Provides power for the IC (2.7 - 5.5V)
    21 3 AIN1 Input channel A input 1
    22 4 AIN2 Input channel A input 2
    23 5 PWMA Input channel A PWM input
    24 +Vin VM1 Power Motor supply (2.5-13.5V)

    The table below (copied from the Control Function section of the datasheet) shows us how to use this circuit to control the motors.

    IN1 IN2 PWM STBY OUT1 OUT2 Mode
    H H H/L H L L Short brake
    L H H H L H CCW
    L H L H L L Short brake
    H L H H H L CW
    H L L H L L Short brake
    L L H H OFF (High impedance) OFF Stop
    H/L H/L H/L L OFF OFF Standby

    So, what does this mean? In order to drive a motor "forward" (counter-clockwise/CCW), we set that channel's input 1 to logic level low voltage (GND), input 2 to logic level high voltage (5V), PWM to a voltage level that will set the speed, and standby to high. As shown in the table (row 2) this results in the motor outputs OUT1 at a low voltage and OUT2 at a high voltage, driving the motor counter-clockwise. This can be applied to both the A and B channels to drive both motors simultaneously.

    In code, on the Arduino, this results in the following function (where AIN1 and AIN2 are IN1 and IN2 for the A channel (motor A) and BIN1 and BIN2 are IN1 and IN2 for the B channel (motor B):

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    // Move the robot forward for STEPTIME
    void goForward ( ) {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, LOW);
        digitalWrite(AIN2, HIGH);
        digitalWrite(BIN1, LOW);
        digitalWrite(BIN2, HIGH);
        writePwms (STRAIGHTSPEED-leftOffset,STRAIGHTSPEED-rightOffset);
        pwmTimeout = millis() + STEPTIME;
    }
    

    We use the Arduino's digitalWrite() function to set the value of the pins. writePwms() is a function shown below that wraps Arduino's analogWrite() function.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    // Function to write out pwm values
    void writePwms ( int left, int right) {
        analogWrite (pwms[0], left);
        analogWrite (pwms[1], right);
    }
    

    We use the variable pwmTimeout to determine when to turn off the motor by recording the current time in milliseconds (obtained via the millis() function) and adding STEPTIME to that. We'll then compare pwmTimeout to the current time and zero out the voltage to the PWM pins to stop the motors from turning, as shown in the code snippet below.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    if (pwmTimeout > 0) {
    	// Check pwmTimeout has not been reached.
    	if (millis() > pwmTimeout) {
    		// If it has, zero voltage to PWM pins
    		pwmTimeout = 0;
    		writePwms (0,0);       
    	}
    }
    

    Let 

    First, we'll start with an Arduino sketch that drives the robot forward continuously. Upload the code below to your robot using the Arduino IDE.

    If you don't have the Arduino IDE installed, visit the Arduino download page to download it for your operating system (it is free). Then, copy and paste the code below into the IDE and upload it to your robot by plugging in the USB cable and clicking the upload button in the IDE program. Arduino has detailed instructions on Getting started as well as how to upload a program to an Arduino Uno board.

    Once you click upload, the robot will upload the code and should start to drive both motors forward immediately. If your robot isn't moving, double check that you have the 4 AA batteries installed. If your robot is driving continuously in a circle, figure out which motor is rotating backwards. Then, remove the batteries to stop the robot. Grab your screwdriver and loosen the terminal blocks for that motor's wired connections, then swap the two wires and tighten the terminal block connector screws to secure them.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    // Pin assignments
    #define AIN1 3
    #define AIN2 4
    #define APWM 5
    #define BIN1 12
    #define BIN2 13
    #define BPWM 11
    #define STBY 6
    
    // Constants for motor control functions
    #define STEPTIME 600 
    #define STRAIGHTSPEED 200
    #define TURNSPEED 120
    #define TURNTIME 300
    
    // Array to track current PWM values for each channel (A and B)
    int pwms[] = {APWM, BPWM};
    
    // Offsets to be used to compensate for one motor being more powerful
    byte leftOffset = 0;
    byte rightOffset = 0;
    
    // Variable to track remaining time
    unsigned long pwmTimeout = 0;
    
    // Function to write out pwm values
    void writePwms ( int left, int right) {
        analogWrite (pwms[0], left);
        analogWrite (pwms[1], right);
    }
    
    // Move the robot forward for STEPTIME
    void goForward ( ) {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, LOW);
        digitalWrite(AIN2, HIGH);
        digitalWrite(BIN1, LOW);
        digitalWrite(BIN2, HIGH);
        writePwms (STRAIGHTSPEED-leftOffset,STRAIGHTSPEED-rightOffset);
        pwmTimeout = millis() + STEPTIME;
    }
    
    // Move the robot backward for STEPTIME
    void goBack() {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, HIGH);
        digitalWrite(AIN2, LOW);
        digitalWrite(BIN1, HIGH);
        digitalWrite(BIN2, LOW);
        writePwms (STRAIGHTSPEED-leftOffset,STRAIGHTSPEED-rightOffset);
        pwmTimeout = millis() + STEPTIME;
    }
    
    // Turn the robot left for TURNTIME
    void goLeft () {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, HIGH);
        digitalWrite(AIN2, LOW);
        digitalWrite(BIN1, LOW);
        digitalWrite(BIN2, HIGH);
    
        writePwms (TURNSPEED,TURNSPEED);
        pwmTimeout = millis() + TURNTIME;
    }
    
    // Turn the robot right for TURNTIME
    void goRight () {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, LOW);
        digitalWrite(AIN2, HIGH);
        digitalWrite(BIN1, HIGH);
        digitalWrite(BIN2, LOW);
    
        writePwms (TURNSPEED,TURNSPEED);
        pwmTimeout = millis() + TURNTIME;
    }
    
    // Stop the robot (using standby)
    void stop(){
        digitalWrite(STBY, LOW); 
    }
    
    // Arduino setup function
    void setup() {
        // Initialize pins as outputs
        pinMode (STBY, OUTPUT);
        pinMode (AIN1, OUTPUT);
        pinMode (AIN2, OUTPUT);
        pinMode (APWM, OUTPUT);
        pinMode (BIN1, OUTPUT);
        pinMode (BIN2, OUTPUT);
        pinMode (BPWM, OUTPUT);
    }
    
    // Loop (code betwen {}'s repeats over and over again)
    void loop() {
        // Make the robot go Forward.
        goForward();
    }
    

    The following Arduino sketch contains uses the previous code as a base and modifies the loop() function so that the robot drives forward for 1 second, stops for 1 second, drives the robot backward for 1 second, stops for 5 seconds, and then repeats. Upload this code to your robot to see the robot follow the commands you programmed into it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    // Pin assignments
    #define AIN1 3
    #define AIN2 4
    #define APWM 5
    #define BIN1 12
    #define BIN2 13
    #define BPWM 11
    #define STBY 6
    
    // Constants for motor control functions
    #define STEPTIME 600 
    #define STRAIGHTSPEED 200
    #define TURNSPEED 120
    #define TURNTIME 300
    
    // Array to track current PWM values for each channel (A and B)
    int pwms[] = {APWM, BPWM};
    
    // Offsets to be used to compensate for one motor being more powerful
    byte leftOffset = 0;
    byte rightOffset = 0;
    
    // Variable to track remaining time
    unsigned long pwmTimeout = 0;
    
    // Function to write out pwm values
    void writePwms ( int left, int right) {
        analogWrite (pwms[0], left);
        analogWrite (pwms[1], right);
    }
    
    // Move the robot forward for STEPTIME
    void goForward ( ) {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, LOW);
        digitalWrite(AIN2, HIGH);
        digitalWrite(BIN1, LOW);
        digitalWrite(BIN2, HIGH);
        writePwms (STRAIGHTSPEED-leftOffset,STRAIGHTSPEED-rightOffset);
        pwmTimeout = millis() + STEPTIME;
    }
    
    // Move the robot backward for STEPTIME
    void goBack() {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, HIGH);
        digitalWrite(AIN2, LOW);
        digitalWrite(BIN1, HIGH);
        digitalWrite(BIN2, LOW);
        writePwms (STRAIGHTSPEED-leftOffset,STRAIGHTSPEED-rightOffset);
        pwmTimeout = millis() + STEPTIME;
    }
    
    // Turn the robot left for TURNTIME
    void goLeft () {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, HIGH);
        digitalWrite(AIN2, LOW);
        digitalWrite(BIN1, LOW);
        digitalWrite(BIN2, HIGH);
    
        writePwms (TURNSPEED,TURNSPEED);
        pwmTimeout = millis() + TURNTIME;
    }
    
    // Turn the robot right for TURNTIME
    void goRight () {
        digitalWrite(STBY, HIGH);
        digitalWrite(AIN1, LOW);
        digitalWrite(AIN2, HIGH);
        digitalWrite(BIN1, HIGH);
        digitalWrite(BIN2, LOW);
    
        writePwms (TURNSPEED,TURNSPEED);
        pwmTimeout = millis() + TURNTIME;
    }
    
    // Stop the robot (using standby)
    void stop(){
        digitalWrite(STBY, LOW); 
    }
    
    // Arduino setup function
    void setup() {
        // Initialize pins as outputs
        pinMode (STBY, OUTPUT);
        pinMode (AIN1, OUTPUT);
        pinMode (AIN2, OUTPUT);
        pinMode (APWM, OUTPUT);
        pinMode (BIN1, OUTPUT);
        pinMode (BIN2, OUTPUT);
        pinMode (BPWM, OUTPUT);
    }
    
    // Loop (code betwen {}'s repeats over and over again)
    void loop() {
        // Make the robot go Forward.
        goForward();
        // Wait for one second
        delay(1000);
        // Make the robot stop
        stop();
        // Wait for one second
        delay(1000);
        // Make the robot go backward
        goBack();
        // Wait for one second
        delay(1000);
        // Make the robot stop
        stop();
        // Wait for one second
        delay(1000);
    }
    
    Start Playing

    Now have some fun!

    Part two of this tutorial module will cover the ultrasonic module to turn the robot into an obstacle avoiding robot as well as programming the WiFi module so you can control the robot remotely. Play around with the example code to see if you can make the robot navigate an obstacle course with a very simple dead-reckoning technique. In part 2, we will introduce the ultrasonic module to provide some feedback on the robot's position relative to obstacles and give you true remote control over the robot using the WiFi module.

    Have fun!