Simple alarm

Hey There…

I would like to build a simple alarm for my motorcycle, and all i could find by search was some advanced projects including GSM and more.

I would like to use 2 or 3 mercury switches, but i want the alarm to give people a heads up about the alarm, and then if they still touches… the alarm to go off.

I have no problem with the eletronics parts, but the logic in the programing is causing trouble.

attached is a diag, that shows how i would like the arduino to think ::slight_smile:

Martin - Denmark

What have you tried? Do you have a circuit built? How many switches are there and to which pins are they connected? How are the switches connected? Such questions need answered before you can write your code. What does the beeper need? A logic signal or a tone? Which Arduino do you want to use?

I'd be interested to see how you've setup your mercury switches. I've thought about this in the past and the concept I came up with was a freely hanging pendulum with the tilt switch that becomes locked once the alarm is set.

I've just never worked out quite how to lock/unlock that pivot point.

Ken, couldn't you latch it in software? I mean once activated, set the state to true and ignore the tilt switch until reset by the owner or a timeout. That way someone can't just cut the wires to disable the switch.

groundfungus: Ken, couldn't you latch it in software? I mean once activated, set the state to true and ignore the tilt switch until reset by the owner or a timeout. That way someone can't just cut the wires to disable the switch.

Good point. You only have to detect a CHANGE of state to determine that it is being moved!

Why did I never think of this :)

Hi again.

I havent built anything yet, cause i would like to have the code ready and build it on a breadboard first.

Im using a Arduino Nano, and since nothing is built, im free to use any pins. as a fact, i only need 1 mercury switch !!

I havent bought the beeper, so im free on that point to.

My real big problem is the sense once, delay and if still motion set off the alarm coding.

oh.. and i would like it in a way that if 1 pin is HIGH, then do nothing (Alarm off when ignition)

We are not here to write code for you. Have you installed the Arduino IDE? There is example code in the IDE. File, Examples, Digital has code for reading switches [buttons]. Also the Playground on the Arduino site has lots of example code and how to wire different things. Use the examples to write some code and if you have trouble post the code and we will help to get it to do what you want.

That said I will start with how to wire a switch (see attached). The digital input will read HIGH when the switch is open and LOW when closed, The cap will help to suppress false activations due to switch bounce. A tilt switch is probably closed (LOW) when sitting still and open (HIGH) when tilted.

Use the millis() function to time your events (blink without delay example). Read the switch, if it is LOW do nothing. If it has gone HIGH (state change detection example) record the value of millis() into a variable, say tiltTime = millis(). Then each time through loop() check to see if your target time has elapsed and act accordingly (if(millis() - tiltTime > 3000) do something; will do something after 3 seconds).

Break up your project into bite size pieces and learn the parts then you can put the pieces together into a complete program. So learn to wire and program for switches, then learn to use millis() for timing. Once you understand the parts it is easier to build the whole.

And lastly, is you bike electrical system 12 volts? If so, do not connect anything from the bike system directly to your Arduino. You must use something like a voltage divider to get the voltage to what your Arduino can safely accept.

There's a bit of a problem with your logic. If we were to read your remit litterally.

First trigger will cause warning beep.

Another trigger within say, 30 seconds, will cause the alarm.

In reality, there's always going to be a second signal. If you disturb a mercury switch, you'll find it next to impossible to just cause one switching event. It's going to go on/off/on/off a few times as the mercury slops around inside.

Even if you could get around this issue, what happens if someone knocks it once, then again 2 seconds later. Should the second bump trigger the main alarm? should it reset the 30 second counter? This really needs thinking through pretty carefully.

Thanks...

As first said, i have no problems with the electrical part of the project, so i do know how to hook things up.

I allready built several arduino projects before including a complete aqaurium computer with OLED display and relays controlling all the lights in different timezones.. and a GPS speedo for the bike.

I just had problems with the delay part of this code.. but i will try my way instead off asking.

Thanks again.

Good luck. I had no way of knowing the level of your expertise so assumed, by the nature your question, that you had less experience. If I wasted your time, I apologize.