Problem resetting relays in MkR IoT Carrier

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

I would like You to post the schematics and links to data sheet of the various things You have connected to the controller. I'm not familiar with the names You tell in the post.
Whenever relays are involved the question about kick back diodes comes up. Relaymodules usually have that.
Any weakness in powering is one possible question...

Thanks a lot for your answer. Yes, I attach here the schematics of the circuit that I implemented (it's very simple), the datasheet of MkR IoT carrier and the schematics of the carrier. Moreover I upload also the datasheet of the Arduino wifi 1010

Thanks a lot for your help.
Lorenzo


schematics.pdf (3.6 MB)
MKR IoT Carrier - Datasheet.pdf (889.8 KB)
Arduino wifi 1010-datasheet.pdf (779.7 KB)

That waterpump needs a kick back diode. Is that Duracell a 9 volt PP3 battery? If so, use something giving more current. 6 x 1.5 volt AA could work.

Sorry my inexperience, what do you mean with "kick back diode"?
The Duracell that I'm using is a battery of 4.5V. I'm using this because when I bought the waterpump on amazon I read that the DC Voltage required was 5V.
If the problem was the Duracell battery why the MkR Carrier resets? Because I think that the problem is that for some reason (that I don't understand) the Arduino turns off and on in some seconds and thus also the carrier, but during the resetting process the carrier turns on and then turns off again the relays.

Thanks again,
Lorenzo

I don't "mean" anything. It's a technical term. Another name is "free wheel diode".
All inductive loads create bad sparcs, or over voltage, when they are turned off. Those diodes suppresses that. Those sparcs easily tricks electronics to go wrong, like a reset, or even get damaged.
5 volt pump powered by that 4.5 volt battery is ok. But, do some Google on those diodes and connect one.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.