Skip to content

Arduino Project: Access Granted Indicator

In the age of classic cameras and darkrooms, photography involved developing images in light-proof rooms using chemical mixtures. To ensure successful image development, preventing light from entering the darkroom was crucial. This project involves developing an electronic circuit to control the operation of two LEDs, indicating the darkroom’s availability.

Assignment

In this DIY guide, we will create an Arduino-controlled LED indicator to show whether the darkroom is occupied. A red LED will light up when the darkroom is busy, and a green LED will light up when it is free. The LEDs will be controlled via commands sent from a computer through the Arduino Serial Monitor.

Only one LED lights up at any time.

Required components

  • Arduino UNO
  • Two LEDs (red and green)
  • Two 220Ω resistors

Electrical scheme

Arduino Access Controll Indicator Electrical Scheme
Arduino Access Controll Indicator Wiring Diagram

Program (sketch)

const int diode[] = {4, 5}; 
const int perioda[] = {500, 1000, 1500, 2000};
int indexPeriode = 0;
int indexDiode = -1;
int duzinaNiza;
String komanda;

void setup() {
Serial.begin(9600);
duzinaNiza = sizeof(perioda) / sizeof(int) - 1;
for(int i=0; i<2; i++) {
pinMode(diode[i], OUTPUT);
digitalWrite(diode[i], LOW);
}
}

void loop() {
diodaTreperi(indexDiode);
}

void diodaTreperi(int d) {
digitalWrite(diode[d], HIGH);
delay(perioda[indexPeriode]);
digitalWrite(diode[d], LOW);
delay(perioda[indexPeriode]);
}

void serialEvent() {
komanda = Serial.readString();
komanda.trim();

if(komanda.equals("#CRVENA") || komanda.equals("#crvena")) {
indexDiode = 0;
}
else if(komanda.equals("#ZELENA") || komanda.equals("#zelena")) {
indexDiode = 1;
}
else if(komanda.equals("#UVECAJ") || komanda.equals("#uvecaj")) {
if(indexPeriode < duzinaNiza) indexPeriode++;
}
else if(komanda.equals("#SMANJI") || komanda.equals("#smanji")) {
if(indexPeriode > 0) indexPeriode--;
} else {
Serial.println("Nepoznata komanda, nema promene stanja programa");
}
}

The LEDs are connected to digital pins 4 and 5, which is defined in the program by an array “leds”.

The period during which the LEDs blink is also defined by an “period” array with the values 500, 1000, 1500 and 2000. These values represent the time interval that the LEDs are on and off expressed in milliseconds.

The period index is an auxiliary variable that enables selection of the appropriate value for the period during which the diode will blink.

Simple access control indicator – Arduino based project

Declaration of variables

The diodes are connected to digital pins 4 and 5, which is defined in the program as an array diode whose values are 4 and 5. The period during which the diodes blink is also defined by a sequence with the values 500, 1000, 1500 and 2000. These values represent the time interval that the diode is on and off expressed in milliseconds. Variable indexPeriode is initialized to 0 so that its value points to the first element of the array perioda. This allows the flickering period to be 500 milliseconds when the diode is turned on, which is defined by the task. Another variable indexDiode has an initial value of -1, in order to ensure that at the beginning of the program no diode lights up. String length is a helper variable used to determine the length of a string perioda, to provide logical control for array manipulation.

Setup function

Setup the function is simple and in its body is placed the initialization of the serial connection between the Arduino and the computer, in the for loop it is set that the pins from the array diode work in output mode, and the diodes are initially off.

Loop function

In loop function there is only one line that calls the function diodaTreperi with a parameter representing the index of the diode in the array diode which should be turned on.

User function – diodaTreperi

As already said function diodaTreperi has one parameter (the index of the diode to be turned on) and enables the diode flickering effect. A particular diode will be on/off as determined by the rows digitalWrite(diode[d], HIGH/LOW). The flicker period is done by reading the corresponding value from the array perioda as follows – delay(perioda[indexPeriode]);

Function – SerialEvent

The most important part of the program is contained in the function serialEvent. This function is executed at the end of each iteration loop functions when there is data written in the serial buffer of the Arduino. It enables the loading of commands sent from the computer and that #crvena, #zelena, #uvecaj и #smanji. Other user entries will be ignored and a corresponding message will be printed. In this function, it is determined which diode will be turned on, which is determined by the commands #crvena, #zelena. By command #crvena the value of the variable indexDiode is set to the value 0, that is, with the command #zelena is set to the value 1. In addition, the period of blinking of the diodes is determined by commands #uvecaj and #smanji. These commands increment or decrement the value of a variable indexPeriode and have a logical control that its value cannot be less than 0 and greater than the value of the variable duzineNiza.

Leave a Reply

Your email address will not be published. Required fields are marked *