Jose Luis Bejarano Vasquez
Published

Automatic food and water dispenser controlled by SMS

This is a food and water dispenser for your pet that is activated sending a sms from your cellphone.

BeginnerFull instructions provided2,341
Automatic food and water dispenser controlled by SMS

Things used in this project

Hardware components

Servos (Tower Pro MG996R)
×1
5v relay
×1
Ultrasonic sensor
×1
Mini Pump water
×1

Story

Read more

Schematics

Circuit diagram

Code

automatic_pet_feeder.ino

C/C++
/* This is a program for controlling a automatic pet food and water dispenser from a sms *. Letter 'W' activates the water dispenser and the letter 'F' activates the food dispenser
/*Programa para el manejo de un dispensador de comida y agua para mascotas controlado desde un mensaje de texto. Con la letra 'F' se activa el dispensador de comida y con 
la letra 'Wse activa el dispensador de agua */

#include <LGSM.h>    //Library for sms/ Libreria para mensajes de texto
#include <LDateTime.h>  //For the ultrasonic sensor HSR-04/ Para el sensor HSR-04
#include <Servo.h>
Servo servo;

int relay = 7; // Relay connected to the water pump

//***** Variables used for ultrasonic sensor***** 
const int TRIG_PIN = 8;
const int ECHO_PIN = 9;

void activatePump()
{
  digitalWrite(relay,HIGH);
}

void deactivatePump()
{
  digitalWrite(relay,LOW);
}

void activateServo()
{
   delay(1000);
  servo.write(180);

  delay(3000);
  servo.write(135);
  
  delay(1000);
  servo.write(70);
}


 
void setup()
{
  // initialize serial communication:
  Serial.begin(9600);
  
  servo.attach(3);
  servo.write(80);
  pinMode(relay,OUTPUT); 
  digitalWrite(relay,0);
  
  pinMode(TRIG_PIN,OUTPUT);
  pinMode(ECHO_PIN,INPUT);
  
  while(!LSMS.ready())
    {  
      delay(1000);
    }
    
    Serial.println("Tarjeta SIM lista para su uso!");

  }
  
 
void loop()
{
   long duration, distanceCm;
 
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse/ mando un pequeo pulso en bajo de antemano para asegurar un pulso limpio en alto
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  
  duration = pulseIn(ECHO_PIN,HIGH);
 
  distanceCm = duration / 29.1 / 2 ;
 
   Serial.println("Water bowl full");
 
   Serial.print(distanceCm);
   Serial.print("cm");
   Serial.println();
    
  //If theSi el tanque ya est lleno apago la bomba
    if(distanceCm<=8)
      {
          deactivatePump();
      }
      
  //********* SMS /Mensaje de texto ***************  
    char buf[20];
    
    int v;
    
    //If a text message is received... /Si se recibe un mensaje de texto...
    if(LSMS.available())
    {
      
      //*******************These lines are only for monitoring the received message in the serial port , they can be omitted in the program ********************************************
      Serial.println("Hay un nuevo mensaje.");
      
      LSMS.remoteNumber(buf, 20);    // Display Number part
      
      Serial.print("Numero:");
      
      Serial.println(buf);
      
      Serial.print("Contenido:");      // display Content part
      //*******************************************************************************************************************************************************************************
      
        while(true)
        
        {
          v = LSMS.read();   
        
          if(v < 0)
          
          break;
          
          Serial.print((char)v);
          
          if((char)v=='W')  //If receives letter W, then activate the mini pump water of the water dispenser/ Si recibe el caracter W activa la mini bomba de agua del dispensador de agua
            {
              activatePump();
            }
           
           if((char)v=='F')  //If receives letter F, then activates the servo of the food dispenser/ si recibe la letra F activa el servomotor del dispensador de comida
            {
              activateServo();
            
            }
            
            else
            
              digitalWrite(13,LOW);
        }  // end serial available
        
        Serial.println();
        
        LSMS.flush();  //Delete the received message / Borra el mensaje recibido
      
      }
    
    delay(1000);
    
    
}   // end loop

Credits

Jose Luis Bejarano Vasquez
5 projects • 22 followers
Electronic technologist, software developer and robotic lover.
Contact

Comments

Please log in or sign up to comment.