Cat door informer

Hello All. A Arduino newbie here.
I made a cat door informer. My plan is simple.

I installed an accelerometer ( ADXL335 ) on the cat door. ( Please see diagram at the very bottom of this post ).
If a cat goes through the door, the accelerometers' x or y or z axis changes in value.

When there is a change in the x or y or z value, I told the Serial Monitor to inform me that a cat went through the door.

When the cat door is fully closed, My serial monitor was telling me that:
x = 274
y = 341
z = 338

Everytime a cat goes through the door, the serial monitor is telling me that:
x = 274
y = 341
z = 352 ( Maximum value)

As we can see, the z-axis is changing from 338 to 352.

So I went ahead and changed my sketch a little and told the sketch that if the z value is greater than 348, then the Serial Monitor needs to print A cat just came in!

I chose 348 in my if statement because the maximum 'z' value that I am seeing is 352. The body of the cat doesn't seem to be big enough to make the 'z' value go higher than 352. So I figured that I want the 'trigger' to be at around 348.

In a normal situation, the cat goes through the door, then the sketch notices that the z axis value is greater than 348 and spits out the message in the serial terminal that a cat went through. Life is good.

Here is the issue:
When the cat is done going through the door, the door keeps oscillating!
This is messing things up for me.
This oscillations are making the z value go from 344 to 350 and then back to 344 to 349 etc etc.
Everytime the cat door oscillates such that the z value is greater than 348, the serial monitor is spitting out a false message that a cat just went through!

This oscillation is creating a 'fake' serial terminal message that says that a cat just went through when it is just the door that is oscillating!

Ideally, once the z value is higher than 348 I want the serial monitor to tell me just once, that the cat came in.
I dont want the extra "A cat just came in" fake messages which are being generated due to the oscillations of the door around the threshold value of 348.

( This will be an issue going forward, because I want to have a buzzer in this system and I don't want the buzzer going off due to the oscillations. i just want one buzz when the cat comes in.)

Here is my sketch:

#include "ADXL335.h"
ADXL335 accelerometer;

void setup() {
  Serial.begin(9600);
  accelerometer.begin();
}

void loop() {
  int x, y, z;
  accelerometer.getXYZ(&x, &y, &z);
  Serial.println("value of X/Y/Z: ");

  Serial.println(x);
  Serial.println(y);
  Serial.println(z);

  if (z > 348)
  {
    Serial.println("A cat just came in! " );
  }
  delay(3000);
}
  1. Can you guys give me some feedback on how to stop the fake messages that are being generated due to the oscillations?
  2. I am willing to replace the project with any other sensor. I choose an accelerometer just cause it was lying around.

Ty for the replies!

One approach would be to put a damper of some sort on the door, so it doesn't oscillate so vigorously. A second would be to start a timer to ignore oscillations after the first trigger. Determine the best timer period by experiment.

Welcome to measurements in the real world!

Thank you. Can you please guide me on how to start a timer to ignore oscillations after the first trigger?
Do you know of an example sketch that I could follow?
Ty

To start a timer, record the current value of millis(), and ignore the door until the timer expires.

The Blink Without Delay example program shows one way to proceed, but there are others, like setting a "flag" variable to signal that the door should be ignored.

You could do the same thing with a tilt switch.  Just sayin'.

Appreciate the feedback.
That might help.
Cause a tilt switch is a 0 or 1 output.

Mind you, you'll still have to debounce it.

Perhaps use a cat door with an embedded magnet that has a mating magnet at the bottom of the opening. The two magnets allow the cat in/out, but door will not swing further than completely closing.

I have a cat flap , connected as follows.

I have two Reed switches , one outside and one inside in the frame below the door ,the normal magnet on the flap
Is enough to trigger those .
Just connect those to digital inputs . First one to trigger tells you the direction .
When the first trigger occurs , ignore any others for a set period .
You still get issues where the cat looks through the flap and then doesn’t go out .
Some raw data :

01 is IN , 10 is out , these are the signals from the reed switches .


02/08/2024 23:34:39,0,0,I/O:()                  
02/08/2024 23:35:08,1,0,I/O:()                  
02/08/2024 23:35:10,0,0,I/O:()                  
02/09/2024 01:12:02,0,1,I/O:()                  
02/09/2024 01:12:03,0,0,I/O:()                  
02/09/2024 02:49:03,1,0,I/O:()                  
02/09/2024 02:49:04,0,0,I/O:()                  
02/09/2024 02:49:11,1,0,I/O:()                  
02

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.