vinay y.n
Published © MIT

IoT Based Android phone accelerometer controlled robot

Controlling a robot vehicle movements using android phone sensors and Blynk app.

IntermediateProtip3 hours748
IoT Based Android phone accelerometer controlled robot

Things used in this project

Hardware components

NODEMCU ESP8266 12E
×1
L298N Motor driver
×1
DC Motor 12 volt 300RPM
×4
WHEELS
×1
SWITCH
×1
Rechargeable Battery, 12 V
Rechargeable Battery, 12 V
×1
CHASSIS
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

Connection Diagram: IoT Based Android phone accelerometer controlled robot

I have created the connection diagram using fritzing. In that, I have shown 9 v battery instead of 12-volt battery due to non-availability in the fritzing library.

Code

CODE: IoT Based Android phone accelerometer controlled robot

Arduino
Blynk Libraries have not defaulted in the Arduino IDE So we have to download and use it separately.
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "Add your blynk authentication key";
char ssid[] = "your wi-fi name";
char pass[] = "your wifi password";
const int ml1 = 1;//pins for controlling the motor drivers
const int ml2 = 2;//pins for controlling the motor drivers
const int mr1 = 4;//pins for controlling the motor drivers
const int mr2 = 5;//pins for controlling the motor drivers
void setup()
{
  pinMode(ml1, OUTPUT);
  pinMode(ml2, OUTPUT);
  pinMode(mr1, OUTPUT);
  pinMode(mr2, OUTPUT);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}
void loop()
{
  Blynk.run();
}
BLYNK_WRITE(V1)
{
  int x = param[0].asFloat(); //acceleration force applied to axis x
  int y = param[1].asFloat(); //acceleration force applied to axis y
  int z = param[2].asFloat();//acceleration force applied to axis z
  Serial.print("x axis:");
  Serial.println(x);
  Serial.print("y axis:");
  Serial.println(y);
  Serial.print("z axis:");
  Serial.println(z);
  if (y == 0 && x == 0)//stop
  {
    digitalWrite(ml1, HIGH);
    digitalWrite(ml2, HIGH);
    digitalWrite(mr1, HIGH);
    digitalWrite(mr2, HIGH);
  }
  else if (y < 0)//forward
  {
    digitalWrite(ml1, HIGH);
    digitalWrite(ml2, LOW);
    digitalWrite(mr1, HIGH);
    digitalWrite(mr2, LOW);
  }
  else if (z < 6)//reverse
  {
    digitalWrite(ml1, LOW);
    digitalWrite(ml2, HIGH);
    digitalWrite(mr1, LOW);
    digitalWrite(mr2, HIGH);
  }
  else if (x > 1)//right
  {
    digitalWrite(ml1, HIGH);
    digitalWrite(ml2, LOW);
    digitalWrite(mr1, LOW);
    digitalWrite(mr2, HIGH);
  }
  else if (x < 0)//left
  {
    digitalWrite(ml1, LOW);
    digitalWrite(ml2, HIGH);
    digitalWrite(mr1, HIGH);
    digitalWrite(mr2, LOW);
  }
  else
  {

  }
}

Credits

vinay y.n

vinay y.n

4 projects • 23 followers
Maker | Hardware Hacker | Electronics Enthusiast

Comments

Add projectSign up / Login