Hi to everybody,
I'm working with an Arduino MkR wifi 1010 and MkR IoT Carrier. In particular I'm preparing a smart garden project and so, I connected a waterpump to one of the two relay of the carrier in NO mode. In addition I'm using also a moisture sensor.
I tried to leave the arduino+carrier for days connected to the power in order to monitor some quantities (light, temperature, moisture, humitidy, etc..) and I left the waterpump OFF for all the time. However, I noticed that after some times (maybe after one day), for some inexplicable reason, the object (arduino+carrier) reset itself and so, also all the relays (making the classic sounds CLIC-CLAC), as if it had lost the supply. In principle it is not a big problem, however it becomes a problem with the waterpump, because resetting itself (turning itself ON and OFF for some seconds), it gives water. And it's a problem if I connected all the system to a plant. It did it a couple of times. Has someone known something about this? Is it normal?
I don't think is a "software" problem, but I attach here the skecth of code:
#include "thingProperties.h"
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
String waterPumpState;
String lightState;
int moistPin = A5;
int wateringTimeInSeconds=5000;
int t = 0;
int dry = 1023;
int wet = 0;
uint32_t lightsOn = carrier.leds.Color(82, 118, 115);
uint32_t lightsOff = carrier.leds.Color(0, 0, 0);
//_______
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
//while (!Serial);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
//Wait to get cloud connection to init the carrier
while (ArduinoCloud.connected() != 1) {
ArduinoCloud.update();
delay(500);
}
CARRIER_CASE = true;
carrier.begin();
carrier.display.setRotation(0);
delay(500);
carrier.Relay2.close();
waterPumpState = "PUMP: OFF";
updateScreen();
delay(1500);
}
//_______
void loop() {
ArduinoCloud.update();
//Serial.print("### Waterpump: ");
//Serial.println(waterpump);
if (waterpump == false){
t = 0;
carrier.Relay2.close();
}
//Update touch buttons
carrier.Buttons.update();
//function to print out values
if (carrier.Buttons.onTouchDown(TOUCH0)) {
printInfo();
}
if (carrier.Buttons.onTouchDown(TOUCH1)) {
printInfoRelays();
}
//read temperature and humidity
temperature = carrier.Env.readTemperature();
humidity = carrier.Env.readHumidity();
//read raw moisture value
int raw_moisture = analogRead(moistPin);
//map raw moisture to a scale of 0 - 100
moisture = map(raw_moisture, wet, dry, 100, 0);
//read ambient light
while (!carrier.Light.colorAvailable()) {
delay(5);
}
int none;
carrier.Light.readColor(none, none, none, light);
if (waterpump == true) {
carrier.Relay2.open();
if (t == 0){
waterPumpState = "PUMP: ON";
updateScreen();
}
t = t + 1000;
}
if (t >= wateringTimeInSeconds){
waterpump = false;
waterPumpState = "PUMP: OFF";
updateScreen();
}
delay(1000);
}
//_______
void onArtificialLightChange() {
if (light_state == true) {
carrier.leds.fill(lightsOn, 0, 5);
carrier.leds.show();
lightState = "LIGHTS: ON";
} else {
carrier.leds.fill(lightsOff, 0, 5);
carrier.leds.show();
lightState = "LIGHTS: OFF";
}
updateScreen();
}
//Update displayed Info
void printInfo(){
carrier.display.fillScreen(ST77XX_BLACK);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(2);
carrier.display.setCursor(40, 60);
carrier.display.print("Water: ");
carrier.display.print(moisture);
carrier.display.println("%");
carrier.display.setCursor(40, 80);
carrier.display.print("T: ");
carrier.display.print(temperature);
carrier.display.println("C");
carrier.display.setCursor(40, 100);
carrier.display.print("Hum: ");
carrier.display.print(humidity);
carrier.display.println("%");
}
//_______
void printInfoRelays(){
carrier.display.fillScreen(ST77XX_BLACK);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(3);
carrier.display.setCursor(40, 50);
carrier.display.print(waterPumpState);
carrier.display.setCursor(40, 90);
carrier.display.print(lightState);
}
//Update carrier screen
void updateScreen(){
printInfoRelays();
}
Thanks a lot in advance.
Lorenzo
