In subway systems there a device that controls the passage of users out for in and vice versa. In these devices, there is a sensor that detects the proximity of the user of the turnstile.
When the user is closer to the turnstile is a need that he pass your card to access the subway system.
But in these systems, very times the user doesn't know that exists a sensor that allows the access when the user is closer to the turnstile.
Therefore, in this article, you'll learn how to implement a human-machine interface to better the change information with the subway users.
This project was developed thanks to the support of the PCBWay Company through the production of printed circuit boards for our projects.
The development of the ProjectFor developing this project, see Figure 1 and you'll understand how the circuit was developed. As is possible to see, the circuit is very simple. The button connected in the digital pin 8 is used to simulate the sensor that is in the machine and the other button that's connected in the digital pin 9 is used to simulate the process of passage of the card.
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7); //LiqyuidCrystal lcd(RS, EN, DB4, DB5, DB6, DB7)
#define PinoSensor 9
#define PinoCartao 8
bool sensor = 0, cartao = 0, controle = 0, EstadoSensor = 0, EstadoCartao = 0;
void setup()
{
for(byte pinos = 2; pinos < 8; pinos++)//Configuracao dos pinos do LCD como saida
{
pinMode(pinos, OUTPUT);
}
lcd.begin(16,2); //Inicializa o display de LCD 16 x 2
lcd.clear();//Limpa a tela do LCD
}
void loop()
{
// put your main code here, to run repeatedly:
sensor = digitalRead(PinoSensor);
cartao = digitalRead(PinoCartao);
delay(50);
if((sensor != EstadoSensor)||(cartao != EstadoCartao))
{
controle = 0;
}
if(sensor == 0 && cartao == 0 && controle == 0)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Metro-Silicios");
lcd.setCursor(6,1);
controle = 1;
}
if(sensor == 1 && cartao == 0 && controle == 0)
{
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Insira o seu");
lcd.setCursor(4,1);
lcd.print("Cartao!");
controle = 1;
}
if(sensor == 0 && cartao == 1 && controle == 0)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Aproxime-se da");
lcd.setCursor(4,1);
lcd.print("Catraca");
controle = 1;
}
if(sensor == 1 && cartao == 1 && controle == 0)
{
lcd.clear();
lcd.setCursor(5,0);
lcd.print("Catraca");
lcd.setCursor(4,1);
lcd.print("Liberada");
controle = 1;
}
EstadoSensor = sensor;
EstadoCartao = cartao;
}
At the beginning of the code, the status of the two buttons representing the proximity sensor of the user and the sensor that detects the passage of the card is read, as is possible see in the code presented below.
sensor = digitalRead(PinoSensor);
cartao = digitalRead(PinoCartao);
delay(50);
The "delay(50)" is used for debouncing via code. After this, we have a condition that will verify if occur alteration in the states of the sensor or card. For this, the condition will use the before states of the card and the sensor.
If the actual state of the sensor or actual state of the card is different from the before state, the variable "controle" it will be for zero.
This concept that uses the variable state "Controle" is used to allow that flow code to enter only one time in each condition to show the messages on the LCD 16 x 2.
Below, you can see the portion of the code that presents the commands.
if((sensor != EstadoSensor)||(cartao != EstadoCartao))
{
controle = 0;
}
Any change of card or sensor status will be detected and the value of the "control" variable will be changed.
To facilitate, we use a 16 x 2 LCD to improve communication between the user and the system. This will make it much easier for the user to use the machine.
To improve communication, 4 conditions have been created that can happen to the user when approaching and using the ratchet. And the 4 conditions are:
- Message on the LCD is not being used;
When the condition occurs, the block of commands is executed by the system.
if(sensor == 0 && cartao == 0 && controle == 0)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Metro-Silicios");
lcd.setCursor(6,1);
controle = 1;
}
And the message "Subway - Silicios" will be presented on the LCD 16 x 2.
- Message on the LCD when the user approaches the turnstile but does not pass the card;
When the condition occurs, the block of commands is executed.
if(sensor == 1 && cartao == 0 && controle == 0)
{
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Insira o seu");
lcd.setCursor(4,1);
lcd.print("Cartao!");
controle = 1;
}
- Message on the LCD when the user passes the card but does not approach the turnstile;
When the condition occurs, the block of commands below is executed.
if(sensor == 0 && cartao == 1 && controle == 0)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Aproxime-se da");
lcd.setCursor(4,1);
lcd.print("Catraca");
controle = 1;
}
- Message on the LCD when the user passes the card and is close to the turnstile.
When the condition occurs, the block of commands below is executed.
if(sensor == 1 && cartao == 1 && controle == 0)
{
lcd.clear();
lcd.setCursor(5,0);
lcd.print("Catraca");
lcd.setCursor(4,1);
lcd.print("Liberada");
controle = 1;
}
AcknowledgmentThanks to the PCBWay for support the our YouTube Channel and produce and assembly PCBs with better quality.
The Silícios Lab thanks UTSOURCE to offer the electronic components.
Comments
Please log in or sign up to comment.