DIY liquor dispenser shuts off half way sometimes

I am very new to arduino and coding in general. This is my first project and I feel like I might be overlooking something very simple. The way that the system works is that you push a momentary button which activates all of the pumps at the same time through a relay board. I decided to go with a relay board rather then a motor drive because it was less wiring and more related to what I know (I'm a heavy duty mechanic). After a short delay the first pump shuts off, and so on for the remaining pumps. All the pumps are peristaltic pumps.

The issue that I'm having is the odd time everything starts out perfect and all pumps turn on. After the delay time the WOR pump shuts off while the others keep running. However when its time for the VODKA pump to shut off both the vodka and the CLAM pump shut off at the same time. Its always this exact same scenario. I've tried changing times, I've tried swapping pumps and I've tried swapping where the pumps are on the relay board.

Im fairly certain that i should be able to fix it with the code. I appreciate any help. Thanks

const int CLAM = 5;
const int VODKA = 7;
const int WOR = 6;
const int BUTTON = 11;
boolean lastButton = LOW;

boolean currentButton = LOW;
boolean clamOn = false;
boolean vodkaOn = false;
boolean worOn = false;

void setup()
{

  pinMode (CLAM, OUTPUT);
  digitalWrite (CLAM, HIGH);
  pinMode (VODKA, OUTPUT);
  digitalWrite (VODKA, HIGH);
  pinMode (WOR, OUTPUT);
  digitalWrite (WOR, HIGH);
  pinMode (BUTTON, INPUT);
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(BUTTON);
  if (last != current)
  {
    delay(50);
    current = digitalRead(BUTTON);
  }
  return current;
}

void loop()

{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    digitalWrite(CLAM, LOW);
    digitalWrite(VODKA, LOW);
    digitalWrite(WOR, LOW);
    
    delay(1745);
    digitalWrite(WOR, HIGH);
    delay(3500);
    digitalWrite(VODKA, HIGH);
    delay(29555);
    digitalWrite(CLAM, HIGH);
  }
}

One leg of your pushbutton is connected to pin 11, what about the other leg? If it's connected to +5V, you need a 10k pulldown resistor connected from pin 11 to GND, so pin 11 is not "floating" and causing "ghost" presses when the button is NOT pressed.

DIY liquor dispenser shuts off half way sometimes

Clearly, you are in WAY over your head. Let me know where you live. I will come there and help you troubleshoot. I bet that within 10 or 15 cycles of dispensing liquor, we will not care how the machine behaves! :D

hdme: Im fairly certain that i should be able to fix it with the code. I appreciate any help. Thanks

My guess is that your Arduino is resetting and it is the digitalWrite()s in setup() that are shutting off the relays. That would happen if your relays are drawing too much current from the Arduino.

Post a diagram that shows clearly how you have everything connected. See this Simple Image Guide

Also put a Serial.print() statement in setup() so you can tell when it restarts. And / or a few LED flashes.

If you plan to extend that program you will almost certainly want to remove all those blocking delay()s. Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R

FredScuttle:
One leg of your pushbutton is connected to pin 11, what about the other leg? If it’s connected to +5V, you need a 10k pulldown resistor connected from pin 11 to GND, so pin 11 is not “floating” and causing “ghost” presses when the button is NOT pressed.

So for this what I did, because I wanted to cut down on wiring, I soldered a 10k resistor on the bottom side of the board from the 11pin to the ground pin. I did check to make sure with my multimeter that I had a good connection.

Robin2:
My guess is that your Arduino is resetting and it is the digitalWrite()s in setup() that are shutting off the relays. That would happen if your relays are drawing too much current from the Arduino.

How would I fix it if it is the digitalWrite() in the setup()? Sadly I had to do this because the relay board that I am using is activated with a low signal. Which was a problem because that meant that i had to put the motors on the normally closed side of the relay and if power was lost to the arduino or it faulted out, the pumps would just keep running. I also added the serial.print() function as suggested.

IMG_0868.jpg

IMG_0866.jpg

I should also note that in the code I change it pins for the motors to 2,3,4 to see if that helps that is why it is wired up on those pins.

I tried to make a diagram with one of the online programs but none of them had the relay board that I am using on file and it would have been way to time consuming to for me to try and make my own. I hope these picture are helpful. I know that I probably shouldn’t be using the breadboard wiring for this but later on i do plan on changing to a custom PCB

So this is my new code after taking Robin’s suggestions.

const int CLAM = 2;
const int VODKA = 4;
const int WOR = 3;
const int BUTTON = 11;
boolean lastButton = LOW;

boolean currentButton = LOW;
boolean clamOn = false;
boolean vodkaOn = false;
boolean worOn = false;

void setup()
{

  Serial.begin(9600);
  Serial.println("Caesar Machine");
  
  pinMode (CLAM, OUTPUT);
  digitalWrite (CLAM, HIGH);
  pinMode (VODKA, OUTPUT);
  digitalWrite (VODKA, HIGH);
  pinMode (WOR, OUTPUT);
  digitalWrite (WOR, HIGH);
  pinMode (BUTTON, INPUT);
  
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(BUTTON);
  if (last != current)
  {
    delay(50);
    current = digitalRead(BUTTON);
  }
  return current;
}

void loop()


{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {

    Serial.println("CLAM ON");
    digitalWrite(CLAM, LOW);

    Serial.println("VODKA ON");
    digitalWrite(VODKA, LOW);

    Serial.println("WOR ON");
    digitalWrite(WOR, LOW);
    
    delay(1745);
    Serial.println("WOR OFF");
    digitalWrite(WOR, HIGH);

    delay(3500);
    Serial.println("VODKA OFF");
    digitalWrite(VODKA, HIGH);

    delay(29555);
    Serial.println("CLAM OFF");
    digitalWrite(CLAM, HIGH);
  }
}

It definitely does look like you are right that it is restarting and faulting for some reason. After well over 100 times this is what I got on the monitor.

Screen Shot 2018-07-27 at 11.29.55 PM.png

After a couple of mess ups it started working perfectly again. Thought I would and a picture of one f the first times I tested it so you guys had a better idea of what it is too.

Proto.jpg

You seem to be drawing 5v power for the relays from the Arduino's 5v pin. Don't do that. Give the relays a separate power supply with a common GND with the Arduino. For testing try powering the relays from a pack of 3 x AA alkaline cells (4.5v).

If that does not work please make a simple drawing of all your connections - it will be much clearer (even a bad drawing) than photos of the wiring.

For the future please don't post pictures of text -it is unreadable. Just copy and paste the text.

...R PS ... overloading the Arduino may damage it.

Robin2:
You seem to be drawing 5v power for the relays from the Arduino’s 5v pin. Don’t do that. Give the relays a separate power supply with a common GND with the Arduino. For testing try powering the relays from a pack of 3 x AA alkaline cells (4.5v).

…R
PS … overloading the Arduino may damage it.

The 5v is strictly to power the coil of the relays would you say that’s still to much power draw for the arduino?

arduino.pdf (765 KB)

hdme: The 5v is strictly to power the coil of the relays would you say that's still to much power draw for the arduino?

Yes. I have been saying that since Reply #3

Here is a rough drawing of the wiring for the project.

You need to attach a PNG or JPG. See this Simple Image Guide

...R

Here it is again, I tried scanning it the first time.

You drawing is very hard to read - some of the writing is sideways and more of it is upside-down. And the lettering is tiny.

Also, make the image resolution smaller so the image does not take so long to load. 640 x 480 should be quite sufficient.

Assuming the long rectangular thing on the right is the relay board, why is it connected to the Arduino 3.3v pin?

What is the thing at the bottom-right that is connected to the 5v pin?

...R

I will make a new drawing when I get home. When I looked up the board it said that it would work with 3.3v or 5v so used the 3.3v and used the 5v for the button.

The button is what is connect to the 5v on the arduino.

The Arduino 3.3v pin can only supply a very small current.

It is better to connect a switch between an I/O pin and GND and use pinMode(pin, INPUT_PULLUP) as then there is no possibility of a damaging short circuit. It is also simpler.

...R

An Uno powered with 12volt (bad) can only power ONE relay coil (75-80mA) at the time. The Uno will reset after some time (overheating 5volt regulator) if two or more relays are activated.

The relay module should be powered with 5volt, not 3.3volt.

I would power the Uno with a 5volt cellphone charger, connected to the USB socket. That would provide enough power to activate four relays (max) at the same time, because it bypasses the onboard 5volt regulator. Power the pumps (nothing else) from 12volt.

The pumps MUST have a diode across, otherwise switching spikes could still reset the Arduino. Keep pump wiring clear of Arduino wiring. Leo..