If by "normal jumpers" you mean plug in connections then, assuming that you have got the circuit wired correctly, then these connections re likely to be the cause of the problem
Move your project to the box in stages and test each component as you add it
yes, I mean plug-in connections. Now I proceed to test the connections as you suggest. The thing I don't explain is why, by loading other sketches with the same sensors and the same connections, everything works perfectly
Is the installation in the box meant to be permanent ? If so, then you really need too move away from plug in single jumper connections as they are not reliable
Yes, the installation in the box is final, in fact I was thinking of soldering the cables directly to Arduino. However I wanted to proceed with this step once everything works
I tried to connect these sensors to arduino
RTC
LED
LDR
BUTTON
It does not work.
I tried to upload a sketch to test led and ldr and everything works perfectly.
At this point I think the problem is the sketch
I think that we need to revisit the schematic of your project. Usually I am quite tolerant of Fritzing diagrams, but a real schematic, even if only hand drawn and photographed is much better. For instance, some of the pin labels on the shield are obscured by the wires so I don't know what they are
Is the code that you are using still the same as you posted in your original post ? It uses NeoPixels but there is no sign of them in the Fritzing drawing
I'll immediately post a photo of the handmade circuit.
On Fritzing I couldn't find the neopixel ring I have, so I didn't insert it. In any case it has only 3 pins = GND VCC DATA IN
The sketch is always the same.
I tried to draw as best I could. If there are links of different colors that intersect, of course I don't mean that they are linked. I inserted a legend hoping to improve the reading
Thank you for posting that, it is clearer than the Fritzing picture
You have a lot going on in the sketch and the circuit but if teh sketch works sometimes and not others the problem is not in teh sketch.
I am still suspicious of the connections, whether the circuit is on the breadboard or not. I am still suspicious of your plug/socket connections and that is reinforced by the fact that it has never worked when moved to the box and sometimes fails when outside of the box
As it stands all you know is that sometimes the project does not work. I suggest that you add Serial.print()s at strategic points in the sketch to show you what it is doing. In order to test the program flow. If you insert
Serial.println(__FUNCTION__);
at the start of each function then the name of the function will be printed each time the function is called. Does the program flow look correct or does it stall somewhere ?
Thank you so much for the help you are giving me.
I have already tried to insert serial.prints in the whole sketch but it doesn't print anything. The only thing that appears on the serial monitor is the error "Cannot find RTC" which occurs only if the RTC is not connected.
For the rest, when the sketch does not work, no messages are output on the serial monitor.
When the sketch works instead, after 5 seconds that Arduino is connected, the neopixel LEDs light up and the LDR values start to appear on the serial monitor.
I try to verify by entering the serial.print you told me.
The thing that I can't explain, however, is why the same sensors, with other sketches, work perfectly.
Also, even when it's on the breadboard it doesn't work. After 1-2 days, however, everything works.
Is that the case even when it is working or only when it isn't working ?
Only when it isn't working.
One thing that might be useful to know is that on Arduino, when the sketch does not work, the LED L lights up and remains fixed. On the other hand, when the sketch works, the L LED flashes and then the Rx LED lights up too, which flashes very quickly.
Another thing is that when I try to load the sketch on Arduino the IDE sometimes tells me that access to the COM7 port is not allowed because it is busy.
Restarting the PC this error disappears.
But when the sketch worked, I tried to reload several times on Arduino to add more code and it never gave me the error
I took the DHT11 to be one of those where the actual DHT11 is mounted on a small PC which has the resistor built in. My reason for assuming this is that the DHT11 on the diagram is shown as having 3 pins rather than 4
@edoardo7152 how many pins are there on the DHT11 module ?
As I wrote below the post, if there are cables of different colors touching each other, this is not the case in reality.
That black cable came out longer, sorry.
Yes, right!
The DHT11 and LDR are mounted on breakout boards, have built-in resistors
Important update.
Yesterday I tried to insert Serial.print (__ FUNCTION__);
At the beginning of each function.
Serial monitor printed "Cannot find RTC"
"Die Here"
And so far everything is right. I left everything still and went to sleep, this morning I tried to connect the RTC and open the serial monitor and I saw that it was printing "Select mode" and "loop" all the time.
I then connected:
LCD, BUTTON, LDR, LED to do a quick test and ... everything works.
If the hardware and sketch work sometimes and not others then you have to ask yourself what has changed between the 2 states
But that's what I don't understand ... I don't touch anything anymore and when I try again the next day, it works
So you leave the project powered up at all times and never touch it between tests on different days ? How is the project powered by the way ?
Does the environment change in any way. Hotter/colder more/less humid ?
Do you always test it at the same time of day or is it sometimes lighter/darker day/night ?
If you are using the Serial monitor then the project is obviously connected to a PC. Do you ever upload the code when the project is not working and it works afterwards or maybe vice versa ?
Do you always connect using the same USB port and USB lead and are the same other components (mouse, keyboard etc) always plugged in when you test it ?
Have you measured the voltage on your project power lines ? Are they always correct and are they consistent ?
Have you put a print statement in setup() so that you know that the code is actually starting ? Maybe blink an LED using the BlinkWithoutDelay technique in loop() so that you can tell whether the code is actually running