Go Down

Topic: Creating a direction with RFID sensors (Read 560 times) previous topic - next topic

NatCrazy54

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

I am a beginner in programation  :smiley-confuse:
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.

ardy_guy

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

Code: [Select]

 if (sens == entree)


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

Code: [Select]

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


So both those mean your "if" should be

Code: [Select]

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


[irishAccent]Have you tried turning it off and on again?[/irishAccent]

NatCrazy54

#2
Mar 17, 2017, 11:41 am Last Edit: Mar 18, 2017, 11:54 am by NatCrazy54
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.

NatCrazy54


TomGeorge

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... :)
Everything runs on smoke, let the smoke out, it stops running....

ardy_guy

Nobody can help me ?  :smiley-confuse:
You haven't actually said what the problem is since you fixed the earlier problems.

[irishAccent]Have you tried turning it off and on again?[/irishAccent]

NatCrazy54

Thanks for the answers,
I am actually not at home so tomorrow i will send the circuit i made :)
I use a Arduino Uno card, and the problem is with the "sens" which mean direction..
The LEDs can't stop flashing :/
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 :)

ardy_guy

#7
Mar 19, 2017, 05:21 am Last Edit: Mar 19, 2017, 08:00 am by ardy_guy
I've been thinking about this and wonder if you shouldn't incorporate a third reader, called say "confirm" (or French equivalent ;) )? 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....
[irishAccent]Have you tried turning it off and on again?[/irishAccent]

NatCrazy54

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   :smiley-sad:
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.

ardy_guy

#9
Mar 20, 2017, 04:28 am Last Edit: Mar 20, 2017, 04:51 am by ardy_guy
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?

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.
[irishAccent]Have you tried turning it off and on again?[/irishAccent]

NatCrazy54

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  :smiley-lol:
I will try to make your program adapted for 2 sensors RFID.

ardy_guy

Okay, so could you give me the program you made ?
Attached....  Your Mileage May Vary ;)

[irishAccent]Have you tried turning it off and on again?[/irishAccent]

NatCrazy54

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

NatCrazy54

Hello !
So, i tried to adapt this programm for two sensors, and... It don't work  :(
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.

ardy_guy

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.
[irishAccent]Have you tried turning it off and on again?[/irishAccent]

Go Up