Creating a direction with RFID sensors

Hello, to begin sorry for my English, i'm from France.

I am a beginner in programation :confused:
I have a project with 3 firends to do which is very important for my studies.
My part in this project consists to make a program with 2 RFID sensors and 5 RFID tags that will detect if the subject enter or exit the room...

For the moment i am working with button (representing RFID sensors) and LEDS (representing the entry or exit) but the program doesn't work (the leds are going crazy in the simulator :o )
Here is the program :

" int ledPin1 = 5;
int ledPin2 = 6;

int bouton1 = 10;
int bouton2 = 11;
int compteur = 0;

int capteur1= 0;
int capteur2 = 0;
int sens = 0;

int entree = 0;
int sortie = 0;

void setup () {
pinMode(bouton1, INPUT);
pinMode(bouton2, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}

void loop () {

if (digitalRead(bouton1) == HIGH);
{
capteur1 = 1;
}
if (capteur1 = 1 && bouton2 == HIGH);
{
sens = entree;
}

if (digitalRead(bouton2) == HIGH);
{
capteur2 = 1;
}
if (capteur2 = 1 && bouton1 == HIGH);
{
sens = sortie;
}

if (sens = entree);
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
}
if (sens = sortie);
{
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin1, LOW);
}

if (sens = entree);
{
compteur = compteur+1;
}
if (sens = sortie);
{
compteur = compteur-1;
}
} "

If somebody could help me it would be appreciated, thanks.

First thing is that to do a comparison in an "if" you use == not =

 if (sens == entree)

Second, you can't have a ; on the "if", because that will prevent what't in the braces from running.

 if (sens = entree)
  {
    compteur = compteur+1;
  }

So both those mean your "if" should be

 if (sens == entree)
  {
    compteur = compteur+1;
  }

Thanks ardy_guy for the quick answer !
I have already corrected this thaks but the problem is with the "sens"
If you want i can make translation in my program for you.

Nobody can help me ? :confused:

Hi,
How have you got your buttons wired?

If they switch digital input to 5V, you need a 10K resistor between the digital input and gnd.

If they switch digital input to gnd, you need a 10K resistor between the digital input and 5V.

What model Arduino are you using.

Can you please post a copy of your test circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

NatCrazy54:
Nobody can help me ? :confused:

You haven't actually said what the problem is since you fixed the earlier problems.

Thanks for the answers,
I am actually not at home so tomorrow i will send the circuit i made :slight_smile:
I use a Arduino Uno card, and the problem is with the "sens" which mean direction..
The LEDs can't stop flashing :confused:
I have also a powerpoint which explain how do my program need to work.
Sorry for my bad skills in programation :o
Thanks again and i hope you could help me tomorrow :slight_smile:

I've been thinking about this and wonder if you shouldn't incorporate a third reader, called say "confirm" (or French equivalent :wink: )? Here's why: with 2 readers, if someone swipes to leave, then someone else immediately swipes to enter, that's the same sequence as someone leaving. The counter will decrement, but what you actually have is 2 different people in a sort of limbo, neither in nor out.

With 3, once you swipe to exit, listen only for confirmation, and ignore an entry swipe. Timeout if person changes their mind and doesn't confirm. Or if you get an enter, listen only for confirm and ignore an exit. Timeout if they change their mind.

Here's a state diagram for either solution. Have a look at my solution in another thread here in reply #10, and see how to use switch..case to sit in any state and await an action. From any state you explicitly move to another state once an action noted. Makes the coding pretty simple.

EDIT: I've coded a solution if you want it. Won't post it unless you ask: depends how much you want to try by yourself....

Wow thanks for the work you did to help me !
The problem is that for my project (that i make at school) i only have 2 sensors available :slightly_frowning_face:
It would be very appreciated to have some help from you if possible, can we talk by private messages ? I could send you my work then, thanks again.

My chart shows you can either use a 3rd sensor or not: 3 just makes it foolproof. With 2, you have to make sure that one person does his or her two swipes before someone going the other way does their first one otherwise you won't know what's going on.

But the coding would be the same except for the 2nd swipe being from the other direction sensor not the 3rd one.

Did you look at the code I linked in that other thread which may help?

NatCrazy54:
can we talk by private messages ? I could send you my work then.

No thanks.... keep it in the forum. First you get the benefit of others' input not just mine and Second I can't commit to replying in time (or even at all, for that matter).

I'd suggest you work off my other example I linked to, see how far you get.

Okay, so could you give me the program you made ?
I would make //explications at every line to try to understannd, and if i don't i would ask for some help..
Thanks for the help, it will really help me to improve my skills in coding :grinning:
I will try to make your program adapted for 2 sensors RFID.

NatCrazy54:
Okay, so could you give me the program you made ?

Attached.... Your Mileage May Vary :wink:

_463382_entry_exit.ino (4.35 KB)

Thanks a lot for the work you did !
I don't know it was this complicated to create a direction :confused:
I am trying to adapt it for 2 sensors, I really appreciate the help :slight_smile:

Hello !
So, i tried to adapt this programm for two sensors, and... It don't work :frowning:
I think that i am really useless at programming but i have to finish my project.. If somebody could help me doing it (also with maybe some explainations) i would be very gratefull, sorry for the disturbance.

2 sensor version attached.

About 3-4 lines changed, marked XXX.

It compiles but not tested since I don't have an Uno and switches and LEDs handy right now.

_463382_entry_exit_for_2_readers.ino (4.36 KB)

Wow thanks a lot for this fast answer :slight_smile:
I will test it tomorrow morning and tell you !

Hey !
Sorry, I am late..

I looked your program, it works fine ! But there is the main problem... How do we know that the character has entered or left the room ?
I think that I must make a "tempo" like :

If the first sensor has detected something, there is a cooldown, like in 10 seconds the tempo return to 0 until the second sensor has detected something.
And with that we can understand when the character enter or leave ! I hope you see what I mean...

My teacher also told me that only 2 leds are required.

But I still can't do it I did my best... I think I have to use millis.
I hope somebody could help me; it is very very important for me and I have only one month left to finismy prt of the project.

Thanks for reading my message, and maybe for the help ! Cordially.

Anybody could help me ?