Automatic lighting control is an automation system present in some industrial sectors, projects that need adequate monitoring, and even in homes, among others. An example is in the lighting poles present in some cities, which turn on automatically when in the late afternoon, the sensor no longer detects the presence of sunlight close to the sensor.
For many automation projects involving Arduino UNO, the Light Dependent Resistor is used, whose principle of operation is the variation of its resistance, as it is exposed to the lighting of an environment, that is, the resistance of the LDR is inversely proportional to the lighting.
Thus, an application was developed in the case of the Didactic Robot Using the LDR Sensor, as shown in Figure 1.
Figure 1 - Case of the Didactic Robot Using the LDR Sensor.
With the development of this case of the Didactic Robot Using the LDR Sensor, you will learn both to assemble the basic circuit using the Arduino as in previous projects and to program it.
The Didactic Robot Using the implemented LDR Sensor has a simple structure, with the LDR sensor, 9 red Led's, 2 green Led's, 3 red Led's, 11 220Ω resistors, and one 10kΩ resistor.
The LDR sensor detects the presence of ambient light, and transmits the analog value through a voltage divider to the Arduino, which is responsible for processing the signal, and then activating the LEDs according to the variation of the light intensity. about the LDR.
In this article you will learn how to program the Arduino for this project and how to use the LDR sensor, this being an analog sensor with good accuracy.
Therefore, through this article you will learn:
- Know the structure of the Didactic Robot case using the LDR Sensor and the Analog LDR Sensor;
- Understand the operation of the Analog LDR Sensor well with the other devices in the case;
- Perform the Communication between the LDR Analog Sensor, the Led's, and the Arduino UNO;
- Couple the structure of the LDR Analog Sensor and other components to the didactic case developed.
- Earn 10 free NEXTPCB Arduino Compatible Boards.
Now, we will start the complete presentation of the development of the Didactic Robot Using the LDR Sensor.
Project Development Methodology
This project consists of presenting a didactic model of a robot using the LDR sensor with the UNO Arduino development board.
The project basically consists of the LDR sensor (which is a variable resistance device), responsible for detecting the presence of light in the environment, and through its housing, converting this light intensity into an analog signal, the Led's and the development board Arduino UNO, which will receive an analog signal sent by the sensor, supply the power so that the circuit can work and still process the received signals, as shown in Figure 2.
Figure 2 - Circuit proposed for the operation of the Didactic Robot Using the LDR Sensor.
The sensor detects the lighting in the environment through its housing and converts that luminous intensity into an analog voltage value, which is sent to the Arduino. Figure 3 illustrates the LDR schematic.
The LDR Sensor is basically constituted by a carcass of shape close to that of a cylinder trunk, however, flattened at two opposite ends, and two-three pins, responsible for the connection in the voltage and the 10kΩ resistor, being made at this point the divider of voltage responsible for the analog signal sent to the Arduino UNO.
According to its datasheet, the LDR has an inversely proportional relation to lighting, according to Figure 4.
Figure 4 - Resistance is a function of lighting.
Dessa maneira, é necessário captar o sinal analógico enviado por um dos pinos para o Arduino, para que possa ser convertido em um intervalo de 0 a 1023 (valor analógico).
Em seguida, é possível encontrar o valor de intensidade luminosa correspondente à iluminação captada pelo sensor e ser utilizado para configurar a lógica da programação desenvolvida.
A Figura 5 ilustra o Sensor LDR.
Figure 5 - LDR Sensor.
All communication of the Didactic Robot Using the LDR Sensor will be done through the sensor itself, which will send the information to the Arduino.
When the luminous intensity of the LDR sensor is above the programmed value, only the two lateral LEDs (green LEDs) will be lit, proportionally to the analog signal sent by the voltage divider connected to the LDR pin, because when increasing the luminosity, the lower it will be the resistance.
As the circuit at this point is composed of two 220Ω resistors in parallel, each connected to a Led, and another 10kΩ resistor connected to the GND.
When the light intensity over the LDR decreases, the electrical voltage over the resistor increases. Then, the LEDs are turned off.
To set up the experiment, first, make sure that your Arduino is turned off by disconnecting it from the USB cable.
Now, take the components and connect everything as shown in Figure 6 below.
Figure 6 - Wiring diagram for the proposed circuit.
According to the wiring diagram shown in Figure 6, the experiment consists of the LDR sensor circuit, the green LED circuit, the red LED circuit and the Arduino UNO circuit.
The circuit of the green LEDs with their respective 220 Ω resistors is responsible for visually detecting almost instantly the variation in light intensity on the LDR sensor.
When the light intensity on the LDR is reduced, the voltage on the LEDs decreases, causing them to have a reduced brightness.
In this way, the red LEDs will be triggered as the intensity of the analog value sent by the LDR pin comes close to the program value by the program on the Arduino, as shown in Figure 7.
Figure 7 - Variation in the light intensity of the LEDs through the LDR.
As the luminous intensity on the LDR decreases the brightness of the LEDs it will also decrease proportionally, as illustrated by Figure 8 when turning off the lights of the place where the circuit was mounted.
Figure 8 - Maximum intensity of red LEDs due to reduced intensity in the LDR.
All the programming logic of the Didactic Thermometer was developed as commented on the following program:
/* * ROBO DIDÁTICO UTILIZANDO O LDR E LEDS */ //************* INICIO - CONEXOES DOS LEDS**************************************** int pino_ldr = A0;// pino do ldr será conectado ao pino analogico A0 do Arduino UNO int luminosidade_ldr = 0;// variável utilizada para a leitura do pino do ldr. //pinos de controle para acionar os leds internos do robo. int pino_led1 = 2;// variável utilizada para definir o pino digital 2 int pino_led2 = 3;// variável utilizada para definir o pino digital 3 int pino_led3 = 4;// variável utilizada para definir o pino digital 4 int pino_led4 = 5;// variável utilizada para definir o pino digital 5 int pino_led5 = 6;// variável utilizada para definir o pino digital 6 int pino_led6 = 7;// variável utilizada para definir o pino digital 7 int pino_led7 = 8;// variável utilizada para definir o pino digital 8 int pino_led8 = 9;// variável utilizada para definir o pino digital 9 int pino_led9 = 10;// variável utilizada para definir o pino digital 10 //************* FIM - CONEXOES DOS LEDS**************************************** int controle_iluminacao_leds_interno = 440;//variável para especificar o limiar do valor analogico para acionar os leds internos do robô, //inicializada com um valor analogico de acordo com a iluminação do local proprio. void setup() { //******INICIO - definindo os ldes como saida************ pinMode(pino_ldr,INPUT);//definindo o led_sup_esquerdo como saida pinMode(pino_led1,OUTPUT); pinMode(pino_led2,OUTPUT); pinMode(pino_led3,OUTPUT); pinMode(pino_led4,OUTPUT); pinMode(pino_led5,OUTPUT); pinMode(pino_led6,OUTPUT); pinMode(pino_led7,OUTPUT); pinMode(pino_led8,OUTPUT); pinMode(pino_led9,OUTPUT); //******FIM - definindo os leds como saída************ Serial.begin(9600); //inicia a porta serial, configurando a taxa de transferência para 9600 bytes por segundo (bps) } void loop() { luminosidade_ldr = analogRead(pino_ldr);//lê o valor analogico de luminosidade enviado pelo ldr Serial.print("Luminosidade (valor analogico): ");//Escreve a mensagem inicial no monitor serial Serial.println(luminosidade_ldr);//Escreve no monitor serial o valor da luminosidade em valor analogico. //condição para acionar os leds internos do robô de acordo com a variavel controle_iluminacao_leds_interno. if(luminosidade_ldr<controle_iluminacao_leds_interno){ // aciona os leds internos do robo. digitalWrite(pino_led1,LOW); digitalWrite(pino_led2,LOW); digitalWrite(pino_led3,LOW); digitalWrite(pino_led4,LOW); digitalWrite(pino_led5,LOW); digitalWrite(pino_led6,LOW); digitalWrite(pino_led7,LOW); digitalWrite(pino_led8,LOW); digitalWrite(pino_led9,LOW); delay(100);//aguarda 100 ms para sair da condição } //condição contraria para acionar os leds internos do robô de acrodo com a variavel controle_iluminacao_leds_interno. else { digitalWrite(pino_led1,HIGH); digitalWrite(pino_led2,HIGH); digitalWrite(pino_led3,HIGH); digitalWrite(pino_led4,HIGH); digitalWrite(pino_led5,HIGH); digitalWrite(pino_led6,HIGH); digitalWrite(pino_led7,HIGH); digitalWrite(pino_led8,HIGH); digitalWrite(pino_led9,HIGH); delay(100); } }//FIM DO PROGRAMA
For this project, a specific case was developed, which will receive the LDR sensor, LCD display, and LEDs, as shown in Figure 9.
Figure 9 - Didactic Robot Case Using the LDR Sensor developed in Solid edge 2020.
From the assembly of the circuit and the programming of the used Arduino, it is possible to couple the LDR sensor in the upper region of the teaching case, as well as the two green LEDs, one on the right and one on the left.
The cover had no screw in its structure, as they were placed on the sides.
Figure 10 illustrates the connection of the LDR sensor, as well as one of the green LEDs, the other being connected to the opposite end.
Figure 10 - Connection of the LDR Sensor to the upper structure of the teaching case.
The red LEDs, which are located inside the didactic house, were coupled to a tower-like structure so that they could be stable inside.
Figure 11 illustrates the arrangement of the red LEDs, as well as their fixation structure.
Figure 11 - Internal structure for the connection of the red LEDs of the didactic case.
A differential of this case is that the structures of your face are in high relief so that they could have a greater prominence when they were made.
As they were modeled separately, they can be fixed to the front region using glue. Figure 12 illustrates this region in high relief.
Figure 12 - Structure of the case face in high relief.
The entire structure of the case was modeled to have a T-lock at several points, and its upper region was modeled to fit the second structure to which the LDR sensor will be attached.
The entire structure of the case was made to be coupled by fitting and in some points using the T-lock, with M3 screw, in order to guarantee better stability, as shown in Figure 13.
Figura 13 - Encaixes em T para os parafusos.
The rear region has a hole for the wires to exit the devices used.
The illustrative images of the Didactic Robot Using the LDR Sensor have some transparent regions in order to better understand the internal structure of the case, as shown in Figure 14.
Figure 14 - Internal structure of the case and the rear region for the wire outlet.
At the end of all modeling of the case structure, the rendered exploded perspective of the entire structure was made in order to better illustrate all the components of the circuit, as shown in Figure 15.
Figura 15 - Perspectiva explodida renderizada do Robô Didático Utilizando o Sensor LDR.
Conclusion
Therefore, from the development of this project, it was possible to know the structure of the LDR sensor, in addition to analyzing the communication of the sensor with the LEDs used in the project. With that, we conclude that the voltage variation on the green LEDs is inversely proportional to the luminous intensity on the LDR, which is a resistor with variable resistance.
In addition, it was observed the communication with the Arduino UNO through the developed program, and the response of the sensor in relation to the variation of the luminous intensity.
A BIG BONUS OF NEXTPCB
The NEXTPCB want offer 10 units of this Arduino compatible PCB for your projects in your first order with the link:Earn my PCBs Arduino Compatible.
Figure 16 - 2D View of the Printed Circuit Board.
Below is the 3D View of the NEXTPCB Arduino compatible Printed Circuit Board.
Figure 17 - 3D View of the Printed Circuit Board.