Hello all!
My hardware:
- 12v 10A power supply
- Arduino Mega 2560 R3
- x6 12v hydraulic pumps
- 8 relay module board
- Buttons, LCD, potentiometer (not important to current issue)
Please see my attached schematic, I reference it below.
Description:
I am creating a machine that uses 6 12v hydraulic pumps to pump liquid from a bottle into a glass. In order to control the pumps, I purchased an 8 relay control board that also runs on 12v. When both are connected to a 12v power supply, and the Mega board is connected to my laptop running the IDE code, one button controls drink type, while the other serves as a "select" button. Also in the machine is a 16x2 LCD display for information graphics.
Problem:
"Drink One" is navigated to and selected. The code tells the relay board to activate Relay 1 for 2 seconds, then Relay 2 for 1 second. However, both relays (only 1 and 2, none of the other 6) activate for 3 seconds, then turn off. I am unable to figure out how to get only one relay to activate at a time. In order to test if the problem was a coding error, I programmed only ONE Relay 1 to activate. Both were still connected, however only Relay 1 was supposed to activate. Both relays (1 and 2) activated for the desired time. The problem persists if I move the connections to two separate relays (1&7, 2&3, etc).
What I'm looking for help with:
I would like to know what the issue with my project is. I am not sure if my code is the culprit, or if I have a hardware/wiring issue. Also, the motor is not attached in the diagram because I do not know the proper way to wire it. It is not urgently important, because the relay board has built in LEDs that activate when the relay does. Thank you for your assistance.
Code information (please read):
- I am programming for two buttons, however I intend to switch to a rotary encoder once it comes in. This is why the two button names are odd
- The serial monitor is there for debugging, it can be removed
- I am not sure if this is the "right" code to use with relay boards
#include <LiquidCrystal.h>
const int pushyPin=53;
const int rotatePin=51;
const int motorPin=13;
const int motor2Pin=12;
int pushyState=0;
int rotateCurrentState=0;
int rotatePreviousState=0;
int rotateCounter=0;
LiquidCrystal lcd(23, 25, 27, 29, 33, 35);
void setup() {
Serial.begin(9600);
pinMode(pushyPin,INPUT);
pinMode(rotatePin,INPUT);
pinMode(motorPin,OUTPUT);
pinMode(motor2Pin,OUTPUT);
lcd.begin(16, 2);
lcd.print("BeerTender 9000");
}
void loop() {
// read the pushbutton input pin:
rotateCurrentState = digitalRead(rotatePin);
// compare the rotateCurrentState to its previous state
if (rotateCurrentState != rotatePreviousState) {
// if the state has changed, increment the counter
if (rotateCurrentState == HIGH) {
// if the current state is HIGH then the button went from off to on:
rotateCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(rotateCounter);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
rotatePreviousState = rotateCurrentState;
if (rotateCounter==1){
lcd.begin(16, 2);
lcd.print("Drink Uno");
pushyState=digitalRead(pushyPin);
if(pushyState==HIGH){
//If the switch has been pushed make the motor spin
digitalWrite(motorPin,HIGH);
delay(2000);
digitalWrite(motor2Pin,HIGH);
delay(1000);
digitalWrite(motorPin,LOW);
digitalWrite(motor2Pin,LOW);
}
}
if (rotateCounter==2){
lcd.begin(16, 2);
lcd.print("Drink Dos");
pushyState=digitalRead(pushyPin);
if(pushyState==HIGH){
//If the switch has been pushed make the motor spin
digitalWrite(motorPin,HIGH);
delay(1000);
digitalWrite(motor2Pin,HIGH);
delay(1000);
digitalWrite(motorPin,LOW);
digitalWrite(motor2Pin,LOW);
}
}
}
Thank you kind people!!!