Pet Water Warden

details

This project shows how to give your pet water automatically when you are outside. It measures the height of the pet’s water bowl by connecting two sensors with micro controller. It operates the pump automatically to fill the water bowl with water if there is no water. It also sends you tweet message if all the water in the bowl runs out.

step1 : Build the sensor circuit

 

step2 : Build the water sensor on board.

step3 :

The circuit has two dip probes that can detect the height of water. It is detected when the water is reaching probe in the bottom of the bowl. It shows the status of the probe through LED.
Let’s test before soldering MakerShield.

step4 :

We solder the sensor circuit to MakerShield. We should connect the collector of transistor and contact pad of MakerShield as the wires of a pair. Please measure the voltage of the collector of transistor connected with probe. The sensor is turned on if it is in the water and is turned off if it is outside of the water. We will use the measured voltage at this time in your code. The collector is connected to the anode of LED.

step5 :

Strip a few inches of insulation part from the wire. Paste it in the bottom of water bowl through Sugru. Paste probes on the side of the wall in the water bowl.

step6 :

Cut the top off the jug to make an opening just big enough for the aquarium pump to fit through the top. Then, connect the pump to the hose. Fasten the pump to the bottom of the reservoir. Drill a 1/8″ hole in the hose, somewhere near the top of its arc but still inside the reservoir. This little vent will break suction and prevent water from siphoning out after the pump switches off. Any water that dribbles out the vent during pumping will run back down into the reservoir.
Code : 
/************************************************
  * Author: Eloy Salinas
  * Project: Pet Water Warden
  * Company: Make Magazine // RadioShack
  * Date: 8/8/13
  * Version: 1.0
  * http://makezine.com/projects/petwaterwarden/
  *************************************************/
  //Twitter capabilities thanks to http://arduino-tweet.appspot.com/
  
  
  //Ethernet Shield Version

  #include <SPI.h>
  #include <Ethernet.h>//Included with Arduino V1.0 and higher
  #include <Twitter.h>//Lib from Arduino Tweet
 
  //Twitter info
  // Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
  Twitter twitter("Your-Token-Here");
 
  // Message to post to twitter in case of a fail
  charmsg[] ="Pet Water Warden Error: Please check my water!";
 
  //Network information (Only edit if not using default mode).
  //Default mode is Auto DHCP, your router will assign an ip address.
  //Only fill in ip, gateway, and subnet if not using auto DHCP
  byte mac[] = {
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // this can be made up
  byteip[] = {
    0, 0, 0, 0 }; // a free IP address on your network
  byte gateway[] = {
    0, 0, 0, 0 }; // the gateway address of your network
  byte subnet[] = {
    0, 0, 0, 0 };  // the subnet mask of your network
 
  //Set output pin 8 to control switchtail/pump
  constint pump =8;
 
  //Failsafe off
  longtimerA=0;
  intwardenFailed=0; // Flag incase something goes wrong
 
voidsetup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
 
  //Set pump output pin
  pinMode(pump, OUTPUT);
 
  //Start with pump off
  digitalWrite(pump, LOW);
 
  
 
  //If not using auto DHCP use Ethernet.begin(mac, ip, gateway, subnet);
  Ethernet.begin(mac);  //begins the Ethernet connection and uses automatic DHCP
  Serial.begin(9600);  // starts serial communications so we can debug easier
  delay(1000);        // a 1 second delay to let everything settle down!
 
  // attempt a DHCP connection:
  Serial.println("Attempting to get an IP address using DHCP:");
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println("failed to get an IP address using DHCP, trying manually");
    Ethernet.begin(mac, ip);
  }
  Serial.print("My address:");
  Serial.println(Ethernet.localIP());
 
  //Test Twitter
  Serial.println("Pet Water Warden testing twitter connection...");  
 
  if (twitter.post("Pet Water Warden is up and running!!")) {  // Twitter that we are up and running
    int status =twitter.wait(&Serial);     // wait for a response from twitter                    
    if (status ==200) {    // if Twitter responds 200
      Serial.println(", Tweet is OK!");  // print success
      Serial.println();  // print a blank line, used for debugging
    }
    else {
      Serial.print("Tweet failed : code ");
      Serial.println(status);  // print error code
      Serial.println();  // print a blank line, used for debugging
    }
  }
  else {
    Serial.println("Connection to Twitter failed.");
  }
 
}
 
 
voidloop(){
 
  //Read the input on A0-A1
  //High and Low Sensors
  intsensorLow=analogRead(A1);
  intsensorHigh=analogRead(A0);
 
  //Convert to a voltage
  floatvoltageLow=sensorLow* (5.0/1023.0);
  floatvoltageHigh=sensorHigh* (5.0/1023.0);  
 
  //Sensor States
  intlowState=0;
  inthighState=0;
 
  //Are the sensors on or off?
  //Write states, voltage comparison values may need to be adjusted depending on your transistor 
  //and if you are using extneral or the MakerShields LEDs
  if (voltageLow>=3.3){lowState=0;}
  elseif (voltageLow<3.3){lowState=1;}
 
  if (voltageHigh>=3.3){highState=0;}
  elseif (voltageHigh<3.3){highState=1;}
 
  //Turn on the pump?
  if(highState==1&&lowState==1&&wardenFailed==0){
    digitalWrite(pump, LOW);
    timerA=0;  
  }elseif(highState==0&&digitalRead(pump) == LOW &&wardenFailed==0){
    //FailSafe Timers
    timerA=0;
    digitalWrite(pump, HIGH);
    timerA=millis();
    Serial.print("Starting timer: ");    
    Serial.println(timerA);
  }
 
  //My pet bowl fills in about 45 sec, adjust to the size
  // of your pet bowl
  if( (millis() -timerA) >=45000&&timerA!=0){
    digitalWrite(pump, LOW);  
    Serial.println(timerA);
    Serial.println(millis());
    timerA=0;
    //Either no water left or the pump didn't turn off, bad sensor?
    tweetFail();
    wardenFailed=1; // the Pet Warden Warden has run into trouble and failed
    Serial.print("Something went wrong! The wardenFailed status is: ");
    Serial.println(wardenFailed);
    exit(0);// exit the program until error is fixed
    Serial.println("Either no water left or the pump didn't turn off, bad sensor?");
  }
 
 
  //Debug Prints
  Serial.print("Low Sensor: ");
  Serial.println(lowState);
  Serial.print("High Sensor: ");
  Serial.println(highState);
  Serial.println(voltageLow);
  Serial.println(voltageHigh);
 
  //Check Sensors every 10 sec
  delay(10000);
 
 
}
 
 
voidtweetFail(){
    if (twitter.post(msg)) {  // Twitter that we are up and running
    int status =twitter.wait(&Serial);     // wait for a response from twitter                    
    if (status ==200) {    // if Twitter responds 200
      Serial.println(", Tweet is OK!");  // print success
      Serial.println();  // print a blank line, used for debugging
    }
    else {
      Serial.print("Tweet failed : code ");
      Serial.println(status);  // print error code
      Serial.println();  // print a blank line, used for debugging
      //If Tweet fails try again
      tweetFail();
    }
  }
  else {
    Serial.println("Connection to Twitter failed.");
  }
}

Result :

URL :http://kocoafab.cc/make/view/18

COMMENTS

Please Login to comment
  Subscribe  
Notify of