icon

How to Make a Google Assistant Control Car with an Integration of AI and IoT.

projectImage
STEP 1
Introduction:

Hey Guys, welcome to my new article. So guys today we are going to make a " Google Assistant Control Car Using Node MCU ".

 

Project Information:

The project is based on the use of AI and IoT devices together for creating a fast, simple and cool ecosystem. Here in this project, I am going to create a Voice assistance control car that makes use of AI (Google assistance, Alexa, etc) and IoT Components (ESP8266, NodeMcu) to make this voice automation car.

 

You might be thinking, Where can it be Used?

It can be used for making a real-world voice-automated car in the future, just like Tesla has their automated parking system in their cars, but to use it we need to use our smartphones to do that, just thinking if you would just say "Hey Google, Park my car" and your car is parked in its parking place. So it can be done by this voice automation idea.

 

Special thanks to PCBWay for sponsoring this project.

So let's get started with the project :-)

STEP 2
🚀 Materials Required:
Node MCU:https://amzn.to/3G5aFUkL298N motor driver: https://amzn.to/3GxIMpqBo Motor (4x): https://amzn.to/3i0EnBURubber wheel (4x): https://amzn.to/3i7n9mfJumper wire: https://amzn.to/3Gycrid18650 battery: https://amzn.to/3vunOBu18650 battery holder: https://amzn.to/3hY0pFr
STEP 3
Making Of The Chassy :

~ So for making the chassis I am using cardboard which is cut 10*14 cm.

~ Then we need a gear motor 4pcs.

~ We will stick the motor with the cardboard using the hot glue gun.

~ We move into the wiring of the motors, the wiring will go in this way we will solder the wires of the same side in a crossword direction. As shown in the above image.

~ We will require a rubber wheel (4pcs) for the motor.

~ Then our chassis will be ready.

let's move to the next step...

STEP 4
Attaching The Motor Driver with the chassis:

~ over here we will be using the L298N Motor driver.

~ Attach the motor drivier to the back side of the chassis with the help of glue. As shown in the image.

~ Then you need to connect the motor wire to the motor terminals of the motor driver.

and that's all you need to do for making the chassis functional.

STEP 5
Mount The Node MCU And Motor Drivers Connections:

~ Here first we will make the connection between the motor driver and the Node MCU.

Motor driver pins with Node MCU pins:

IN1 to D8

IN2 to D7

IN3 to D3

IN4 to D4

enA to D5

enB to D6

~ So that is all we need to do with the motor driver pins...

STEP 6
How Can I Simplify My Circuit?

This can be done by using a PCB, I have many times used a custom-designed circuit board to give more professional touch. So I choose PCBWay to design and order the custom-designed PCB for this project.

 

About PCBWay:

 

With more than a decade in the field of PCB prototype and fabrication, They are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness, and any other demanding requests. As one of the most experienced PCB manufacturers in China, They pride themselves to be the best business partners as well as good friends in every aspect of our PCB needs.

 

They provide 2 layers of PCB just for $5, they also provide 4-6 layers of PCB manufacturing as well as SMT and STENCILS Services at very low cost and their other services are CNC and 3D Printing.

 

Make sure to visit their website PCBWay.com .

STEP 7
Setup For Adafruit Io And IFTTT:

For this project, we have made use of an integration of Adafruit Io and IFTTT. With this integration, we can easily control our car with google assistance.

 

Watch the above video to do the integration of Adafruit Io and IFTTT.

STEP 8
Time To Upload The Sketch:

Watch the above video for uploading the sketch.

Upload the code and don't forget to include the libraries.

 

Library download links:

 

Adafruit MQTT Library - Arduino Libraries

Adafruit_MQTT Clint

CODE
//Google Assistance control Robot
//Created By roboattic Lab
//Contact me here https://www.instagram.com/diy_burner/
//You need to include "ESP8266WiFi.h,Adafruit_MQTT.h,Adafruit_MQTT_Client.h" library before uploading the sketch, otherwise you'll get compilation error message.

#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"


#define ENA 14   // Enable/speed motors Right        GPIO14(D5)
#define IN1 15   // L298N in1 motors Right           GPIO15(D8)
#define IN2 13   // L298N in2 motors Right           GPIO13(D7)
#define IN3 2    // L298N in3 motors Left            GPIO2(D4)
#define IN4 0    // L298N in4 motors Left            GPIO0(D3)
#define ENB 12   // Enable/speed motors Left         GPIO12(D6)


//Your WIFI name and password


#define WLAN_SSID       "name"             // Your SSID
#define WLAN_PASS       "password"        // Your password


/************************* Adafruit.io Setup *********************************/


#define AIO_SERVER      "io.adafruit.com" //Adafruit Server
#define AIO_SERVERPORT  1883                   
#define AIO_USERNAME    "username"            // Username
#define AIO_KEY         "key"   // Auth Key


//WIFI CLIENT
WiFiClient client;


Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);


Adafruit_MQTT_Subscribe Forward = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME"/feeds/forward"); // Feeds name should be same everywhere
Adafruit_MQTT_Subscribe Left = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/left");
Adafruit_MQTT_Subscribe Right = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/right");
Adafruit_MQTT_Subscribe Backward = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/Backward");


void MQTT_connect();


void setup() {
  Serial.begin(115200);


  //Set the motor pins as output pins
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENB, OUTPUT);
  
  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);


  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();


  Serial.println("WiFi connected");
  Serial.println("IP address: "); 
  Serial.println(WiFi.localIP());
 
  mqtt.subscribe(&Forward);
  mqtt.subscribe(&Left);
  mqtt.subscribe(&Right);
  mqtt.subscribe(&Backward);


}


void loop() {
 
  MQTT_connect();
  


  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(20000))) {
    if (subscription == &Forward) {
     
      Serial.print(F("Got: "));
      Serial.println((char *)Forward.lastread);
      int Forward_State = atoi((char *)Forward.lastread);
      if(Forward_State ==1)
      {
         goAhead();
         delay(1600);
         carStop();
      }
     }
      
    
      if (subscription == &Left) {
      Serial.print(F("Got: "));
      Serial.println((char *)Left.lastread);
      int Left_State = atoi((char *)Left.lastread);
      if(Left_State == 1)
      {
        
          goLeft();
          delay(1500);
          carStop();
      }
    }


    if (subscription == &Right) {
      Serial.print(F("Got: "));
      Serial.println((char *)Right.lastread);
      int Right_State = atoi((char *)Right.lastread);
      if(Right_State == 1)
      {
        
          goRight();
          delay(1500);
          carStop();
      }
    }
    
    if (subscription == &Backward) {
      Serial.print(F("Got: "));
      Serial.println((char *)Backward.lastread);
      int Backward_State = atoi((char *)Backward.lastread);
      if(Backward_State == 1)
      {
        
          goBack();
          delay(1600);
          carStop();
      }
    }


    
  }


}


void MQTT_connect() {
  int8_t ret;


  if (mqtt.connected()) {
    return;
  }


  Serial.print("Connecting to MQTT... ");


  uint8_t retries = 3;
  
  while ((ret = mqtt.connect()) != 0) {
    Serial.println(mqtt.connectErrorString(ret));
    Serial.println("Retrying MQTT connection in 5 seconds...");
    mqtt.disconnect();
    delay(5000); 
    retries--;
    if (retries == 0) {
      while (1);
    }
  }
  Serial.println("MQTT Connected!");
  
}


void goAhead(){ 


      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      analogWrite(ENA, 200);


      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      analogWrite(ENB, 200);
      
  }


void goBack(){ 
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      analogWrite(ENA, 200);


      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      analogWrite(ENB, 200);
      
  }


void goRight(){ 


      digitalWrite(IN1, LOW);
      digitalWrite(IN2, HIGH);
      analogWrite(ENA, 200);


      digitalWrite(IN3, HIGH);
      digitalWrite(IN4, LOW);
      analogWrite(ENB, 200);
      
  }


void goLeft(){


      digitalWrite(IN1, HIGH);
      digitalWrite(IN2, LOW);
      analogWrite(ENA, 200);


      digitalWrite(IN3, LOW);
      digitalWrite(IN4, HIGH);
      analogWrite(ENB, 200);
     
  }
void carStop() {
      digitalWrite(IN1, LOW);
      digitalWrite(IN2, LOW);
      analogWrite(ENA, 0);


      digitalWrite(IN3, LOW);
      digitalWrite(IN4, LOW);
      analogWrite(ENB, 0);
}
STEP 9
All Set, Now It's Time To Test It:


After done with uploading the code. Just put the battery into the Battery Holder and enjoy the project.

 

Watch our YouTube video to see its testing video. Watch Now!

STEP 10
We're Done Now:

We're Done Now. I hope you like my project and if you have any queries then leave your comments here, I will surely help you with it if you have any idea of any new type of project then please comment here I will be definitely making it.

 

I'll keep updating this Article.

 

For Business or Promotion Query e-mail me on Email

 

Thanks for watching the project, I hope you liked this project, if you did then please follow me I'll keep posting awesome new projects. Also, don't forget to SUBSCRIBE to my YouTube channel. (YouTube: roboattic Lab).

License
All Rights
Reserved
licensBg
0