Project tutorial

M-Car © GPL3+

A Simple IoT Car!

  • 825 views
  • 0 comments
  • 2 respects

Components and supplies

Necessary tools and machines

Scissors
ScrewDriver
Cutter

Apps and online services

Google Chrome

About this project

First of all I am a fan of Arduino and I love what some us endless things you can create with it, and this little car is one of them.

Code

M-Car_Source_CodeArduino
The M-Car Source Code :D
/*
    /|    //| |         //   ) )                 
   //|   // | |        //         ___      __    
  // |  //  | | ____  //        //   ) ) //  ) ) 
 //  | //   | |      //        //   / / //       
//   |//    | |     ((____/ / ((___( ( //        */


/*   _____    _______  ______   _______ _________ _______          
  / ___ \  (  ____ )/ ___  \ (  ____ )\__   __/(  ____ \|\     /|
 / / _ \ \ | (    )|\/   \  \| (    )|   ) (   | (    \/| )   ( |
( ( / \ ) )| (____)|   ___) /| (____)|   | |   | (_____ | (___) |
| |(()// / |  _____)  (___ ( |     __)   | |   (_____  )|  ___  |
( ( \___/  | (            ) \| (\ (      | |         ) || (   ) |
 \ \____/\ | )      /\___/  /| ) \ \_____) (___/\____) || )   ( |
  \______/ |/       \______/ |/   \__/\_______/\_______)|/     \| */

                                                              
/*                                                              
--.-- --.-- .-.  .-.    .--. .---.                            
  |     |  (   )(   )  :     |                         o      
  |     |   `-.  `-.   | --. |--- .-. .--..--..-.  .--..  .--.
  |     |  (   )(   )  :   | |   (.-' |   |  (   ) |   |  `--.
--'--o--'--o`-'o `-'    `--'o'    `--''   '   `-'`-' -' `-`--' */
/*
Before sending the program to the Arduino board , 
make sure the connections are correct , 
which has as its browser Google Chrome , 
and you have a Wifi connection. */
/* Instructions */ /* Instructions */ /* Instructions */
/* 
1) Send the program to the Arduino board .
2) Wait 20 seconds to complete initialization of the Wifi Shiled (ESP8266) .
3) Connect your phone to the Wifi connection : " Ai- Thinker " .
4) Open Google Chrome and go to address " 192.168.4.1 " .
5) HAVE FUN !.
 */

#include <SoftwareSerial.h>
#include <String.h>
#include <Servo.h>
#define DEBUG true
SoftwareSerial esp8266 (10,11);
Servo frontWheel;
int blueLed = 12; int redLed = 8; int greenLed = 13;
/* Ruota posteriore destra */
const int enablePinRight = 9; //Aziona il ponte H.
const int forwardVerseRight = 4; //Fa andare il motore destro in avanti.
const int backVerseRight = 3; //Fa andare il motore destro indietro.
/* Fine dichiazioni ruota posteriore destra */
/* Ruota posteriore sinistra */
const int enablePinLeft = 6; //Aziona il ponte H.
const int forwardVerseLeft = 2; //Fa andare il motore sinistro in avanti.
const int backVerseLeft = 5; //Fa andare il motore sinistro indietro.
/* Fine dichiazioni ruota posteriore sinistra */
String webPage = "<html><head><title>M-Car</title><link rel='shortcut icon' type='image/x-icon' href='http://arduino.cc/en/favicon.png' /></head><body bgcolor='grey'><p align='center'><button><a href='/?Power=1'>Avvia Motore</a></button></p><br><p align='left'><button><a href='/?Turn=2'>Gira a Sinistra</a></button><p align='right'><button><a href='/?Turn=3'>Gira a Destra</a></button></p></p><br><p align='center'><button><a href='/?Turn=4'>Vai Dritto</a></button></p><br><p align='center'><button><a href='/?Power=0'>Spegni Motore</a></button></p></body></html>";
String search = "";
int startPos = 90; int pos;
void setup (){
  Serial.begin (115200);
  esp8266.begin (115200);
  frontWheel.attach (7);
  pinMode (blueLed,OUTPUT);
  pinMode (redLed,OUTPUT);
  pinMode (greenLed,OUTPUT);
  pinMode (enablePinRight,OUTPUT);
  pinMode (forwardVerseRight,OUTPUT);
  pinMode (backVerseRight,OUTPUT);
  pinMode (enablePinLeft,OUTPUT);
  pinMode (backVerseLeft,OUTPUT);
  pinMode (forwardVerseLeft,OUTPUT);
  esp8266.print ("AT+RST\r\n"); /*Resetta il modulo.*/ delay (2000);
  esp8266.print ("AT+CWMODE=2\r\n"); /*Imposta il modulo come punto di accesso.*/ delay (2000);
  esp8266.print ("AT+CIFSR\r\n"); /*Localizza l'indirizzo ip.*/ delay (2000);
  esp8266.print ("AT+CIPMUX=1\r\n"); /*Imposta la connessione multipla.*/ delay (2000);
  esp8266.print ("AT+CIPSERVER=1,80\r\n"); /*Crea il server sulla porta 80.*/ delay (2000);
  Serial.println ("Inizzializzazione avvenuta con successo!");
  digitalWrite (greenLed,HIGH);
  digitalWrite (enablePinRight,HIGH);
  digitalWrite (enablePinLeft,HIGH);
  frontWheel.write (startPos); 
}
void loop (){
  while (esp8266.available()){
    char data = esp8266.read();
    search.concat (data);
  }
  if (esp8266.find("+IPD,")){ //Se la connessione  avvenuta con successo...
    if (search.indexOf("Power=1")>-1){
      Serial.println ("Motori Accesi!");
      digitalWrite(backVerseRight, LOW);
      digitalWrite(forwardVerseRight, HIGH);
      digitalWrite(backVerseLeft, LOW);
      digitalWrite(forwardVerseLeft, HIGH);
    }
    if (search.indexOf("Turn=2")>0){
      Serial.println ("Giro a Sinistra");
      frontWheel.write (80); 
    }
    if (search.indexOf("Turn=3")>0){
      Serial.println ("Giro a Destra");
      frontWheel.write (105);
    }
    if (search.indexOf("Turn=4")>0){
      Serial.println ("Vado Dritto");
      frontWheel.write (90);
    }
    if (search.indexOf("Power=0")>0){
      Serial.println ("Motori Spenti");
      digitalWrite(backVerseRight, LOW);
      digitalWrite(forwardVerseRight, LOW);
      digitalWrite(backVerseLeft, LOW);
      digitalWrite(forwardVerseLeft, LOW);
    }
    int netId = esp8266.read() -48;
    esp8266.print (sendToEsp(netId,webPage.length())); 
    esp8266.print (webPage);  //Mostra la pagina..
    esp8266.print (closeEsp(netId));
    search = "";
    blink (); //Lampeggia :D
  }
}
String sendToEsp (int id,int webpageLength){ //Funzione per l'invio di dati al modulo.
  String data = "AT+CIPSEND=";
  data += id;
  data += ",";
  data += webpageLength;
  data += "\r\n";
  return data;
}
String closeEsp (int id){ //Funzione per la chiusura di connessione.
  String closeConnection = "AT+CIPCLOSE=";
  closeConnection += id;
  closeConnection += "\r\n";
  return closeConnection;
}
void blink (void){
  digitalWrite (blueLed,HIGH);
  delay (1000);
  digitalWrite (blueLed,LOW);
  digitalWrite (redLed,HIGH);
  delay (1000);
  digitalWrite (redLed,LOW);
  
}

Schematics

M-Car_Scheme
The M-Car Wiring Scheme :D
M car sheme

Comments

Created by

P3RISH

Are you P3RISH? Claim this project and add it to your profile.

This is mine

Posted by

P3rish
Mattia Colasanto
  • 1 project
  • 1 follower

Published on

May 22, 2016
See similar projects
you might like

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 455,790 views
  • 44 comments
  • 242 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 289,739 views
  • 96 comments
  • 677 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 229,864 views
  • 38 comments
  • 239 respects

OpenCat

Project in progress by Team Petoi

  • 197,061 views
  • 154 comments
  • 1,370 respects
Add projectSign up / Login