everything is working properly until I put 12v power to the pumps

Hi there, so I’m building some kind of vending machine with my Arduino
…When a user puts coins in coinAcceptor he gets credit
then when he pushes the button a timer is start counting and one of the pumps is start working
Every button has different price. If the user want to switch from one pump to another he has to press a PuseButton which when he press it the timer is paused and the code the credit is calculated and the balance is displayed on the display… then she user press the next button and the timer is starting to count again depending from the balance and so on. until the credit is =0

Now …this everything is working properly until I put 12v power to the pumps… then the credit is messed up.

When I put 12v power to the pumps trough the relay the coinAcceptor is working properly (it counts coins correctly) the user presses first button the timer is start to count correctly until the user presses PauseButton… then the credit for like a split of a second is shown OK on the display but then the number is messed Up like instead of subtracting it is adding up credit like crazy… if I cut the power to the pums it starts to work ok again… so I don’t think that is the code… must be something with my connections.
but I don’t know what is it.

I try to connect all the grounds together but no result… I try to separate 5v gnd from 12v gnd but still no result…I remove the 12v to 5v convertor and power the arduino with 12v still no result.

my parts are
Arduino Mega
i2c display
coinAcceptor CH-926
8ch relay (5v)
8 pumps (12v 0,8mA)
5 push buttons
12 power supplay (100w 8,5A)
12v to 5v convertor

Please help because I try every thing

Images from Original Post so we don't have to download them. See this Simple Image Posting Guide

...R

My very wild guess is that the pumps are overloading the power supply and causing the voltage to drop. That could be because the pumps have a high inrush current when they start or it could be that there is a bad connection somewhere.

What happens if you disconnect all but one pump from the system?

...R

thank you but
I just try this... I disconnected all the other pumps I leave just one pump... still no result
I change the power supply 12v 3A with one pump no result again :slightly_frowning_face:

Do you have snubber diodes on your pumps?

I don't know what that is.. here is what I have
I'm not much into electronics .. I'm a logic persion hobbiest :slight_smile:

this is the pump

this is the relay

I don't see any mention of the motor current in the Bangood link. It would be useful to run a pump directly off the 12v supply and measure the current while it is pumping.

...R

I just meassure … 0.33mA

Very unlikely. Did you mean 0.33 Amperes?

jremington:
Very unlikely. Did you mean 0.33 Amperes?

yes… sorry 330mA

here is another link of the pump

tanjamaya:
I don’t know what that is… here is what I have

Take a look at this.

tanjamaya:
yes... sorry 330mA

A motor that draws 330mA when running could easily draw 2 or 3 amps (or more) when stalled and for a brief period at startup. Pumps, especially, present a high startup load on the motor.

...R

Hi gues...first of all thank you for your effort to help me
now... I think that I find what is the problem but jet I didn't solve it :frowning:
its not hardware its the code I'm sure.. but I dont know how to solve it
here is what code I'm using

const byte coinValues[4] = {
  10, 20, 50, 100}; //Coin values goes into this array ... Ove vrednosti gi dele so 10 za a ja dobie pravata vrenost na parata
#define pulseTimeout 200        //How many milliseconds there are from the last impulse to the coin is determined (default 275)
#define actionTimeout 60000     //How many milliseconds before stored credit is reset (default 60000)
#define pinCoinSignal 3          //Pin za signalot od coinAcceptorot belata zica

unsigned long lastAction = 0;   //When last action was made
unsigned long lastPulse = 0;    //When last pulse was send
int pulseCount = 0;             //How many pulses we got
int currentCredit;              //The current credit

void showCredit()
{
  int credit = currentCredit/10;
  int left = currentCredit % (currentCredit/10);
  
  Serial.print("Current credit: ");
  Serial.print(credit, DEC);
  Serial.print(".");
  Serial.print(left, DEC);
  Serial.println("0");
}

void setup()
{
  Serial.begin(115200);

  attachInterrupt(0, acceptorCount, RISING); //Digital interrupt pin 1
  attachInterrupt(1, acceptorPulse, RISING); //Digital interrupt pin 2

  Serial.println("Coin Acceptor ready");
  pulseCount = 0;

   pinMode(pinCoinSignal, INPUT_PULLUP);
}

unsigned long tempAction;
unsigned long tempPulse;

void loop()
{
  tempAction = lastAction;
  tempPulse = lastPulse;
  
  if (millis() - lastPulse >= pulseTimeout && pulseCount > 0 || pulseCount >= 4)
  {
    if (tempAction != lastAction || tempPulse != lastPulse) return; //Check if interrupt has fired since loop started, wait for next cycle if it has
    
    tone(12, 1800, 150);
    currentCredit += coinValues[pulseCount-1];
    showCredit();
    pulseCount = 0;
  }


  if ((millis() - lastAction >= actionTimeout) && (lastAction != 0) && (currentCredit > 0) && (pulseCount == 0))
  {
    if (tempAction != lastAction || tempPulse != lastPulse) return; //Check if interrupt has fired since loop started, wait for next cycle if it has
    
    currentCredit = 0;
    lastAction = 0;
    Serial.println("\n*** TIMEOUT! Credit reset. ***");
    showCredit();
  }
}

void acceptorPulse()
{
  lastAction = millis();
  lastPulse = millis();
  pulseCount++;
}

void acceptorCount()
{
  digitalWrite(pinCoinSignal, digitalRead(pinCoinSignal));
}

thanks to Coin acceptor - YouTube
original code original code

I add this

#define pinCoinSignal 3

and change this

void acceptorCount()
{
  digitalWrite(pinCoinSignal, digitalRead(pinCoinSignal));
}

because with the original code if I connect the white (coin) wire to D2 it doesn't read the pulses
... in my case I connect the coin wire to D3 and than it reds them but when I connect the pumps it messes up... I assume that has something with PWM but I'm not sure what

This code won't do anything. What do you want it to do?

void acceptorCount()
{
  digitalWrite(pinCoinSignal, digitalRead(pinCoinSignal));
}

If the intention is to toggle the pin then it should be

void acceptorCount()
{
  digitalWrite(pinCoinSignal,  ! digitalRead(pinCoinSignal));
}

...R

Hello guys... sorry I'm so late but I had to work :frowning:
but these days I was reading more about interrupts to understand it more... here what I learn so far about it... In my code the interrupt 0 is D2 and the interrupt 1 is D3 ... meaning D3 is the pin that I need for my credit.
now ...I about wiring I read a lot too :slight_smile: i try every possible way with it... like to wire all the system with separate power supplys or with one power supply... I wire the ground to one place (star wire ground) but every time I got the same result... which is :

every thing is working properly without my pump connected to the relay...
as soon as I connect the pump to the relay then the credit starts to add-UP, if I disconnect COIN wire from pin D3 then it's working properly ... so I assuming that is something with the interrupts like when I connect the pump it start the interrupt somehow .

also if the COIN wire is connected to D3 and I press the button for starting the relay Chanel (without pump connected to the relay Chanel) its working... its not messing the credit
so what can it be?

Hi guys today I change all of my code that I used before… Now I used another one (thanks to Control Coin Acceptor with Arduino - Arduino Project Hub)

and I change it a little bit so I can test if for my needs
I setup the 10K resistor to my Coin wire as “mdraber” did in his setup
end I get this result:

When I put a coin into the “coinAcceptor” the credit works as it should be (it counts impulses and it convert them into credit correctly)
but when I press the “buttonP1” with the pump connected to the “RelayChanel1”, then the “RelayChanell1” of the relay swiches ON the pump is starting to run, but the number of Impulses are starting to RISE UP if I disconnect the pump from the “Relaychanell1” and pres the “buttonP1” again the “Relaychanell1” swiches ON and the number of Impulses are OK (they are not changing)

so I get the same result as previous with the other Code… which is that when the pump is connected to the system and is running some how it is activating the Interrupts… is this normal?

here is the Code I used (other setup with the wiring is the same)

#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>    //LiquidCrystal C:\Program Files (x86)\Arduino\libraries
#include <EEPROM.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address



#define buttonP1 31 
#define buttonP2 33 
#define buttonP3 35 
#define buttonP4 37 
#define buttonP5 39 

#define buttonPause 22   
#define buttonSecret 43  

#define relayR1 30 
#define relayR2Glaven 32 
#define relayR3 34 
#define relayR4 36 
#define relayR5 38
#define relayR6 40 
#define relayR7 42 
#define relayR8 44 


// variable use to measuer the intervals inbetween impulses
int i = 0;
// Number of impulses detected
int impulsCount = 0;
// Sum of all the coins inseted
float credit = 0;

void setup() {
  // pinMode(2, INPUT_PULLUP);
  Serial.begin(115200);

  // Interrupt connected to PIN D2 executing IncomingImpuls function when signal goes from HIGH to LOW
  attachInterrupt(0, incomingImpuls, FALLING);

  // Setup size of LCD 16 characters and 2 lines
  lcd.begin(16, 2);
  // Back light on
  lcd.backlight();

  digitalWrite(relayR1, HIGH);    
  digitalWrite(relayR2Glaven, HIGH);    
  digitalWrite(relayR3, HIGH);
  digitalWrite(relayR4, HIGH);
  digitalWrite(relayR5, HIGH);
  digitalWrite(relayR6, HIGH);
  digitalWrite(relayR7, HIGH);
  digitalWrite(relayR8, HIGH);

  pinMode(relayR1, OUTPUT);
  pinMode(relayR2Glaven, OUTPUT);
  pinMode(relayR3, OUTPUT);
  pinMode(relayR4, OUTPUT);
  pinMode(relayR5, OUTPUT);
  pinMode(relayR6, OUTPUT);
  pinMode(relayR7, OUTPUT);
  pinMode(relayR8, OUTPUT);

  // Activating the digital pins pull up resistors
  pinMode(buttonP1, INPUT_PULLUP);
  pinMode(buttonP2, INPUT_PULLUP);
  pinMode(buttonP3, INPUT_PULLUP);
  pinMode(buttonP4, INPUT_PULLUP);
  pinMode(buttonP5, INPUT_PULLUP);
  pinMode(buttonSecret, INPUT_PULLUP);
  pinMode(buttonPause, INPUT_PULLUP);



}

void incomingImpuls()
{
  impulsCount = impulsCount + 1;
  i = 0;
}

void loop() {
  i = i + 1;

  Serial.print("i=");
  Serial.print(i);
  Serial.print(" Impulses:");
  Serial.print(impulsCount);
  Serial.print(" Total:");
  Serial.println(credit);


  if (i >= 10 and impulsCount == 1) {   //1den
    credit = credit + 1;
    impulsCount = 0;
    //   EEPROM.put(0, credit);
  }
  if (i >= 10 and impulsCount == 2) { //10den
    credit = credit + 10;
    impulsCount = 0;
    // EEPROM.put(0, credit);
  }
  if (i >= 10 and impulsCount == 3) {   //50den
    credit = credit + 50;
    impulsCount = 0;
    //  EEPROM.put(0, credit);
  }
  if (i >= 10 and impulsCount == 4) {
    credit = credit + 0.2;
    impulsCount = 0;
    // EEPROM.put(0, credit);
  }
  if (i >= 10 and impulsCount == 5) {
    credit = credit + 0.1;
    impulsCount = 0;
    // EEPROM.put(0, credit);
  }
  showCreditLCD();
  sellProduct();
}



void showCreditLCD() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Imulse:");
  lcd.setCursor(9, 0);
  lcd.print(impulsCount);
  lcd.setCursor(0, 2);
  lcd.print("Credit:");
  lcd.setCursor(9, 2);
  lcd.print((int)credit);
  delay(200);
}


//////////////////////////// RELAY ON / OFF//////////////////////
void stopAllRelays() {
  Serial.println("STOP ALL");
  digitalWrite(relayR1, HIGH);
  digitalWrite(relayR2Glaven, HIGH);
  digitalWrite(relayR3, HIGH);
  digitalWrite(relayR4, HIGH);
  digitalWrite(relayR5, HIGH);
  digitalWrite(relayR6, HIGH);
  digitalWrite(relayR7, HIGH);
  digitalWrite(relayR8, HIGH);

}
void sellP1() {
  Serial.println("Run Relay P1");
  digitalWrite(relayR1, LOW);        
  digitalWrite(relayR2Glaven, LOW);    /
  // all other OFF
  digitalWrite(relayR3, HIGH);
  digitalWrite(relayR4, HIGH);
  digitalWrite(relayR5, HIGH);
  digitalWrite(relayR6, HIGH);
  digitalWrite(relayR7, HIGH);
  digitalWrite(relayR8, HIGH);
}
void sellP2() {
    Serial.println("Run Relay P2");
  digitalWrite(relayR1, HIGH);
  digitalWrite(relayR2Glaven, LOW);    
  digitalWrite(relayR3, HIGH);
  digitalWrite(relayR4, HIGH);
  digitalWrite(relayR5, HIGH);
  digitalWrite(relayR6, HIGH);
  digitalWrite(relayR7, HIGH);
  digitalWrite(relayR8, HIGH);
}
void sellP3() {
    Serial.println("Run Relay P3");
  digitalWrite(relayR1, HIGH);
  digitalWrite(relayR2Glaven, LOW);    
  digitalWrite(relayR3, LOW);        
  digitalWrite(relayR4, HIGH);
  digitalWrite(relayR5, HIGH);
  digitalWrite(relayR6, HIGH);
  digitalWrite(relayR7, HIGH);
  digitalWrite(relayR8, HIGH);
}
void sellP4() {
    Serial.println("Run Relay P4");
  digitalWrite(relayR1, HIGH);
  digitalWrite(relayR2Glaven, HIGH);
  digitalWrite(relayR3, HIGH);
  digitalWrite(relayR4, LOW);       
  digitalWrite(relayR5, HIGH);
  digitalWrite(relayR6, HIGH);
  digitalWrite(relayR7, HIGH);
  digitalWrite(relayR8, HIGH);
}
void sellP5() {
   Serial.println("Run Relay P5");
  digitalWrite(relayR1, HIGH);
  digitalWrite(relayR2Glaven, LOW);    
  digitalWrite(relayR3, HIGH);
  digitalWrite(relayR4, HIGH);
  digitalWrite(relayR5, LOW);           
  digitalWrite(relayR6, HIGH);
  digitalWrite(relayR7, HIGH);
  digitalWrite(relayR8, HIGH);
}

void sellProduct() {      
  // if buttonP1 is pressed
  if ( digitalRead(buttonP1) == LOW  && credit != 0) {        
    sellP1();    
  }

  // if buttonP2 is pressed
  else if ( digitalRead(buttonP2) == LOW  && credit != 0) {         
    sellP2();    
  }

  // if buttonP3 is pressed
  else if ( digitalRead(buttonP3) == LOW  && credit != 0) {         
    sellP3();    
  }

  // if buttonP4 is pressed
  else if ( digitalRead(buttonP4) == LOW  && credit != 0) {        
    sellP4();    
  }

  //  // if buttonP5 is pressed
  else if ( digitalRead(buttonP5) == LOW  && credit != 0) {         
    sellP5();    
  }
  // if Pausebutton is pressed
  else if ( digitalRead(buttonPause) == LOW  && credit != 0) {         
    stopAllRelays();    // stop all
  }
}

tanjamaya:
Hi guys today I change all of my code that I used before... Now I used another one (thanks to Control Coin Acceptor with Arduino - Arduino Project Hub)

To my mind it is just a distraction and a waste of time trying a completely different program when the problem is caused by your hardware.

...R

Robin2:
To my mind it is just a distraction and a waste of time trying a completely different program when the problem is caused by your hardware.

...R

so do you have solution for my problem?
what should I change?

tanjamaya:
what should I change?

You need to have to power to the pumps completely separate from the power to the Arduino. You may need to ensure that they are physically separated too.

wildbill:
You need to have to power to the pumps completely separate from the power to the Arduino. You may need to ensure that they are physically separated too.

I already try that... and the result was the same