Problem with Relays

Hi to everybody. I have a Oplà Kit and I wanted to make a smart garden with a waterpump. I already done the code and I think is fine (I have also checked with the code already done in the manual on "https://opla.arduino.cc/opla/module/iot-starter-kit-maker/lesson/06-smart-garden"). It's not very clear to me how to connect the waterpump to the Mkr IoT Carrier. If I understood right on the carrier there are already present 2 power supplies for the relays.. so in principle from the waterpump i should go directly to the mkr carrier, right? Anyway i'm doing something wrong.. can someone help me?
thanks in advance,
cheers,
Lorenzo

Well this is almost impossible to answer. I cannot see your code although there are some nice pictures. Your link was useless and your schematic with all the connections ett shown and not a frizzy thing is great. More information is needed.

Hi,
I'd like to connect a waterpump to my mkr iot carrier and an Arduino mkr wifi 1010 (from Arduino Oplà Kit). However is not very clear to my how to do the connection with the relays on the carrier. My waterpump has 2 cables (fig 1 attached), can I go directly to the holes in the carrier? And if yes.. where I should put them? There are three holes: NC, COM and NO. If I want waterpump ON, should I use the NO and COM holes?

I put here also the code that I'm using:

#include "thingProperties.h"
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;

int moistPin = A5;
int dry = 1023;
int wet = 700;

String waterPumpState;

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);
 //Get Cloud Info/errors , 0 (only errors) up to 4
 setDebugMessageLevel(2);
 ArduinoCloud.printDebugInfo();

 //Wait to get cloud connection to init the carrier
 while (ArduinoCloud.connected() != 1) {
   ArduinoCloud.update();
   delay(500);
 }
 delay(500);
 CARRIER_CASE = false;
 carrier.begin();
 carrier.display.setRotation(0);
 delay(1500);
}
void loop() {
 ArduinoCloud.update();
 // Your code here
 uint8_t r, g, b;
 control_RGB.getValue().getRGB(r, g, b);
 
 //read temperature and humidity
 temperature = carrier.Env.readTemperature();
 humidity = carrier.Env.readHumidity();

 //read raw moisture value
 int raw_moisture = analogRead(moistPin);
 Serial.print("Moisture (raw): ");
 Serial.print(raw_moisture);


 //map raw moisture to a scale of 0 - 100
 moisture = map(raw_moisture, wet, 1023, 100, 0);
 Serial.print("Moisture: ");
 Serial.print(moisture);
 Serial.println("%");
 
 if (moisture < 10){
   lightsOn();
 }
 else{
   lightsOff();
 }
 //read ambient light
 while (!carrier.Light.colorAvailable()) {
   delay(5);
 }
 int none; //We dont need RGB colors
 carrier.Light.readColor(none, none, none, light);
 delay(1000);
}
void onWaterpumpChange() {
 if (waterpump == true) {
   carrier.Relay2.open();
   waterPumpState = "PUMP: ON";
 } else {
   carrier.Relay2.close();
   waterPumpState = "PUMP: OFF";
 }
 updateScreen();
}


void lightsOn() {
 uint8_t r, g, b;
 control_RGB.getValue().getRGB(r, g, b);
 carrier.leds.setPixelColor(0, 0, 255, 0);
 carrier.leds.setPixelColor(1, 0, 255, 0);
 carrier.leds.setPixelColor(2, 0, 255, 0);
 carrier.leds.setPixelColor(3, 0, 255, 0);
 carrier.leds.setPixelColor(4, 0, 255, 0);
 carrier.leds.show();
 updateScreen();
}
void lightsOff() {
 carrier.leds.setPixelColor(0, 255, 0, 0);
 carrier.leds.setPixelColor(1, 255, 0, 0);
 carrier.leds.setPixelColor(2, 255, 0, 0);
 carrier.leds.setPixelColor(3, 255, 0, 0);
 carrier.leds.setPixelColor(4, 255, 0, 0);
 carrier.leds.show();
 updateScreen();
}
//Update displayed Info
void updateScreen() {
 carrier.display.fillScreen(ST77XX_BLACK);
 carrier.display.setTextColor(ST77XX_WHITE);
 carrier.display.setTextSize(2);
 carrier.display.setCursor(40, 50);
 carrier.display.print("Mois: ");
 carrier.display.print(moisture);
 carrier.display.print("%");
 carrier.display.print(waterPumpState);
}

I'm writing this message because I've never worked with relays. Anyway.. I think i got my mistake: on the mkr iot carrier there are 2 relays but not the battery (24V) to give voltage to the waterpump. So If I understood right I should make a circuit with battery, the waterpump and the relay on the carrier. Right?

Thanks again,
Lorenzo

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
https://forum.arduino.cc/index.php?topic=712198.0
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

You appear to be cross-posting.

You will need to control that pump with a relay or MOSFET as the controller cannot provide the current that it needs.

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom... :slight_smile:

lorenzoscavarda,
I have merged your 2 topics on the same subject. Please do not cross post, it wastes the time of people trying to help you and is therefore against the forum rules.

Please read How to get the best out of this forum - General Electronics - Arduino Forum before you make any more posts.

Thank you.

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original posts (not re-post them) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you later need to post that) from the IDE and click the icon.

In fact, the IDE itself has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. While you were lucky so far, If you do not post it as "code" it can easily be quite garbled and is generally more difficult to read due to the font.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper; yours is not. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only ever single blanks between complete functional blocks.

Why do we think this is more important than just having your question answered? Because it is really difficult to write code properly - as with any other task requiring care - if everything is not well organised!

TomGeorge:
Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
How to get the best out of this forum - Introductory Tutorials - Arduino Forum
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

You appear to be cross-posting.

You will need to control that pump with a relay or MOSFET as the controller cannot provide the current that it needs.

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom... :slight_smile:

Hi,
I'm sorry for the mess of this post. I read now the instruction and i have modified my "second" post (I will remove the first one). Anyway.. I'm physics researcher skilled in particle detectors. I work mainly in the data analysis so I code a lot (mainly c++ and python). With the electronics I don't have big experience and in particular with the relays, for this reason I created this post. Now, reading my new restyled post can you help me?
Thanks,
Lorenzo

Paul__B:
OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original posts (not re-post them) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you later need to post that) from the IDE and click the icon.

In fact, the IDE itself has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. While you were lucky so far, If you do not post it as "code" it can easily be quite garbled and is generally more difficult to read due to the font.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper; yours is not. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only ever single blanks between complete functional blocks.

Why do we think this is more important than just having your question answered? Because it is really difficult to write code properly - as with any other task requiring care - if everything is not well organised!

Hi,
thank you for your informations. I read the instructions and I restyled my post. Is it fine now? and.. could you help me with my questions?
thanks,
Lorenzo

I don't see any power going to your pumps

A relay is just a switch - it does not provide any power

I think you need to provide power to the pumps - what is the voltage required by the pump?

Keep in mind also that most (maybe all) Arduino boards don't have enough energy to drive a pump -

You will probably require an outside power supply of the proper voltage and current rating

Also the start current of a motor is higher than the running current - so the power supply will need to be larger than the pump(s) running current totals

saildude:
I don't see any power going to your pumps

A relay is just a switch - it does not provide any power

I think you need to provide power to the pumps - what is the voltage required by the pump?

Keep in mind also that most (maybe all) Arduino boards don't have enough energy to drive a pump -

You will probably require an outside power supply of the proper voltage and current rating

Also the start current of a motor is higher than the running current - so the power supply will need to be larger than the pump(s) running current totals

Yes, you are right. I studied better the problem and relays and I understood that it needs the power. The pump should work with a DC voltage of 3-5V. So I thought to use a battery of 4.5V. What do you think? Should be fine?

Yes 4.5 volts should be fine, they also have more power than the smaller ones.
Be sure to check if pumps in the right direction, if not change + and -.
(I assume your pump is rotation direction-sensitive)
Best Regards,
Johi.

JOHI:
Yes 4.5 volts should be fine, they also have more power than the smaller ones.
Be sure to check if pumps in the right direction, if not change + and -.
(I assume your pump is rotation direction-sensitive)
Best Regards,
Johi.

thanks for your answer. Yes should be "direction-sensiste".. but I suppose that the black cable is the negative pole and the red one the positive.. should be easy!
Thanks again,
Lorenzo

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