Pages: [1]   Go Down
Author Topic: Alarm - Connection  (Read 370 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Thank you for your answers!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Using digitalRead().

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:
pinMode(somePin, INPUT);
digitalWrite(somePin, HIGH); // Turn on the pullup resistor

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

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How much money do you want?

Thank you for your answer!
You have helped me a lot.
Logged

Pages: [1]   Go Up
Jump to: