Ice Machine controlor

I am trying to make a ice machine control I have every thing wired up and running fine but after about 4hrs it disides to lock up and stop running and I have no idea way this happens can anyone help my out

this is my sketch

//-------------------------------SET PINS---------------------------
int plateS1 = 4;
int f1 = 2;
int f2 = 3;
int f1s = 1;
int f2s = 1;
int PS = 0;
const int watergate = 9;
const int comp = 10;
const int waterP = 11;
const int reverse = 12;
//------------------------------ lcd setup-------------------------
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x3F // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int n = 1;

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
//-------------------------------

void setup() {
//--------------------------------SET SERIAL AND LCD START UP---------------
Serial.begin(9600);
lcd.begin (16,2);
//--------------------------------SET INPUTS------------------------
pinMode(f1, INPUT);
pinMode(f2, INPUT);
pinMode(plateS1, INPUT);
//--------------------------------SET OUTPUTS------------------------
pinMode(watergate, OUTPUT);
pinMode(comp, OUTPUT);
pinMode(waterP, OUTPUT);
pinMode(reverse, OUTPUT);
//--------------------------------TURN RELAYS OFF--------------------
digitalWrite(comp, HIGH);
digitalWrite(waterP, HIGH);
digitalWrite(watergate, HIGH);
digitalWrite(reverse, HIGH);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.setCursor ( 4 , 0 );
lcd.print(“Welcome”);
delay(5000);
}

void loop() {

Start_Up://-----------------------------------Start_Up------------------------------

// in start up we check to see if the hopper is full
// If hopper is full Machine will hold at this piont untill hopper has been cleared
// If hopper is empty the Machine will begin to make ice

PS = digitalRead(plateS1);
delay(1000);
if (PS == LOW)
{
Serial.print(“Hopper Full”);
delay(500);
lcd.clear ();
delay(500);
lcd.setCursor ( 0 , 0 );
lcd.print(“Hopper Full”);
lcd.setCursor ( 0 , 1 );
lcd.print(“Please Empty”);
delay(5000);
goto Start_Up;
}
else
{
Serial.print(“Hopper Empty”);
delay(500);
lcd.clear ();
delay(500);
lcd.setCursor ( 0 , 0 );
lcd.print(“Ready”);
goto Start;
}
//----------------------------------START--------------------
Start:
//-----------------------------------------------------------

digitalWrite(comp, HIGH); //
digitalWrite(waterP, HIGH); // turns all relays off
digitalWrite(watergate, HIGH); //
digitalWrite(reverse, HIGH); //

//-----------------------------------------------------------------
//------------------------Check_What_Hight_Water_Is----------------
f1s = digitalRead(f1);
if (f1s == HIGH)
{
Serial.print(" Water is full “);
goto clean;
}
else
{
Serial.print(” Water is low ");
delay(2000);
goto Fill_Water;
}
clean: //-----------------------------Clean Plate------------

Serial.print(“Cleaning plate”);
lcd.clear ();
delay(500);
lcd.setCursor ( 0 , 0 );
lcd.print(“Cleaning Plate”);
digitalWrite(watergate, HIGH);
digitalWrite(comp, HIGH);
digitalWrite(waterP, LOW);
delay(60000);
Serial.print(“Plate has been cleaned”);
lcd.clear ();
delay(500);
lcd.setCursor ( 0 , 0 );
lcd.print(“Plate Cleaned”);
goto Makeice;

//-----------------------------------------------------------

//-----------------------------------FILL_Water--------------
Fill_Water:
//-----------------------------------------------------------
digitalWrite(waterP, HIGH);
digitalWrite(watergate, LOW);
Serial.print(“filling water”);
lcd.clear ();
delay(500);
lcd.setCursor ( 0 , 0 );
lcd.print(“Filling Water”);
f1s = digitalRead(f1);
delay(1000);
if (f1s == HIGH)
{
Serial.print(" WATER HI “);
delay(2000);
lcd.setCursor ( 0 , 0 );
lcd.clear ();
lcd.print(“High Water”);
Serial.print(” Clean Plates “);
goto clean;
}
else
{
Serial.print(” WATER LOW ");

delay(2000);
goto Fill_Water;
}

goto Start;

Makeice: //-------------------------------MAKE ICE --------------
digitalWrite(watergate, HIGH);
digitalWrite(comp, LOW);
delay(2000);
lcd.clear ();
lcd.setCursor ( 0 , 0 );
lcd.print(“Compressor ON”);
Serial.print(" COMP ON “);
digitalWrite(waterP, LOW);
lcd.setCursor ( 0 , 1 );
lcd.print(“Water Pump ON”);
delay(2000);
Serial.print(” Water Pump ON “);
delay(1000);
Serial.print(” MAKING ICE ");
lcd.clear ();
lcd.setCursor ( 0 , 0 );
lcd.print(“Making Ice”);
delay(6000);
goto F2s;
F2s: //----------------------------------F2s--------------------
f2s = digitalRead(f2);
if (f2s == HIGH)
{
goto F2s;
}
else

{
goto DROPICE;
}
DROPICE: //-----------------------------DROP ICE-------------
Serial.print(" Lets heat it up “);
delay(2000);
digitalWrite(waterP, HIGH);
delay(2000);
Serial.print(” waterP off “);
delay(2000);
digitalWrite(reverse, LOW);
delay(2000);
Serial.print(” Hot Gas ON “);
goto plate_S;
plate_S: //-------------------------------Check For Ice Drop----
PS = digitalRead(plateS1);
if (PS == HIGH)
{
goto plate_S;
}
else
{
Serial.print(” Cheching for ice drop “);
delay(1000);
Serial.print(” 1 plate droped ");
delay(180000);
lcd.clear ();
lcd.setCursor ( 0 , 0 );
lcd.print(“ICE Dropped”);
Serial.print(“we have done it”);
delay(2000);
digitalWrite(reverse, HIGH);
digitalWrite(comp, HIGH);
goto Start;
}
}

goto is a horrible horrible thing to do. It makes the code impossible to follow. There is absolutely no need for it in C++. Everything can be done without it and will be much easier to debug.

What you want is a "state machine"

Please use code tags when posting code.

and how do I go about changing the way I have this sketch to get ride of the goto ? im running this on a arduino uno

Delta_G:
What you want is a "state machine"

Keep one variable to track the state, and use a series of if / else if statements or a switch / case block to decide based on the state which code to run. Instead of using the goto, you just change the state and let the loop run again.

yes sorry im new to this how do i do that state machine?

I edited the last post to indicate what that is. Here it is again.

Delta_G:
Keep one variable to track the state, and use a series of if / else if statements or a switch / case block to decide based on the state which code to run. Instead of using the goto, you just change the state and let the loop run again.

All of the goto and the delay(..) in your code scare me, but they are probably not the problem.

You need to provide a diagram of your wiring. Specs on the relays would be useful as well.

One of the common causes of this type of problem is trying to power relays off of the same power supply as that which is being used by your Arduino.

By the way, to avoid goto, you need to learn while, and the use of functions.

Learning to write Finite State Machines would also be useful and could avoid the need for all of those delay(..) statements. delay(..) can be evil because nothing useful can happen while a delay(..) is happening.

This thread

has a useful alternative to using delay(..)

Do you know how to use Google? If so, then there are tons of state machine examples out there.

yes i do know how to use google and i will have a look at the state mechine examples

i have 2 float switches for high and low water and 2 reed switches that control if the hopper is full or if the ice has dropped off the plates in defrost mode

i also have 4 240v 10a relays switching compresser ,reversing vovle, water pump, and water filler on and off

Yes, but how are the switches and the relay coils connected to the Arduino? I still think that a wiring diagram would help. How is power provided to the Arduino and to the relay coils?

ok iv tried to show u what i have running. i have put a pic up on the last post sorry for how bad it looks

i just find it strange that it can run for 4-6hrs and than locks up

Hi,

Can you please post a copy of your circuit a picture of a hand drawn circuit in jpg, png will be fine.

Tom..... :slight_smile:

Please don't post to previous posts... it messes up the history!

According to your diagram:

  1. There are only three switches, not four.
  2. Arduino pins 2, 3, and 4 will always be grounded no matter what the switches do.
  3. The power supply has one connection, probably +9v. The -9v (ground) connection to the power supply is missing.
  4. No details have been provided about the 9 volt power supply.
  5. I still don't know anything about the relay controls. Many relays will use a lot of current for their coils, perhaps more than the 9 volt power supply can adequately provide.
  6. Many relay coils produce an inductive "kickback" when de-energized. Unless protected against, this can cause the Arduino to reset or even be damaged. Perhaps your relay board actually has transistors to drive the relays, and protection against the "kickback"?

If you don't know the answers, at least provide us with brands and model numbers and/or URLs. I already took one guess in an earlier post. If I can't get more information, I will have to give up.

this is the relay

5V Eight 8 Channel Relay Module With optocoupler For PIC AVR DSP ARM Arduino

the 9v is a 240v down to 9v I think it is 2amp ratting and yes it has 9v and gnd
in the sketch I did have 4 switches 2 float and 2 reed but I linked the 2 reed switches together

8 relay.jpg

the only other thing I can see that might be making it freeze is that I have the relays mounted over the top of the arduino uno would or could that make it lock up and do funny things? and thanx everyone for the help u are giving me

TomGeorge:
Hi,

Can you please post a copy of your circuit a picture of a hand drawn circuit in jpg, png will be fine.

Tom… :slight_smile:

there u go

After digging around, I was able to come up with this URL:
http://www.ebay.com/itm/5V-Eight-8-Channel-Relay-Module-optocoupler-PIC-AVR-DSP-ARM-Arduino-/310574415181?pt=LH_DefaultDomain_0&hash=item484fad7d4d

and this information:
Specification:
100% Brand New
Size: 13.5 x 5.3 x 1.7cm (LxWxH)
Working voltage: 5V
Channel: 8 channel
This relay module is 5V active low.
It is an 8-channel relay interface board, which can be controlled directly by a wide range of microcontrollers such as Arduino, AVR, PIC, ARM, PLC, etc.
It is also able to control various appliances and other equipments with large current.
Relay output maximum contact is AC250V 10A and DC30V 10A.
Standard interface can be directly connected with microcontrollers.
Red working status indicator lights are conducive to the safe use.
Widely used for all MCU control, industrial sector, PLC control, smart home control.

...which still doesn't tell me whether the coils have kickback protection, or how much current is used from the 5 volt supply (apparently supplied from the Arduino's regulator!) or how much current is needed from each output. It also doesn't correct the OP's other drawing errors.

My guess is still that the Arduino board cannot supply sufficient current to itself and to the relays. There should be a separate 5 volt supply for the relays, with the ground for that supply and the 9 volt supply tied together.

The grammar in "Red working status indicator lights are conducive to the safe use" does not exactly give me a warm feeling.

thanx a lot for the help u have been giving me im just not understanding why it will run for 2 days and not have any probs than lock up or run for 6hrs and than lock up to me that doesn't seen like a programing prob I was running an after market arduino uno and have now just changed it for my original arduino uno and im hoping that can fix the prob. if not I will try to separate the arduino to its own box away from the 240v set up I am also in the proses of rewriting the sketch using the machine state way just having probs trying to get my head around it and get away from the goto statements I have been using