Project showcase
Wifi Enabled 2/4 Wheeled Robot Platform Utilizing MKR1000

Wifi Enabled 2/4 Wheeled Robot Platform Utilizing MKR1000 © GPL3+

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

  • 3,612 views
  • 6 comments
  • 11 respects

Components and supplies

Abx00004 iso both
Arduino MKR1000
I was one of 1000 who won this
×1
09670 01
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
11026 02
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

Necessary tools and machines

About this project

This is my 1st published hackster build. I have been interested in Wifi enabled Robot platforms since hearing about the raspberry pi for $25..... Now I have many Robotic Platforms built around the Raspberry Pi, Arduino, PcDuino and many clones of each of them. I have not mastered coding but have learned how to adapt code that others have published and have felt that not one available Robot Platform can interface with anything, any device. Not that this will, but it is helping me to get there in development.

Here is a link to some of my efforts: PiBot Tour.

 1. Gather tools-layout organized

  • 2. Identify / layout hardware

2b. Assemble mini rover platform: (IF 4wheeled version substitute 2 additional dc motors for caster/pivot wheel) also install L298N DC Motor driver.


  • 3. Install MKR1000 supplied header pins onto breadboard at proper width spacing for MKR1000.
  • 4. Install Arduino stacking header pins onto supplied MKR1000 header pins; these LONG Stacking pins should be facing up.
  • 5. Install MKR1000 onto Arduino Stacking pins with component side DOWN.
  • 6. Before soldering header pins onto MKR1000 ensure that they are straight up.
  • 7. Solder Arduino Stacking header pins to bottom side pads on MKR1000.
  • 8. ensure that your soldering iron is only hot enough to melt your solder and not the MKR1000.
  • ***on 3/6/16 this "unofficial setup was uploaded" I wish it was done before I started.
  • 9. Connect USB to micro-USB cable to MKR1000 using micro USB cable end
  • 10. Connect larger USB cable end to your PC, after a few moments, Windows will have installed appropriate Device driver for the MKR1000 and also select a COM-port.
  • 11. Open your Arduino IDE interface (1.6.7).



  • 12. Open tools/board manager to download and install Arduino drivers (there is an issue with latest version for Arduino/Genuino MKR1000 under Arduino SAMD (32-bits ARM Cortex-MO+) Boards v. 1.6.3?
  • v 1.6.4 did not properly recognized/ID my MKR1000. I needed to revert back a version.
  • 13. search for proper latest driver by typing MKR1000 in the Boards Manager search filter.
  • 14.Download available example files from GITHUB.COM FOR WIFI101
  • My Modified code is: Revised MKR1000 WiFi Web Server Code can be downloaded from here.
  • 15. I did test the AP_SimpleWebServer example as well, but it chose my HOME's WiFi Router's IP address and caused conflicts with my connection.
  • 16. Be sure to revise the example code with your networks'info:
  • "char ssid[] = "yourNetwork"; "network SSID (name)"
  • "char pass[] = "secretPassword"; "network "password"
  • 17. Save revision, verify code, upload code to MKR1000 to test function. This code will allow you to turn on your LED on the MKR1000...my board is on pin 6, but this example is on pin 9...experiment/test.
  • 18. Open your webbrowser.
  • 19. With the MKR1000 still connected to your pc via the usb cable, open the serial port window in the Arduino IDE window. you should see the following responses to/from the webbrowser as content is displayed on your browser and you select led on/off.


20. If no response in serial window, ensure the baud rate of COMport of pc matches the baud rate in the code uploaded as well as in the serial window. in my case, all three are 115200.

21. If all 3 baud rates match, try reloading the code example again.during my development and test i needed to perform this task multiple times, i did not try a slower baud rate.

My 1st Code mishap:


I had the DC Motor code in the Void loop, so it was always running while the Webpage was trying to update!!! corrected code below.

22. If this web page loads and functions correctly, you can upload my motor control version : SimpleWebServerWiFi_MKR1000_L298N_Control from here. (Video is not uploaded yet)

23. Helpful guides found after my 1st few days...1 week passed (revised 3/6/16)

https://www.hackster.io/charifmahmoudi/arduino-mkr1000-getting-strarted-08bb4a?utm_source=hackster&utm_medium=email&utm_campaign=new_projects

https://www.hackster.io/nazarenko_a_v/mkr1000-unboxing-and-testing-7-steps-13f8f8?ref=part&ref_id=15858&offset=0

https://www.hackster.io/charifmahmoudi/arduino-mkr1000-getting-strarted-08bb4a?ref=part&ref_id=15858&offset=6

https://www.hackster.io/nazarenko_a_v/mkr1000-connecting-to-the-wifi-3-steps-d02fed?ref=part&ref_id=15858&offset=7 

https://www.hackster.io/mohanp/mkr1000-azure-iot-hub-interface-using-http-57bfda?ref=part&ref_id=15858&offset=2

https://www.hackster.io/mohanp/mkr1000-windows-remote-arduino-with-firmata-wifi-7352be?ref=part&ref_id=15858&offset=1

24. Layout and test of WiFi_L298N_DC_Motor Control Test Bed.

This is MKR1000 SimpleWebServerDCMotorControl-Version 2

MKR1000 SimpleWebServerDCMotorControl-version 2

Next step to install the MKR1000 and L298N DC Motor Controller onto the Adafruit Basic Robot Platform.

I transferred Demo setup configuration on to the 2 wheeled platform...

2nd Coding mishap, responsiveness sluggish...robot gets away.

MKR1000 SimpleWebServerDCMotorControl-version2

I now need to revise code to limit travel of each command.

See MKR1000 SimpleWebServerDCMotorControl-version3

MKR1000 SimpleWebServerDCMotorControl-version3


Code

Revised MKR1000 WiFi Web Server codeArduino
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_ControlArduino
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-version3Arduino
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);
}

Schematics

MKR1000 and L298N interconnect
Hand drawn schematic
20160305 111142
MKR1000 and L298N Demo Layout
Demo Layout
20160305 111124
Demo Circuit
WiFi MKR1000 Demo
20160305 101102

Comments

Similar projects you might like

Wifi-Controlled Precision Camera Slider

Project showcase by Ben Brandt

  • 21,055 views
  • 3 comments
  • 63 respects

2WD Voice Controlled Robot with Arduino and BitVoicer Server

Project tutorial by Marcio Tamagushi

  • 10,203 views
  • 11 comments
  • 32 respects

Gesture-Controlled Robot

Project tutorial by Youssef El-Gendy and Romina Abachi

  • 4,167 views
  • 0 comments
  • 12 respects

3D Printed and Expandable Robot for Arduino

Project showcase by Matthew Hallberg

  • 2,856 views
  • 3 comments
  • 14 respects

WiFi Robot

Project tutorial by Team Kartik

  • 2,231 views
  • 1 comment
  • 8 respects
Add projectSign up / Login