system
March 11, 2012, 12:59pm
1
Hi,
I can build a simple sensor. It makes this:
when on the A0 is the voltage is turned off output 12 and turned on outut 13
when on the A1 is the voltage is turned off output 13 and turned on output 12
I made this code:
int floor1 = 12;
int floor2 = 13;
int vstup1 = A0;
int vstup2 = A1;
void setup () {
pinMode (floor1, OUTPUT);
pinMode (floor2, OUTPUT);
}
void loop () {
analogRead (vstup1);
digitalWrite (floor2, LOW);
digitalWrite (floor1, HIGH);
analogRead (vstup2);
digitalWrite (floor1, LOW);
digitalWrite (floor2, HIGH);
}
Is it right or wrong?
(sorry to my English, I used Google Translate.. :D)
kenny
March 11, 2012, 1:21pm
2
Very wrong!
Do something like:
If (analogRead(analogPin) > 50)
{
DiditalWrite(your_output,LOW);
}
Please use google because this is not the sort of question to ask, but rather the question to google.
These are the basics
system
March 11, 2012, 1:31pm
3
Is it now right?
int floor1 = 12;
int floor2 = 13;
int vstup1 = A0;
int vstup2 = A1;
void setup () {
pinMode (floor1, OUTPUT);
pinMode (floor2, OUTPUT);
}
void loop () {
if (analogRead(vstup1) > 50);
{
digitalWrite(floor2,LOW);
digitalWrite(floor1,HIGH);
}
if (analogRead(vstup2) > 50);
{
digitalWrite(floor1,LOW);
digitalWrite(floor2,HIGH);
}
}
kenny
March 11, 2012, 1:42pm
4
Your language translation is difficult to understand so i don't know what your trying to do
in one part you want to turn on something and in the next you want it off?
this is bad practice! something has to be master and not an "on but no now off" situation
could you try to explain again because i can't make sense of it
system
March 11, 2012, 1:56pm
5
I drawed two pictures. I trust, you understand.
From what I can gather the code looks OK and in line with the design brief.
However the design looks pretty dodgy, for example what happens if both vstup1 and vstup2 are > 50?
Rob
kenny
March 11, 2012, 2:10pm
9
They will switch on and off really fast so that's what you have to find out.
What do you want to happen and when do you want it
system
March 11, 2012, 2:23pm
10
I want use this circuit into the elevator. I want watch via Arduino where the cabin is. And I need program for watching that. It was idea what I post... no final program!
kenny
March 11, 2012, 2:28pm
11
Okay now i'm getting it
when one is is on, the other can never be on
well then it looks okay
kenny
March 11, 2012, 2:29pm
12
did you test it yet?
from there just see what you run in to
This is a problem:
if (analogRead(vstup1) > 50);
That semicolon should not be there
kenny
March 11, 2012, 2:35pm
14
That's a dumb one sorry lol
I corrected it in my post thanks
system
March 11, 2012, 2:40pm
15
It doesn´t work so if I want...
system
March 11, 2012, 3:06pm
16
Would someone help me with the program?
kenny
March 11, 2012, 3:15pm
17
Did you lose the semicolons?
then it shall work, only please change your wiring to something like the button tutorial
http://arduino.cc/it/Tutorial/Button
kenny
March 11, 2012, 3:18pm
18
the problem is that you remove the resistor and your readings will go up and down.
you have to pull it to ground if it's unconnected
system
March 11, 2012, 3:49pm
19
Circuit remains the same but the cable moves from 2 to A0?
kenny
March 11, 2012, 4:01pm
20
first you set A1 high and A2 to ground
then A2 high and A1 to ground
So for more floors you just connect all the not in use to ground and only the one you
need to the resistor and then to 5V