Ioannis Kydonis
Published © GPL3+

Wi-Fi RC Car - Qi Enabled

This is a project that will show you how to create a Wi-Fi controlled RC Car that will recharge wirelessly while it is parked.

EasyFull instructions provided3 hours10,672
Wi-Fi RC Car - Qi Enabled

Things used in this project

Hardware components

Qi 5W Transmitter Prototype Kit
IDT Qi 5W Transmitter Prototype Kit
×1
Qi 5W Receiver Prototype Kit
IDT Qi 5W Receiver Prototype Kit
×1
Arduino MKR1000
Arduino MKR1000
×1
• 2WD Robot Car Chassis for Arduino
×1
L293DNE
×1
CN6009 - Step-up boost Power Converter Module
×1
3.7V Li-Po Battery
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×8
LED (generic)
LED (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Tie Wraps
×5
Breadboard (generic)
Breadboard (generic)
(Optional)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
Screwdriver
Voltmeter

Story

Read more

Custom parts and enclosures

PCBWeb

Schematics

Schematic

Wifi car 4

Code

Arduino_IDT_Wi-Fi_Car.ino

Arduino
Replace example and password in lines 12-13 with your ssid and password respectively.
#include <SPI.h>
#include <WiFi101.h>

const int motor1Control = 2; // Right motor
const int motor2Control = 3; // Left motor
const int motor1Input1 = 4;
const int motor1Input2 = 5;
const int motor2Input1 = 8;
const int motor2Input2 = 9;
const int wifiLed = 10; // For indicating successful Wi-Fi connection

char ssid[] = "example";   // Fill in your network SSID (name)
char pass[] = "password"; // Fill in your network password
int keyIndex = 0;          // Fill in your network key Index number (Optional - needed only for WEP)

int status = WL_IDLE_STATUS;
String readString;

WiFiServer server(80); // Define the port of the server

String speedMode = "fast";

void setup() {
  pinMode(motor1Control, OUTPUT);
  pinMode(motor2Control, OUTPUT);
  pinMode(motor1Input1, OUTPUT);
  pinMode(motor1Input2, OUTPUT);
  pinMode(motor2Input1, OUTPUT);
  pinMode(motor2Input2, OUTPUT);
  pinMode(wifiLed, OUTPUT);
  
  // Attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    // For WEP network, replace with: status = WiFi.begin(ssid, keyIndex, pass);
    // For open network, replace with: status = WiFi.begin(ssid);
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }

  // Begin the webserver
  server.begin();
  // Indicate that the server is running
  digitalWrite(wifiLed, HIGH);
}

void loop() {
  // Listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // If you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
        }
        
        if (c == '\n') {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<head>");
          client.println("<style>");
          client.println("a.button {-webkit-appearance: button;");
          client.println("-moz-appearance: button;");
          client.println("appearance: button;");
          client.println("height:400px;");
          client.println("line-height:400px;");
          client.println("text-align:center;");
          client.println("text-decoration: none;");
          client.println("font-size: 100px;");
          client.println("color: initial;}");
          client.println("</style>");
          client.println("</head>");
          client.println("<body>");
          // Button for moving Forwards
          client.println("<a href=\"/?moveForwards\" class=\"button\" style=\"width:100%;\"\">FORWARDS</a>");
          client.println("<br />");
          // Button for turning Left
          client.println("<a href=\"/?turnLeft\" class=\"button\" style=\"width:35%;\"\">LEFT</a>");
          // Button for Stopping the car
          client.println("<a href=\"/?stopMoving\" class=\"button\" style=\"width:29%;\"\">STOP</a>");
          // Button for turning Right
          client.println("<a href=\"/?turnRight\" class=\"button\" style=\"width:35%;\"\">RIGHT</a>");
          client.println("<br />");
          // Button for moving Backwards
          client.println("<a href=\"/?moveBackwards\" class=\"button\" style=\"width:100%;\"\">BACKWARDS</a>");
          client.println("<br />");
          client.println("<br />");
          // Button for moving Backwards
          client.println("<h1 style=\"text-align:center;\">SPEED MODES</h1>");
          client.println("<a href=\"/?fast\" class=\"button\" style=\"width:45%;\"\">FAST</a>");
          client.println("<a href=\"/?slow\" class=\"button\" style=\"width:45%;\"\">SLOW</a>");
          client.println("</body>");
          client.println("</html>");
           break;
        }
        
        // Decide which button was clicked (if any)
        // Fast Mode button
        if (readString.indexOf("?fast") > 0){
          speedMode = "fast";
          // Clear the readString to be able to get the next command
          readString = "";
        }
        // Slow Mode button
        if (readString.indexOf("?slow") > 0){
          speedMode = "slow";
          // Clear the readString to be able to get the next command
          readString = "";
        }
        // Fast Mode
        if (speedMode == "fast"){
          if (readString.indexOf("?moveForwards") > 0){
            moveForwards();
            // Clear the readString to be able to get the next command
            readString = "";
          }
          if (readString.indexOf("?moveBackwards") > 0){
            moveBackwards();
            // Clear the readString to be able to get the next command
            readString = "";
          }
        } else if (speedMode == "slow"){
          // Slow Mode
          if (readString.indexOf("?moveForwards") > 0){
            moveForwardsSlow();
            // Clear the readString to be able to get the next command
            readString = "";
          }
          if (readString.indexOf("?moveBackwards") > 0){
            moveBackwardsSlow();
            // Clear the readString to be able to get the next command
            readString = "";
          }
        }
        if (readString.indexOf("?turnLeft") > 0){
          turnLeft();
          // Clear the readString to be able to get the next command
          readString = "";
        }
        if (readString.indexOf("?turnRight") > 0){
          turnRight();
          // Clear the readString to be able to get the next command
          readString = "";
        }
        if (readString.indexOf("?stopMoving") > 0){
          stopMoving();
          // Clear the readString to be able to get the next command
          readString = "";
        }
      }
    }
    // Give the web browser time to receive the data
    delay(1);
    // Close the connection:
    client.stop();
  }
}

// Commands for moving forwards
void moveForwards(){
  digitalWrite(motor1Control, HIGH);
  digitalWrite(motor2Control, HIGH);
  digitalWrite(motor1Input1, LOW);
  digitalWrite(motor1Input2, HIGH);
  digitalWrite(motor2Input1, LOW);
  digitalWrite(motor2Input2, HIGH);
}
// Commands for moving backwards
void moveBackwards(){
  digitalWrite(motor1Control, HIGH);
  digitalWrite(motor2Control, HIGH);
  digitalWrite(motor1Input1, HIGH);
  digitalWrite(motor1Input2, LOW);
  digitalWrite(motor2Input1, HIGH);
  digitalWrite(motor2Input2, LOW);
}
// Commands for turning right
void turnRight(){
  // Lower voltage is provided to turn slower - better control
  analogWrite(motor1Control, 0);
  analogWrite(motor2Control, 200);
  digitalWrite(motor1Input1, HIGH);
  digitalWrite(motor1Input2, LOW);
  digitalWrite(motor2Input1, LOW);
  digitalWrite(motor2Input2, HIGH);
}
// Commands for turning left
void turnLeft(){
  // Lower voltage is provided to turn slower - better control
  analogWrite(motor1Control, 200);
  analogWrite(motor2Control, 0);
  digitalWrite(motor1Input1, LOW);
  digitalWrite(motor1Input2, HIGH);
  digitalWrite(motor2Input1, HIGH);
  digitalWrite(motor2Input2, LOW);
}
// Commands for stopping the car
void stopMoving() {
  digitalWrite(motor1Control, LOW);
  digitalWrite(motor2Control, LOW);
  digitalWrite(motor1Input1, LOW);
  digitalWrite(motor1Input2, LOW);
  digitalWrite(motor2Input1, LOW);
  digitalWrite(motor2Input2, LOW);
}
// Commands for low speed forward moving
void moveForwardsSlow(){
  analogWrite(motor1Control, 200);
  analogWrite(motor2Control, 200);
  digitalWrite(motor1Input1, LOW);
  digitalWrite(motor1Input2, HIGH);
  digitalWrite(motor2Input1, LOW);
  digitalWrite(motor2Input2, HIGH);
}
// Commands for low speed backward moving
void moveBackwardsSlow(){
  analogWrite(motor1Control, 200);
  analogWrite(motor2Control, 200);
  digitalWrite(motor1Input1, HIGH);
  digitalWrite(motor1Input2, LOW);
  digitalWrite(motor2Input1, HIGH);
  digitalWrite(motor2Input2, LOW);
}

Credits

Ioannis Kydonis

Ioannis Kydonis

2 projects • 16 followers

Comments