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
Program (sketch)
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.
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.