i've been working with tilt sensor module SW-520D, in some tutorials, the sensor's position must be placed on a horizontal position, but when i upload my code, it gives me unstable data, so i try to set the module in vertical position but turns out it keeps reading 1 (no matter i change the position of the module or give it a shake), it should be 0 right when there's change of orientation?
so i try again, but the output now is always turning 0, i place the sensor as flat as possible, but it never read digital 1 anymore no matter the position. i adjust the sensitivity by rotating the potentiometer but no effect.
could it be that the sensor is not precise? or maybe my sensor module is broken?
yes, yes
The delay(1000) in your code causes you to miss 1000 opportunities to catch the pulse every second
As the pulse of the tilt sensor can be short (depends on its internals) you might need an interrupt routine to catch its pulse. Check attachInterrupt examples.
Yes. But first, just remove the delay. The device shouldn't make such fast pulses as to need interrupts - it is two small balls that make continuous contact at certain angles.
So lose the delay and slowly move the sensor pointing it in every direction to discover where it turns on.
As I read about the sensor itself, I can't explain why the module would need a sensitivity control; the sensor is a switch and could just as well be attached directly to an input pin in the manner of a regular pushbutton.
If you have the skill, you could try removing the sensor and using it in that way. I suppose it is possible that the sensor itself is bad, but if the module is bad it seems more likely to be some other failure.
and if I used one, would probably just use traditional switch handling or, as you say, a small capacitor. Or both.
It's odd they refer to it as a vibration sensor. There is a similar package ih which find themselves a spring and a probe. It is open in all orientations after it settles; sufficient vibration causes it to present briefly as closed.
While even in this case I don't see a legitimate need for any other circuitry or module, it may be that interrupts have a place for grabbing very brief events.