Pet Feeder

Now you can feed your pets, even when you are away from them by leveraging the power of IoT and a smartphone app.

IntermediateFull instructions provided2 days4,438
Pet Feeder

Things used in this project

Story

Read more

Code

MSP432 Code for receiving the data from server

Arduino
This code receives data from server and provides trigger to MSP430 launchpad for controlling the servo motor
#ifndef __CC3200R1M1RGC__
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>
 
// ssid and password of the hotspot to which CC3100 module is connected
char ssid[] = "vivo 1802";
char password[] = "nevergiveup";

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

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

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

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

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



void setup() {
  pinMode(2,OUTPUT);
  digitalWrite(2,HIGH);
  //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);
  }
  
  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')
  {    
    // provide a trigger to MSP430 launchpad for rotating the servo motor
   digitalWrite(2,LOW);
   delay(1000);
   digitalWrite(2,HIGH);
   delay(1000);
  }
  if(movement=='2')
  {
    //command to stop the rotation of servo motor
    digitalWrite(2,HIGH);// keep 2nd pin HIGH, stop command to MSP430
  }
}

Credits

Dr. Umesh Dutta

Dr. Umesh Dutta

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

Vipin official

2 projects • 2 followers
Texas Instruments University Program

Texas Instruments University Program

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

Energia

34 projects • 26 followers
Founder of @energiaproject
chirag arora

chirag arora

0 projects • 1 follower
Aditya Singh

Aditya Singh

0 projects • 0 followers
Harshit Jain

Harshit Jain

0 projects • 1 follower
devdutt

devdutt

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

Comments