Hi everyone! I need help!
I finally managed to finish a sketch (I opened a topic called "How to merge several sketches") and everything worked perfectly. I decided to put the circuit back on a matrix board but once completed nothing worked anymore. I thought I made the connections wrong, so I rebuilt the circuit on a breadboard identical to the previous one, but nothing works. I noticed that on Arduino, once the sketch has been loaded, the Rx LED flashes for a few seconds and then the L LED stays on.
I haven't changed anything in the sketch and I don't understand why it stopped working
I know it's very messed up, I'm still new to programming, but the fact is it worked the way I wanted and now it doesn't work anymore
I had made a video of the working prototype in which I also framed the code, which is the one below. I rewrote it the same, 3 times the one that worked in the video.
I tried to connect one sensor at a time
I tried to change the jumpers
I tried 2 breadboards
I tried 3 different arduinos
In this sketch all sensor are powered by arduino correctly
I tried to upload verification sketches for each sensor and everything works
I have tried uninstalling and reinstalling all libraries
#include <Adafruit_NeoPixel.h>
#include <RTClib.h>
#include <Wire.h>
#include <DHT.h>
#include <DHT_U.h>
#include <easyRun.h>
#include <LiquidCrystal_I2C.h>
DHT dht(11, DHT11);
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27,16,2);
const byte modePin = 3; // wire : pin---btn---GND
button modeButton(modePin);
const uint32_t autoChangePeriod = 10000ul; // every 10s
enum : byte {LIGHT, SOIL, TEMPERATURE} mode = LIGHT;
#define LDR_PIN A0
#define USOIL A2
#define PIN 2 // input pin Neopixel is attached to
#define NUMPIXELS 24// number of neopixels in Ring
#define secondsSinceMidnight(h, m,s) (3600ul * (h) + 60ul * (m) + (s))
int light = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
uint32_t dayStart = secondsSinceMidnight(6, 0, 0); // 6:00:00 am
uint32_t dayEnd = secondsSinceMidnight(22, 0, 0); // 10:00:00 pm
void dieHere(const char * errorMessage) {
Serial.println(errorMessage);
while (true) yield();
}
void selectMode() {
static unsigned long lastChange = 0;
easyRun();
if (modeButton || (millis() - lastChange >= autoChangePeriod)) {
// need to switch to next mode (and do other stuff if needed upon transition)
for (int i = 0; i <NUMPIXELS; i ++) pixels.setPixelColor (i, pixels.Color (0,0,0)); // turn LEDs off
pixels.show ();
lastChange = millis ();
switch (mode) {
case LIGHT: mode = SOIL; break;
case SOIL: mode = TEMPERATURE; break;
case TEMPERATURE: mode = LIGHT; break;
}
}
}
void handleLight() {
light =analogRead(LDR_PIN);
Serial.println(light);
pixels.begin();
lcd.init();
lcd.backlight();
if (light < 700) {
for(int i=0;i<NUMPIXELS;i++)
pixels.setPixelColor(i, pixels.Color(0,255,0));
pixels.show();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Luce OK");
delay (100);
} else { for(int i=0;i<NUMPIXELS;i++)
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Luce no OK");
delay (100);
}
}
void handleSoil() {
int a = analogRead(USOIL); //sensore umiditĂ
if (a < 600) { //condizione per far partire neopixel con umiditĂ suolo
for(int i=0;i<NUMPIXELS;i++)
pixels.setPixelColor(i, pixels.Color(51,153,255));
pixels.show();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Acqua OK");
delay(100);
} else { for(int i=0;i<NUMPIXELS;i++)
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Acqua no OK");
delay (100);
}
}
void handleTemperature() {
dht.begin();
pixels.begin();
int t = dht.readTemperature();
if (t>=23 ) {
for(int i=0;i<NUMPIXELS;i++)
pixels.setPixelColor(i, pixels.Color(153,51,255)); // violet
pixels.show();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp OK");
delay (100);
} else { for(int i=0;i<NUMPIXELS;i++)
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp no OK");
delay (100);
}
}
void setup() {
Serial.begin(115200); Serial.println();
if (! rtc.begin()) dieHere("Couldn't find RTC");
if (! rtc.isrunning()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // careful will be the time when you compiled the sketch
}
void loop () {
selectMode ();
DateTime now = rtc.now ();
uint32_t sNow = secondsSinceMidnight (now.hour (), now.minute (), now.second ());
if ((sNow >= dayStart) && (sNow <= dayEnd)) {
switch (mode) {
case LIGHT: handleLight (); break;
case SOIL : handleSoil (); break;
case TEMPERATURE: handleTemperature (); break;
}
}
}