Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
James Martel
Published © GPL3+

Wifi Enabled 2/4 Wheeled Robot Platform Utilizing MKR1000

WIP- Using a MKR1000 to create a WiFi Enabled 2/4 Wheeled Robot Platform, Hardware is in hand, now to implement software

IntermediateShowcase (no instructions)4 hours6,202
Wifi Enabled 2/4 Wheeled Robot Platform Utilizing MKR1000

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
I was one of 1000 who won this
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
Any L298N DC Motor driver will do that's Adafruit Shield compatible
×1
Adafruit Robot platform
Any 2/4 wheeled Robotic platform base can be used-I am building both-add DC Motors in Servo enclosure. This was inspiration platform for the MKR1000
×1
SainSmart HC-SR04 Ultrasonic Sensor
I used a SainSmart Clone - these sensors can be purchased very cheap
×1
Adafruit DC Motor in Servo Enclosure
Buy either two or four- based upon platform to based upon
×1
Adafruit Wheel for Micro Continuous Rotation FS90R Servo
Buy two or four-based upon platform to based upon
×1
UltraFire Rechargeable 4000 mAh Battery & Enclosure - 3.7v to 9v AA/18650
×1
Jumper wires (generic)
Jumper wires (generic)
Any style and color with proper termination
×1
servo motors
×1
Arduino Stacking Headers
You'll need 2 kits, 2x 6-pin, and 2x x-pin
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder- Rosen core generic
Heat Shrink Tubing
Philips Screwdriver- various sizes
adjustable wrench
needle nose plyer

Story

Read more

Schematics

MKR1000 and L298N interconnect

Hand drawn schematic

MKR1000 and L298N Demo Layout

Demo Layout

Demo Circuit

WiFi MKR1000 Demo

Code

Revised MKR1000 WiFi Web Server code

Arduino
This is the code I have started with, it compiles but has not been integrated with hardware
/*
  WiFi Web Server LED Blink

 A simple web server that lets you blink an LED via the web.
 This sketch will print the IP address of your WiFi Shield (once connected)
 to the Serial monitor. From there, you can open that address in a web browser
 to turn on and off the LED on pin 6.

 If the IP address of your shield is yourAddress:
 http://yourAddress/H turns the LED on
 http://yourAddress/L turns it off

 This example is written for a network using WPA encryption. For
 WEP or WPA, change the Wifi.begin() call accordingly.

 Circuit:
 * WiFi shield attached
 * LED attached to pin 6

 created 25 Nov 2012
 by Tom Igoe
 modified 24 Feb 2016
 by James Martel
 added DC Motor code
 Still under revision and testing 
 */
#include <SPI.h>
#include <WiFi101.h>

char ssid[] = "yourSSIDhere";      //  your network SSID (name)
char pass[] = "yourpassword";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
WiFiServer server(80);

int motorPin = 8;
int motorPin2 = 7;
int motorPin3 = 0;
int motorPin4 = 1;
int motorPin5 = 2; //pwm INA
int motorPin6 = 3; //pwm INB


void setup() {
  Serial.begin(9600);      // initialize serial communication
  pinMode(6, OUTPUT);      // set the LED pin mode
  pinMode(motorPin, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(motorPin5, OUTPUT); //pwm INA
  pinMode(motorPin6, OUTPUT); //pwm INB 
   
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);       // don't continue
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();                           // start the web server on port 80
  printWifiStatus();                        // you're connected now, so print out the status
}


void loop() {
 for(int motorValue = 0 ; motorValue <= 255; motorValue +=5){
 analogWrite(motorPin, motorValue);
 delay(30);
 analogWrite(motorPin2, motorValue);  
 delay(30);
 analogWrite(motorPin3, motorValue);
 delay(30);
 analogWrite(motorPin4, motorValue);  
 delay(30);
 // analogWrite(motorPin5, motorValue);
 // delay(30);
 // analogWrite(motorPin6, motorValue);  
 // delay(30);       
 }
 for(int motorValue = 255 ; motorValue >= 0; motorValue -=5){
 analogWrite(motorPin, motorValue);
 delay(30);
 analogWrite(motorPin2, motorValue); 
 delay(30);
 analogWrite(motorPin3, motorValue);
 delay(30);
 analogWrite(motorPin4, motorValue);  
 delay(30);
 // analogWrite(motorPin5, motorValue);
 // delay(30);
 // analogWrite(motorPin6, motorValue);  
 // delay(30);       
 }
/* void loop(){  
   digitalWrite(motorPin, HIGH);
   delay(1000);
   digitalWrite(motorPin, LOW);
   delay(1000);
   }
*/
  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> turn the LED on pin 6 on<br>");
            client.print("Click <a href=\"/L\">here</a> turn the LED on pin 6 off<br>");
            client.print("Click <a href=\"/H\">here</a> turn the DC_Motor on pin 8 on<br>");
            client.print("Click <a href=\"/L\">here</a> turn the DC_Motor on pin 8 off<br>");
            client.print("Click <a href=\"/H\">here</a> turn the DC_Motor2 on pin 7 on<br>");
            client.print("Click <a href=\"/L\">here</a> turn the DC_Motor2 on pin 7 off<br>");
            client.print("Click <a href=\"/H\">here</a> turn the DC_Motor3 on pin 0 on<br>");
            client.print("Click <a href=\"/L\">here</a> turn the DC_Motor3 on pin 0 off<br>");
            client.print("Click <a href=\"/H\">here</a> turn the DC_Motor4 on pin 1 on<br>");
            client.print("Click <a href=\"/L\">here</a> turn the DC_Motor4 on pin 1 off<br>");
            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          }
          else {      // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        }
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(6, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(6, LOW);                // GET /L turns the LED off
        }
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(8, HIGH);               // GET /H turns the DC_Motor on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(8, LOW);                // GET /L turns the DC_Motor off
        }
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(7, HIGH);               // GET /H turns the DC_Motor2 on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(7, LOW);                // GET /L turns the DC_Motor2 off
        }
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(0, HIGH);               // GET /H turns the DC_Motor3 on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(0, LOW);                // GET /L turns the DC_Motor3 off
        }
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(1, HIGH);               // GET /H turns the DC_Motor4 on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(1, LOW);                // GET /L turns the DC_Motor4 off
        }
                                        
      }
    }
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  // print where to go in a browser:
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
}

SimpleWebServerWiFi_MKR1000_L298N_Control

Arduino
I modified the simplewebserver test webpage and integrated L298N motor control
/*
  WiFi Web Server LED Blink

 A simple web server that lets you blink an LED via the web.
 This sketch will print the IP address of your WiFi Shield (once connected)
 to the Serial monitor. From there, you can open that address in a web browser
 to turn on and off the LED on pin 6.

 If the IP address of your shield is yourAddress:
 http://yourAddress/H turns the LED on
 http://yourAddress/L turns it off

 This example is written for a network using WPA encryption. For
 WEP or WPA, change the Wifi.begin() call accordingly.

 Circuit:
 * WiFi shield attached
 * LED attached to pin 6

 created 25 Nov 2012
 by Tom Igoe
 modified 24 to 29 Feb 2016
 by James Martel
 added simple Wifi control and two DC Motor code using L298N 
 */
#include <SPI.h>
#include <WiFi101.h>

char ssid[] = "YOUR_SSID";      //  your network SSID (name)
char pass[] = "YOUR_NETWORKPASSWORD";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
WiFiServer server(80);

int motorPin = 8; //motorA+
int motorPin2 = 7; //motorA-
int motorPin3 = 0; //motorB+
int motorPin4 = 1; //motorB-
int motorPin5 = 2; //pwm INA
int motorPin6 = 3; //pwm INB


void setup() {
  Serial.begin(115200);      // initialize serial communication
  pinMode(6, OUTPUT);      // set the LED pin mode
  pinMode(motorPin, OUTPUT); //motorA+
  pinMode(motorPin2, OUTPUT); //motorA-
  pinMode(motorPin3, OUTPUT); //motorB+
  pinMode(motorPin4, OUTPUT); //motorB-
  pinMode(motorPin5, OUTPUT); //pwm INA
  pinMode(motorPin6, OUTPUT); //pwm INB 
   
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);       // don't continue
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();                           // start the web server on port 80
  printWifiStatus();                        // you're connected now, so print out the status
}


/*void loop() {
 for(int motorValue = 0 ; motorValue <= 255; motorValue +=5){
 analogWrite(motorPin, motorValue);
 analogWrite(motorPin3, motorValue); 
 delay(30);
 analogWrite(motorPin2, motorValue);  
 analogWrite(motorPin4, motorValue);  
 delay(30);
 // analogWrite(motorPin5, motorValue);
 // delay(30);
 // analogWrite(motorPin6, motorValue);  
 // delay(30);       
 }
 for(int motorValue = 255 ; motorValue >= 0; motorValue -=5){
 analogWrite(motorPin, motorValue);
 analogWrite(motorPin3, motorValue); 
 delay(30);
 analogWrite(motorPin2, motorValue); 
 analogWrite(motorPin4, motorValue);  
 delay(30);
 // analogWrite(motorPin5, motorValue);
 // delay(30);
 // analogWrite(motorPin6, motorValue);  
 // delay(30);       
 } */
void loop(){  
/* // Forward  
   digitalWrite(motorPin, HIGH);
   digitalWrite(motorPin2, LOW);   
   digitalWrite(motorPin3, HIGH);
   digitalWrite(motorPin4, LOW);
   digitalWrite(motorPin5, HIGH);
   digitalWrite(motorPin6, HIGH);         
   delay(100);
   // STOP
   digitalWrite(motorPin5, LOW);
   digitalWrite(motorPin6, LOW);
   delay(100);   
   // Reverse
   digitalWrite(motorPin, LOW);
   digitalWrite(motorPin2, HIGH);   
   digitalWrite(motorPin3, LOW);
   digitalWrite(motorPin4, HIGH);
   digitalWrite(motorPin5, HIGH);
   digitalWrite(motorPin6, HIGH);        
   delay(100);
   // STOP
   digitalWrite(motorPin5, LOW);
   digitalWrite(motorPin6, LOW);
   delay(100);  
   // LEFT
   digitalWrite(motorPin, LOW);
   digitalWrite(motorPin2, HIGH);   
   digitalWrite(motorPin3, HIGH);
   digitalWrite(motorPin4, LOW);
   digitalWrite(motorPin5, HIGH);
   digitalWrite(motorPin6, HIGH);      
   delay(100);
   // STOP
   digitalWrite(motorPin5, LOW);
   digitalWrite(motorPin6, LOW);
   delay(100);
   // RIGHT
   digitalWrite(motorPin, HIGH);
   digitalWrite(motorPin2, LOW);   
   digitalWrite(motorPin3, LOW);
   digitalWrite(motorPin4, HIGH);
   digitalWrite(motorPin5, HIGH);
   digitalWrite(motorPin6, HIGH);        
   delay(100);
   // STOP
   digitalWrite(motorPin5, LOW);
   digitalWrite(motorPin6, LOW);
   delay(100);
   */
   
   
  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> turn the LED on pin 6 on<br>");
            client.print("Click <a href=\"/L\">here</a> turn the LED on pin 6 off<br>");
            client.print("Click <a href=\"/W\">here</a> move FORWARD 8,0 on<br>");
            client.print("Click <a href=\"/S\">here</a> STOP off<br>");
            client.print("Click <a href=\"/X\">here</a> move REVERSE 7,1 on<br>");
            client.print("Click <a href=\"/A\">here</a> move LEFT 7,0 on<br>");
            client.print("Click <a href=\"/D\">here</a> move RIGHT 8,1 on<br>");
            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          }
          else {      // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        }
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L" or "GET /W" or "GET /S" or "GET /X" or "GET /A" or "GET /D":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(6, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(6, LOW);                // GET /O turns the LED off
        }
        if (currentLine.endsWith("GET /W")) {
          digitalWrite(8, HIGH);               // GET /W moves FORWARD
          digitalWrite(7, LOW);
          digitalWrite(0, HIGH);               
          digitalWrite(1, LOW);
          digitalWrite(2, HIGH);               
          digitalWrite(3, HIGH);
        }
        if (currentLine.endsWith("GET /S")) {
          digitalWrite(2, LOW);                // GET /S STOP
          digitalWrite(3, LOW);
          digitalWrite(8, LOW);               
          digitalWrite(7, LOW);
          digitalWrite(0, LOW);               
          digitalWrite(1, LOW);                         
        }
        if (currentLine.endsWith("GET /X")) {
          digitalWrite(8, LOW);               // GET /X moves REVERSE
          digitalWrite(7, HIGH);               
          digitalWrite(0, LOW);          
          digitalWrite(1, HIGH);
          digitalWrite(2, HIGH);               
          digitalWrite(3, HIGH);                        
        }
        if (currentLine.endsWith("GET /A")) {
          digitalWrite(8, LOW);               // GET /A moves LEFT
          digitalWrite(7, HIGH);               
          digitalWrite(0, HIGH);          
          digitalWrite(1, LOW);
          digitalWrite(2, HIGH);               
          digitalWrite(3, HIGH);          
        }
         if (currentLine.endsWith("GET /D")) {
          digitalWrite(8, HIGH);               // GET /D moves RIGHT
          digitalWrite(7, LOW);               
          digitalWrite(0, LOW);          
          digitalWrite(1, HIGH);
          digitalWrite(2, HIGH);               
          digitalWrite(3, HIGH);            
        }                                       
      }
    }
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  // print where to go in a browser:
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
}

MKR1000-SimpleWebServerDCMotorControl-version3

Arduino
Web Based commands in short durations allow for controlled movement
/*
  WiFi Web Server LED Blink

 A simple web server that lets you blink an LED via the web.
 This sketch will print the IP address of your WiFi Shield (once connected)
 to the Serial monitor. From there, you can open that address in a web browser
 to turn on and off the LED on pin 6.

 If the IP address of your shield is yourAddress:
 http://yourAddress/H turns the LED on
 http://yourAddress/L turns it off

 This example is written for a network using WPA encryption. For
 WEP or WPA, change the Wifi.begin() call accordingly.

 Circuit:
 * WiFi shield attached
 * LED attached to pin 6

 created 25 Nov 2012
 by Tom Igoe
 modified 24 Feb 2016
 by James Martel
 added simple Wifi control and two DC Motor code using L298N 
 */
#include <SPI.h>
#include <WiFi101.h>

char ssid[] = "FiOS-PS868";      //  your network SSID (name)
char pass[] = "aim556hold58kayak";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
WiFiServer server(80);

int motorPin = 8; //motorA+
int motorPin2 = 7; //motorA-
int motorPin3 = 0; //motorB+
int motorPin4 = 1; //motorB-
int motorPin5 = 2; //pwm INA
int motorPin6 = 3; //pwm INB


void setup() {
  Serial.begin(115200);      // initialize serial communication
  pinMode(6, OUTPUT);      // set the LED pin mode
  pinMode(motorPin, OUTPUT); //motorA+
  pinMode(motorPin2, OUTPUT); //motorA-
  pinMode(motorPin3, OUTPUT); //motorB+
  pinMode(motorPin4, OUTPUT); //motorB-
  pinMode(motorPin5, OUTPUT); //pwm INA
  pinMode(motorPin6, OUTPUT); //pwm INB 
   
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);       // don't continue
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();                           // start the web server on port 80
  printWifiStatus();                        // you're connected now, so print out the status
}


/*void loop() {
 for(int motorValue = 0 ; motorValue <= 255; motorValue +=5){
 analogWrite(motorPin, motorValue);
 analogWrite(motorPin3, motorValue); 
 delay(30);
 analogWrite(motorPin2, motorValue);  
 analogWrite(motorPin4, motorValue);  
 delay(30);
 // analogWrite(motorPin5, motorValue);
 // delay(30);
 // analogWrite(motorPin6, motorValue);  
 // delay(30);       
 }
 for(int motorValue = 255 ; motorValue >= 0; motorValue -=5){
 analogWrite(motorPin, motorValue);
 analogWrite(motorPin3, motorValue); 
 delay(30);
 analogWrite(motorPin2, motorValue); 
 analogWrite(motorPin4, motorValue);  
 delay(30);
 // analogWrite(motorPin5, motorValue);
 // delay(30);
 // analogWrite(motorPin6, motorValue);  
 // delay(30);       
 } */
void loop(){  
/* // Forward  
   digitalWrite(motorPin, HIGH);
   digitalWrite(motorPin2, LOW);   
   digitalWrite(motorPin3, HIGH);
   digitalWrite(motorPin4, LOW);
   digitalWrite(motorPin5, HIGH);
   digitalWrite(motorPin6, HIGH);         
   delay(100);
   // STOP
   digitalWrite(motorPin5, LOW);
   digitalWrite(motorPin6, LOW);
   delay(100);   
   // Reverse
   digitalWrite(motorPin, LOW);
   digitalWrite(motorPin2, HIGH);   
   digitalWrite(motorPin3, LOW);
   digitalWrite(motorPin4, HIGH);
   digitalWrite(motorPin5, HIGH);
   digitalWrite(motorPin6, HIGH);        
   delay(100);
   // STOP
   digitalWrite(motorPin5, LOW);
   digitalWrite(motorPin6, LOW);
   delay(100);  
   // LEFT
   digitalWrite(motorPin, LOW);
   digitalWrite(motorPin2, HIGH);   
   digitalWrite(motorPin3, HIGH);
   digitalWrite(motorPin4, LOW);
   digitalWrite(motorPin5, HIGH);
   digitalWrite(motorPin6, HIGH);      
   delay(100);
   // STOP
   digitalWrite(motorPin5, LOW);
   digitalWrite(motorPin6, LOW);
   delay(100);
   // RIGHT
   digitalWrite(motorPin, HIGH);
   digitalWrite(motorPin2, LOW);   
   digitalWrite(motorPin3, LOW);
   digitalWrite(motorPin4, HIGH);
   digitalWrite(motorPin5, HIGH);
   digitalWrite(motorPin6, HIGH);        
   delay(100);
   // STOP
   digitalWrite(motorPin5, LOW);
   digitalWrite(motorPin6, LOW);
   delay(100);
   */
   
   
  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> turn the LED on pin 6 on<br>");
            client.print(" ");
            client.print("Click <a href=\"/L\">here</a> turn the LED on pin 6 off<br>");
            client.print(" ");
            client.print("Click <a href=\"/W\">here</a> move FORWARD 8,0 on<br>");
            client.print(" ");
            client.print("Click <a href=\"/S\">here</a> STOP off<br>");
            client.print(" ");
            client.print("Click <a href=\"/X\">here</a> move REVERSE 7,1 on<br>");
            client.print(" ");
            client.print("Click <a href=\"/A\">here</a> move LEFT 7,0 on<br>");
            client.print(" ");
            client.print("Click <a href=\"/D\">here</a> move RIGHT 8,1 on<br>");
            client.print(" ");
            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          }
          else {      // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        }
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L" or "GET /W" or "GET /S" or "GET /X" or "GET /A" or "GET /D":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(6, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(6, LOW);                // GET /O turns the LED off
        }
        if (currentLine.endsWith("GET /W")) {
          digitalWrite(8, HIGH);               // GET /W moves FORWARD
          digitalWrite(7, LOW);
          digitalWrite(0, HIGH);               
          digitalWrite(1, LOW);
          digitalWrite(2, HIGH);               
          digitalWrite(3, HIGH);
          delay(300);
          digitalWrite(8, LOW);
          digitalWrite(0, LOW);
        }
        if (currentLine.endsWith("GET /S")) {
          digitalWrite(2, LOW);                // GET /S STOP
          digitalWrite(3, LOW);
          digitalWrite(8, LOW);               
          digitalWrite(7, LOW);
          digitalWrite(0, LOW);               
          digitalWrite(1, LOW);
          delay(30);                         
        }
        if (currentLine.endsWith("GET /X")) {
          digitalWrite(8, LOW);               // GET /X moves REVERSE
          digitalWrite(7, HIGH);               
          digitalWrite(0, LOW);          
          digitalWrite(1, HIGH);
          digitalWrite(2, HIGH);               
          digitalWrite(3, HIGH);
          delay(300);
          digitalWrite(7, LOW);
          digitalWrite(1, LOW);                                 
        }
        if (currentLine.endsWith("GET /A")) {
          digitalWrite(8, LOW);               // GET /A moves LEFT
          digitalWrite(7, HIGH);               
          digitalWrite(0, HIGH);          
          digitalWrite(1, LOW);
          digitalWrite(2, HIGH);               
          digitalWrite(3, HIGH);
          delay(300);
          digitalWrite(7, LOW);               
          digitalWrite(0, LOW);
        }
         if (currentLine.endsWith("GET /D")) {
          digitalWrite(8, HIGH);               // GET /D moves RIGHT
          digitalWrite(7, LOW);               
          digitalWrite(0, LOW);          
          digitalWrite(1, HIGH);
          digitalWrite(2, HIGH);               
          digitalWrite(3, HIGH);
          delay(300);
          digitalWrite(8, LOW);
          digitalWrite(1, LOW);                      
        }                                       
      }
    }
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  // print where to go in a browser:
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
}

Credits

James Martel

James Martel

48 projects • 63 followers
Self taught Robotics platform developer with electronics background

Comments