Leah M
Published

Litterbox detector

Detects how often my cats use the litterbox and notifies me when it is ready to be cleaned

BeginnerFull instructions provided3 hours67
Litterbox detector

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
i2c Display Module 0.91 inch
×1
Jumper wires (generic)
Jumper wires (generic)
×11
Male/Female Jumper Wires
Male/Female Jumper Wires
×6
basic button
×1

Software apps and online services

Pushover

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Diagram

Red- Power
Dark blue- Ground
Green-Output pins
Pink/Purple-SCL/SDA

Code

Untitled file

C/C++
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#include "Particle.h"


SYSTEM_MODE(AUTOMATIC);
 

SerialLogHandler logHandler(LOG_LEVEL_INFO);

int sensorPin = 5; //A5     
int button = 4; //D4
int sensorInput = 0;     
int buttonInput = 0;
int threshold = 8.0;
double cur = 0.0;


void setup() {
  pinMode(sensorPin, INPUT);    
  pinMode(button, INPUT_PULLUP);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // 0x3C for 128x32
  
  Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    
  }
}


void loop() {
    
    sensorInput = digitalRead(sensorPin);
    buttonInput = digitalRead(button);
    
    if(sensorInput == HIGH){
        cur+=0.5;
        delay(5000);
    }
    
    if(cur==threshold){
        Particle.publish("push-notification", "Litterbox is dirty");
        delay(1000);
    }
    if(cur>threshold){
        Particle.publish("notification-reminder", "Make sure to clean the litterbox!");
    }
    if(cur >= threshold){
        display.clearDisplay();
        display.setTextColor(WHITE); 
        display.setTextSize(2); // Draw 2X-scale text
        display.setCursor(10, 0);
        display.println(F("Litterbox is dirty!"));
        display.display();   
        

    }
    
    if(cur < threshold){
        display.clearDisplay();
        display.setTextSize(2); // Draw 2X-scale text
        display.setTextColor(WHITE); 
         display.setCursor(10, 0);
         display.println(F("Litterbox is clean!"));
        display.display();   
    }
    
    if(buttonInput == LOW){
        cur = 0.0;
    }
    
}

Credits

Leah M
2 projects • 0 followers

Comments