Led Matrix and Water pump with Relay problem

Hello, this is my first post here so I hope I got the right category since I have more than one problem.

I wanted to build a circuit that waters a plant via a water pump (3-6V) with a relay, a soil moisture sensor, an ultrasonic that helps me measure how much water is there left, a temperature module sensor (KY 028, I've programmed it to show the approximative room temperature) and I wanted to print all of these sensors' information on a led matrix display ( MAX7219 8x8 with 4 devices). Also, I have an arduino uno R3 CH340.

Without the led matrix, the whole circuit and code works fine, but it makes some of the sensors pointless because they're of no use if I can't see the values, and on its own with some sensors (meaning no water pump and relay, just the led matrix and some sensors) it also works fine, so none of the components are broken.
Now, enter the problem: when I put all of the components together, the led matrix has all LEDs on and just flickers as the relay switches on and off.

To counter this problem I've tried connecting a 9V battery to the pump and relay, but to no avail, the led matrix display ..well, displays the same problem, all LEDs on and flickers as the relay switches. To top it off, last time I've tried to upload the code with the led matrix display attached, I've also got an avrdude error. I have checked possible troubleshooting methods online (no wires on pins 0 or 1, drivers work well since I've uploaded code that works well on the arduino multiple times, though I haven't tried uploading the code with Programmer AVR ISP while I had the led matrix display on, I was afraid I'd burn it if I tried more than I already had)

avrdude: stk500_paged_load(): (a) protocol error, expect=0x14, resp=0x1c
avrdude: stk500_cmd(): programmer is out of sync
avr_read(): error reading address 0x0000
    read operation not supported for memory "flash"
avrdude: failed to read all of flash memory, rc=-2
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0xf4
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0xf4

Is there anything I can do to make the led matrix print what I want it to?
Also, note worthy, I don't posses any other components other than the ones in the scheme I have attached aside from another led matrix display, but with only one device. And I don't think it's a code issue either, maybe electrical one, but I'll also attach the code anyway. If I cut all led matrix display lines and leave the last block uncommented, the code works just fine.

Code:

//ultrasonic
int trigPin = 11;
int echoPin = 12;

//matrice led 
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN   9
#define DATA_PIN  10
#define CS_PIN    8
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);


// pompa apa + moisture sensor
int ACWATERPUMP = 13;
int sensor = A0;
int valUmid = 0;

//modul temperatura
int tempPin = A1;
int analogTempVal = 0;

void setup() {
  //ultrasonic
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  //pompa apa
  pinMode(ACWATERPUMP, OUTPUT);

  //matrice
  P.begin();
  Serial.begin(9600);

}

void loop() {
  //for debug purposes, to not have the pump spraying water while I fix the led matrix
  digitalWrite(ACWATERPUMP, HIGH);
  delay(500);

  //ultrasonic
  long duration, distance; 
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  
  if (distance >= 3900 ) {
    Serial.println("Out of range");
    } 
    else {
      Serial.print(distance);
      Serial.println(" cm");
      }
     delay(500);


     
  //masurare temp
  analogTempVal = analogRead(tempPin);
  //Serial.println(analogTempVal);
  int trueTemp = 0;
  trueTemp = (analogTempVal*4-400-23*25)/(-25);
  Serial.println(trueTemp);
  delay(500);
  P.print("temp: ");
  P.print(trueTemp);
  delay(500);
  
  
//  //if moisture value over 450, turn on pump
//  valUmid = analogRead(sensor);
//  //Serial.println(valUmid);
//  if(valUmid > 450)
//  {
//    digitalWrite(ACWATERPUMP, LOW);
//  }
//  else
//  {
//    digitalWrite(ACWATERPUMP, HIGH);
//  }
//  delay(400);


}

The 5V pin of the Arduino board is for sensors, or a (very) few leds.
You may not use it for a motor or a led display.

1 Like

Hi~
Motor and Relay the Power don't form arduino.

Hi,
Welcome to the forum.

You cannot power all that hardware from the 5V pin of the UNO, it is not designed for that amount of current.

A 9v "smokedetector battery" is even worse.

You should for the experiment power your hardware off a 3 x 1.5V AA battery pack.
4.5V should be enough for them all.

Can you please post a link to a specs/data for your pump?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:
PS, A hand drawn circuit with component and pin lables would be better than a Fritzy picture.

1 Like

Hello, Tom, thank you for the detailed answer.

The place where I've bought the pump only provided this video and in the video there's this amazon link, hope it's useful: Water pump video , Water Pump Specs

Also, I have a question, I powered the circuit by usb and afaik arduino provides 5V and you mentioned powering the circuit by 3x 1.5V AA batteries which provide 4.5V, wouldn't that be the same thing? Sorry if it's a dumb question, I'm not familiar with this.

I also have a 6 battery holder with arduino power jack (if that's the right term) and some 1.2V batteries, would that be enough if I just plug that 6 pack of 1.2V in the arduino?

Hello, Koepel, thank you for the answer.

What should I use to power it instead? I have powered it by USB so far and that 9V battery attached.

Is it enough if I plug in the arduino itself a 6 pack battery holder of 1.2V or 1.5V each battery?

The voltage regulator on the Arduino board for 5V is not that strong. You have to power the leds and the motor and maybe also the relay from something else.

When you use a 5V power supply or three AA batteries, then you can power the motor and everything else directly from that. The Arduino board can be powered with 5V via the 5V pin or via the USB connector.

Using the 5V pin to power the Arduino board has a few consequences. Current could flow into the computer via the USB cable.

1 Like

Thank you for the answer!

It wasn't clear from this, but would it be alright if I used a 6x battery holder with 6x 1.5V batteries in it plugged into the power barrel of the arduino? I don't have a 4 battery holder.

Then I'd also have to upload the code and plug in the usb into the board, but from some research online I've read that arduino disables the current coming in from the pc if it's receiving current from other parts. Is this also okay?

You are missing the point. This isn't about voltage, it's about power, The Arduino can control your devices but it cannot provide enough power to drive them, whatever you plug into the barrel jack.

Arduino needs power and the motor and the display and probably the relay coils need power from another source, not through the Arduino.

Indeed, one of the reasons for having the relay is to make it simple to provide separate power to the motor but still turn it on and off from the Arduino.

1 Like

And what is there to do in this case? Sorry, I am not familiar with this and it's my first project.

If I remove the led matrix altogheter would there still be problems? From running it a few times, it doesn't seem like there'd be problems, but I ve only ran the program with the components no more than a few minutes at a time

Basically, you need two power supplies. Koepel described it for you in reply #7.

That I have understood, but I am not sure if a 9V battery for the relay + pump and a 6 pack of 1.5V batteries plugged in the arduino board consist of two different power supplies, based from your responses, I believe not... Is it correct?

That sounds like two. Forget the LED display for now. Write something that turns the relay on for 10 seconds and then turns it off. Connect the 9V power to the motor via the relay and get that working.

I suspect that the 9V battery will not last very long.

I'll remove the led matrix then for now. I have written code that turns the relay on via the soil humidity sensor and that seems to work well and doesn't cause problems, at least in the short term.

Not last long as in being drained or the circuit being faulty (without the led matrix) ?

As mentioned, if that 9V battery is a smoke detector battery, they are next to useless for anything that needs power. They provide very little current and have limited capacity so a motor will run it flat quickly.

AAs are much better. Check what voltage your motor needs and put enough AAs together to provide it.

1 Like

Let's get this straight.

The clear blunder is not comprehending what the "Vin" or "RAW" terminal is. The regulator on the Arduino UNO/ Nano/ Pro Mini/ Mega2560/ Leonardo/ Pro Micro has very little heatsink, so will not pass very much current (depending on the input voltage and thus, how much voltage it has to drop) before it overheats and (hopefully reversibly) shuts down. It is essentially little more than a novelty provided in the very beginning of the Arduino project when "9V" power packs were common and this was a practical way to power a lone Arduino board for initial demonstration purposes. And even then it was limited because an unloaded 9 V transformer-rectifier-capacitor supply would generally provide over 12 V which the regulator could barely handle.

Nowadays, 5 V regulated switchmode packs are arguably the most readily available in the form of "Phone chargers" and switchmode "buck" regulators to regulate down from 12 V or other available voltages are cheap on eBay so these can be fed into the USB connector or (more appropriately) 5 V pin to provide adequate power for most applications. Unfortunately, many tutorials or "instructables" are seriously outdated or misleading and have not been updated to reflect the contemporary situation.

If powering directly from batteries, as long as the battery pack cannot exceed 5.5 V, this must be connected to the 5 V pin.

In your case, it seems nothing requires a 9 V supply, so do not use a 9 V supply of any sort and do not use the "barrel jack" or "Vin" pin. Use a 5 V supply, connect it to your 5 V devices and the Arduino via the "5V" pin (and of course, the ground).

The only concern with a UNO is that you should not connect a power supply to the "5V" pin when you have it plugged in to a PC via USB so just disconnect that pin only. A 4.5 V battery (three alkaline "AA") will generally approximate the 5 V for the pump and MAX7219.

your schematic must have protection diode for motor and for relay.
you can replace them with LED for period of development.
Or power them separated, i.e. from battery or accumulator. GND and signal to relay must be connected to ardu.

Sounds like @pierse02 Is trying to build this project from the parts they already have, which probably came from a starter kit. Probably few or none of the parts are going to be suitable or the best choice for any final project, and that's certainly true in this case I suspect. Starting with the Uno itself, which is only really a suitable Arduino if you have a "shield" you want to use with it (a "shield" is a circuit board the same shape and size as Uno, and plugs directly on top of the Uno). If you don't have a shield, an Uno is, at best, an inconvenient form factor. Uno is also a poor choice for any battery powered project.

So I suspect this will be a journey of discovery, where you find out the shortcomings of each of the components you have and gradually replace them.

If battery power is what you want, I would recommend 4xAA NiMH rechargeables, which will should give you close enough to 5V and enough of current for your pump. If you haven't got a NiMh charger, it's about time you stopped buying non-rechargeables and started thinking about the planet!

Which is why the UNO is really a poor choice to be put in starter kits, unless they include a number of the shields!

A Nano and one or two breadboards, and/ or a "terminal adapter" would be a far better starter kit.