Hello to everyone
I need help, please.
I am a beginner with Arduino's programming so please forgive me for any mistakes I can say or do.
I made a small project with Arduino and the TLC5940 with the purpose of illuminating two different spaces at different times. The first is the garage with the relative path to get there, I used for this place 8 led spots, the second is the shed and its path and I used 6 led spots, in both cases the switching on and off of the single LEDs are progressive.
For lighting I used 2 pir sensors for each 1, 1 sensor LDR to exclude the switch daytime lights. I also added a switch that allows in case of need the cancellation of the sensor LDR and then get the lights with a continuous cycle. I made this project, and it works fairly well, the delays are not definitive and I thought 5 minutes of lighting before renewable turning off, maybe from another sensors, the delay of the sensor LDR too I do not know whether to give 5 or 10 minutes just to avoid the flickering of the operation.
As I said, some issues founded, such as when you turn on the 'LDR or pressing the switch to exclude it, sometimes part of a power cycle, also the setting of the' LDR seems to me not to respond adequately, also the whole system seems to me a bit 'slow.
I'll post the code and any suggestions to fix the anomalies are more than welcome.
Thanks in advance for any tips and help.
[code]#include "Tlc5940.h"
#define sensor_1 7 // sensore box
#define sensor_2 8 // sensore shed
#define button 5 // interruttore always
#define led 6 // led always on
#define led_LDR 2 // il pin 2 led ldr
const int sensorValue = 150; // setting LDR sensor
int x = 0; // sensor variable status
int always = 0; // switch variable status
void setup()
{
pinMode(led_LDR,OUTPUT);
pinMode(led,OUTPUT);
pinMode(sensor_1, INPUT);
pinMode(sensor_2, INPUT);
pinMode(button, INPUT);
Tlc.init();
}
void box()
{
for (int channel =5; channel >=0; channel --)
{
Tlc.set(channel, 4095);
Tlc.update();
delay(500);
}
delay(1000); // da modificare con 300000 = 5 minuti
for (int channel =5; channel >=0; channel --)
{
Tlc.set(channel, 0);
Tlc.update();
delay(500);
}
}
// ======= fine box ========
void shed()
{
for (int channel =0; channel <=7; channel ++)
{
Tlc.set(channel, 4095);
Tlc.update();
delay(500);
}
delay(1000); // modifica con 300000 = 5 minuti
for (int channel =0; channel <=7; channel ++)
{
Tlc.set(channel, 0);
Tlc.update();
delay(500);
}
}
// ======= fine shed ===========
void luminoso()
{
digitalRead(sensor_1)&& digitalRead(sensor_2) == LOW;
}
void buio()
{
x = digitalRead(sensor_1);
if ( x == HIGH) {
box();
}
x = digitalRead(sensor_2);
if ( x == HIGH) {
shed();
}
}
void loop(){
always = digitalRead(button);
if ( always == HIGH) {
digitalWrite(led, HIGH);
digitalWrite(led_LDR,LOW);
buio();
}
else {
digitalWrite(led, LOW);
int sensor = analogRead(A0);
if (sensor < sensorValue)
{
luminoso();
digitalWrite(led_LDR,LOW);
delay(2000); // attende 5 secondi
}
else {
buio();
digitalWrite(led_LDR,HIGH);
delay(2000); // attende 5 secondi
}
}
}
[/code]