Grass Cutter Robot

An Internet-controlled robot that can cut the grass of a garden area with ease and efficiently.

AdvancedFull instructions provided2 days7,951
Grass Cutter Robot

Things used in this project

Story

Read more

Code

robot control

Arduino
controlling robot over internet
#ifndef __CC3200R1M1RGC__
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>

//define the pins to be connected to ultrasonic sensorw
//define the pins to be connected to ultrasonic sensor

#define LeftMotor1  24
#define LeftMotor2  25

#define RightMotor1 26

#define RightMotor2 27

#define CUTTER 28

char ssid[] = "UNKNOWN WIFI";
char password[] = "rajsinha123";

const int HTTPPORT = 80;
char * USER_AGENT = "TI";
char * VERSION = "1.0";
char * server = "industrial.api.ubidots.com";
char* TOKEN = "BBFF-rSICR8dcv40GP01Nl1iklcEVcN7tNj"; // Put here your TOKEN

char* DEVICE_LABEL = "autobot"; // Your Device label

/* Put here your variable's labels*/
char const * VARIABLE_LABEL = "autobot";
WiFiClient client;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(115200);

  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to Network named: ");
  // print the network name (SSID);
  Serial.println(ssid); 
  // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED) {
    // print dots while we wait to connect
    Serial.print(".");
    delay(300);
    pinMode(LeftMotor1,  OUTPUT);

  pinMode(LeftMotor2,  OUTPUT);

  pinMode(RightMotor1, OUTPUT);

  pinMode(RightMotor2, OUTPUT);

  
  }
  
  Serial.println("\nYou're connected to the network");
  Serial.println("Waiting for an ip address");
  
  while (WiFi.localIP() == INADDR_NONE) {
    // print dots while we wait for an ip addresss
    Serial.print(".");
    delay(300);
  }

 
}


void loop() {
   if (client.connect(server, 80)) {
    client.print(F("GET /api/v1.6/devices/"));
    client.print(DEVICE_LABEL);
    client.print(F("/"));
    client.print(VARIABLE_LABEL);
    client.print(F("/lv"));
    client.print(F(" HTTP/1.1\r\n"));
    client.print(F("Host: "));
    client.print(server);
    client.print(F("\r\n"));
    client.print(F("User-Agent: "));
    client.print(USER_AGENT);
    client.print(F("/"));
    client.print(VERSION);
    client.print(F("\r\n"));
    client.print(F("X-Auth-Token: "));
    client.print(TOKEN);
    client.print(F("\r\n"));
    client.print(F("Content-Type: application/json\r\n\r\n"));
    client.println();
    
}
  String s="";
  bool a=false;
  char movement='5';
  while (client.available()) {
    char c = client.read();
    s=s+c;
    a=true;
  }

  Serial.println(s);
   movement = get_movement(s);
   Serial.println(movement);
 
  if(a==true){
      client.stop();
      a=false;
  }
 
  if(movement=='1'){    //Forward

  digitalWrite(LeftMotor1, HIGH);

  digitalWrite(LeftMotor2, LOW);

  digitalWrite(RightMotor1, HIGH);

  digitalWrite(RightMotor2, LOW);

  
  }
  else if(movement=='2'){ //Backward

  digitalWrite(LeftMotor2, HIGH);

  digitalWrite(LeftMotor1, LOW);

  digitalWrite(RightMotor2, HIGH);

  digitalWrite(RightMotor1, LOW);

    }
  else if(movement=='3'){ //left
    
  digitalWrite(LeftMotor1, HIGH);

  digitalWrite(LeftMotor2, LOW);

  digitalWrite(RightMotor1, LOW);

  digitalWrite(RightMotor2, LOW);

  }
  else if(movement=='4'){ //Right
  
  digitalWrite(LeftMotor1, LOW);

  digitalWrite(LeftMotor2, LOW);

  digitalWrite(RightMotor1, HIGH);

  digitalWrite(RightMotor2, LOW);
  }
  else if(movement=='5'){ //stop
  digitalWrite(LeftMotor1, LOW);

  digitalWrite(LeftMotor2, LOW);

  digitalWrite(RightMotor1, LOW);

  digitalWrite(RightMotor2, LOW);
  }
   else if(movement=='6')
  digitalWrite(CUTTER , HIGH);
   
    else if(movement=='7')
    digitalWrite(CUTTER , LOW);
 
 }


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");
}


char get_movement(String a){
  int endi =0;
  int i;
  for(i=0;i<a.length();i++){

    if(a.charAt(i)=='\n'){
      endi++;
    }
    if(endi==10){
      break;
    }
  }
  return a.charAt(i+1);
  
}

Credits

Dr. Umesh Dutta

Dr. Umesh Dutta

38 projects • 56 followers
Working as Director of Innovation Centre at Manav Rachna, India. I am into development for the last 12 years.
Himanshu Sinha

Himanshu Sinha

2 projects • 6 followers
Deepak Singh

Deepak Singh

1 project • 2 followers
Drishti dua

Drishti dua

1 project • 5 followers
riya raina

riya raina

1 project • 5 followers
Kajol Thakur

Kajol Thakur

1 project • 5 followers
Texas Instruments University Program

Texas Instruments University Program

91 projects • 120 followers
TI helps students discover what's possible to engineer their future.
Energia

Energia

34 projects • 26 followers
Founder of @energiaproject
devdutt

devdutt

10 projects • 9 followers
Robotic Gold Medalist at IIT Guwahati and Embedded,Hardware Developer at Manav Rachna Innovation and Incubation Centre

Comments