hey everyone, so i'm a high schooler building a project for a national innovation comp. and we guys want to use the tilt sensor as a trigger mechanism. is there anyone who can give us an example of a suitable code
Not without knowing what tilt sensor that you are talking about. They range from a simple switch to a 3 axis accelerometer with gyro. Post a data sheet for the sensor.
So, in other words, is your question one of the following?
- Can anybody suggest a tilt sensor for a HS project? And tell us how to use it?
- I have this tilt sensor, but I don't know how to use it--anybody?
- Can somebody, please, design a tilt sensor based project that we can enter into this competition -- we promise to take full credit (don't want it getting out that we didn't do the work ;))
If 1, then please describe your project so we have some parameters to work with.
If 2, then please supply more info about the sensor, so we know what you're talking about.
If 3, well...more than likely you can get help on particular aspects of a project you create -- but, I doubt if anyone is going to do the whole thing for you. So, give us what we need to help you with that tilt sensor [see #s 1 and 2, above], then if more issues come up, ask your question in a new thread
And, BTW: probably a good idea to read: How To Use This Forum Otherwise you'll, likely, end up annoying people -- see, most of us are busy, and we need you to meet us halfway, so we don't have to pull teeth to get the info we need to help you
@ReverseEMF, Karma++
Probably be easier to use an accelerometer than a 'true' tilt sensor' (vs ie: bearing rolling inside of a tube)..
with all the debouncing and false positives... might be easier to check an axis on the accelerometer and call it a day?
How about this:
- open your favourite web browser.
- open the home page of your favourite search engine.
- in the search bar, type the part number of your specific sensor, then add the words "Arduino example"
- click on the Search button.
- follow the links that come out.
In my opinion, this is easier by making your own tilt sensor using a circle wire and a pendulum. I made plenty of these to demonstrate how a robot can sense its position in space. Kids education project :-). No need for any electronics (except the LED circuit).
Edit: just noticed falexandru opened a year-old thread, and that OP only had the one post and is unlikely to busy with their camp. But whatever, I'll leave my comments here, might help someone else.
I would be very inclined to code it so that whatever your tilt sensor mechanism is (you didn't say) and whatever it triggers (you didn't say) it stays triggered until a different, human-operated, switch resets things.
So if a tilt occurs and the tilt switch changes state (open to closed or closed to open depending on the physical layout) and turns on a warning light or a siren, the warning should stay on even if the tilt switch changes state back again. Reason I say that is it may be important that the tilt occurred, and you the human need to check for damage even if the thing you're monitoring (and you didn't say what it is) is back upright.
I'd go with a boolean flag called say oopsWeHadATilt, initialised false, and set true when a tilt occurs. As long as the flag is true, the lights light and the siren sires. The untilting of the thing and the change of sensor back again is ignored. The flag is only set false again by a human pressing a button once the thing has been inspected.