Go Down

### Topic: Alarm - Connection (Read 688 times)previous topic - next topic

#### cave2596

##### Dec 02, 2012, 05:04 pm
Hello!

I haven't worked with the Arduino very much and I'm not good in programming.
My goal is, to build a alarm system, that reacts on movement/shock.
Therefore my Idea was to build a system simmilar to this example:
http://arduino.cc/en/Tutorial/Button
A plastic piece should fall out of the circuit(5V to pin 2)(simmilar to a button) and the Arduino should detect this.
So if the circuit is closed, the Arduino should make a sound for 5min (for example).
My problem is, that the sampleprogramm would detect a closed circuit, even if it isn't like this.

How can I programm the Arduino, that he only reacts in the case of a closed circuit?

#### PaulS

#1
##### Dec 02, 2012, 05:16 pm
Quote
My problem is, that the sampleprogramm would detect a closed circuit, even if it isn't like this.

Even if what wasn't like what?

Quote
How can I programm the Arduino, that he only reacts in the case of a closed circuit?

Wire the circuit correctly, first. Then, reading whether the pin is HIGH or LOW is trivial.

Quote
A plastic piece should fall out of the circuit(5V to pin 2)(simmilar to a button) and the Arduino should detect this.

Using the internal pullup resistor, and connecting a wire to a pin, to the device holding the plastic piece, and from the other side to ground, the plastic piece will prevent the connection from the pin to ground, so the pin will read HIGH. When the plastic piece falls out, and the pin to switch to ground is complete, the pin will read LOW.

#### cave2596

#2
##### Dec 02, 2012, 05:32 pm
Quote
Quote
My problem is, that the sampleprogramm would detect a closed circuit, even if it isn't like this.

Even if what wasn't like what?

If the circuit is closed, it says: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
If the circuit isn't closed, it says: 0,0,0,1,1,0,1,0,0,0,1,1,1,1,0,0,1,1,1,0,0,0,1

Quote
Quote
How can I programm the Arduino, that he only reacts in the case of a closed circuit?

Wire the circuit correctly, first. Then, reading whether the pin is HIGH or LOW is trivial.

Sorry, but how can I do this?

Quote
Quote
A plastic piece should fall out of the circuit(5V to pin 2)(simmilar to a button) and the Arduino should detect this.

Using the internal pullup resistor, and connecting a wire to a pin, to the device holding the plastic piece, and from the other side to ground, the plastic piece will prevent the connection from the pin to ground, so the pin will read HIGH. When the plastic piece falls out, and the pin to switch to ground is complete, the pin will read LOW.

Sorry, what?
I haven't worked with the Arduino very much.
I don' understand this.
Talk to me, like to an idiot.
Can you give me an example, please?

#### PaulS

#3
##### Dec 02, 2012, 06:01 pm
Quote
If the circuit is closed, it says: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
If the circuit isn't closed, it says: 0,0,0,1,1,0,1,0,0,0,1,1,1,1,0,0,1,1,1,0,0,0,1

What circuit? Quit waving your arms and post a schematic, a picture, or, at a minimum, a description of what is connected where. Post your code.

What you describe sounds like a floating pin condition, caused be lack of pullup or pulldown resistors.

Quote
Sorry, but how can I do this?

Quote
Can you give me an example, please?

I don't know what your circuit looks like. I'm assuming that your piece of plastic is holding a switch open, and that removing the plastic allows the switch to close.

If that is correct, then one end of the switch goes to a digital pin, and the other end goes to ground.

Then, in setup:
Code: [Select]
`pinMode(somePin, INPUT);digitalWrite(somePin, HIGH); // Turn on the pullup resistor`

Then, in loop:
Code: [Select]
`int state = digitalRead(somePin);if(state == LOW){   // The plastic piece is gone. Raise a squawk.}`

#### cave2596

#4
##### Dec 02, 2012, 06:26 pm
First of all, thank you!
Quote
What circuit? Quit waving your arms and post a schematic, a picture, or, at a minimum, a description of what is connected where. Post your code.

It is just a wire from 5v to pin2, which is interrupted by a plastic part.
If the plastic piece falls out, the wire isn't interrupted, so electricity can flow.
My code: http://arduino.cc/en/Tutorial/Button

Quote
I'm assuming that your piece of plastic is holding a switch open, and that removing the plastic allows the switch to close.

That's correct.

Quote
If that is correct, then one end of the switch goes to a digital pin, and the other end goes to ground.

Really?
One goes to 5v and one to pin2 (http://arduino.cc/en/Tutorial/Button)

Do I have to put the wire in another pin?
Can you give me a complete code, please?
And maybe a connecting instruction?

Thank you very much!

#### PaulS

#5
##### Dec 02, 2012, 07:04 pm
That sketch shows how to wire a switch with an external pulldown resistor. It is simpler to wire the switch using the internal pullup resistor.

Quote
It is just a wire from 5v to pin2, which is interrupted by a plastic part.
If the plastic piece falls out, the wire isn't interrupted, so electricity can flow.

Still have no idea what you are talking about. "just a wire" doesn't have any plastic pieces that can fall out.

Quote
And maybe a connecting instruction?

I don't know how much simpler it can get than "put one end of the switch in the digital pin and the other end in ground".

Now, it is your turn. Post a picture of this "just a wire" with "a plastic piece that falls out".

#### cave2596

#6
##### Dec 02, 2012, 08:20 pm
It should be simmilar to this:
https://www.dropbox.com/s/j8gr9bqsb9folax/Ausl%C3%B6ser_Alarm.JPG

And now I have to put the cables into pin2 and ground?!?

Would you be so kind, to send me the complete programm code?

Thank you very much!

#### PaulS

#7
##### Dec 02, 2012, 09:17 pm
Quote
And now I have to put the cables into pin2 and ground?!?

After setting pin 2 as input and turning on the internal pullup resistor, yes.

Quote
Would you be so kind, to send me the complete programm code?

If you send me some money. I've already spelled out everything you need to do. It's your turn to do something.