Shiyun Guan
Published

Smart Cat Litter box

Get into insights about my cat's well-being by capturing his littering behavior with an ultrasonic ranger and record it on a 4-digit display

BeginnerFull instructions provided1 hour385
Smart Cat Litter box

Things used in this project

Story

Read more

Code

Smart Cat Litter Box

Arduino
#include "TM1637.h"
#include <Ultrasonic.h>

Ultrasonic ultrasonic(7); //define pin
const int CLK = 5;//define pin
const int DIO = 4;//define pin
TM1637 tm1637(CLK, DIO);//define pin

boolean catIn = false;
boolean catOut = false;
float counterCatIn = 0;



void setup()
{
  Serial.begin(9600);
  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);

}
void loop()
{
  long RangeInCentimeters;
  RangeInCentimeters = ultrasonic.MeasureInInches(); // two measurements should keep an interval
  if (RangeInCentimeters < 20) {
    catIn = true;
    //Serial.println("cat in");
    delay(1000);
  } else {
    catOut = true;
    //Serial.println("cat out");
    delay(1000);
  }
  //counter
  if (catIn == true && catOut == true) {
    counterCatIn = counterCatIn + 0.5;
    Serial.println("your cat go in litter box");
    Serial.println(counterCatIn);
    tm1637.displayNum(counterCatIn);    
    delay(2000);

    delay(500);
    catIn = false;
    catOut = false;
  }
  //print

}

Credits

Shiyun Guan
1 project • 3 followers

Comments