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);
}
- Can you guys give me some feedback on how to stop the fake messages that are being generated due to the oscillations?
- 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!
8 posts - 4 participants