Simple sensor

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)

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

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);
}
}

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

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

I don´t know...

That's the bad practice

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

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!

Okay now i'm getting it

when one is is on, the other can never be on

well then it looks okay

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

That's a dumb one sorry lol

I corrected it in my post thanks :slight_smile:

It doesn´t work so if I want...

Would someone help me with the program?

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

:slight_smile:

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

Circuit remains the same but the cable moves from 2 to A0?

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