Relays go mental on restart

Hi all,

Just building a project using an 8 channel relay board with an Arduino and wondered if there was a way to stop it going mad for the few seconds when you restart/upload a new sketch/or serial link to the Arduino?

Thanks for any help in advance :)

Is it going mad ? Is it not a relay board with optocouplers ? At power up or during reset the pins of the Arduino are inputs and are high impedance. You could add 10k resistors to ground to keep the pins low.

Lots of details from your set-up are missing. You should list things like:
the code
the Arduino board
Relay board link or datasheet
power source / sources
type of load on relays
Anything that may be related to your problems.

cyclegadget:
Lots of details from your set-up are missing. You should list things like:
the code
the Arduino board
Relay board link or datasheet
power source / sources
type of load on relays
Anything that may be related to your problems.

Sorry didn’t think that much info would be needed with my having a restart question!
Here goes :slight_smile:
Some code attached (can only attach 4 files so have to post again).
Arduino Uno R3 board
Relay board http://www.ebay.co.uk/itm/170745298865?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
Load 13 Watt heat mat

constants.h (1.8 KB)

Cooling.ino (2.15 KB)

Habitat_control.ino (1.71 KB)

Heating.ino (1.65 KB)

indieflow:

cyclegadget:
Lots of details from your set-up are missing. You should list things like:
the code
the Arduino board
Relay board link or datasheet
power source / sources
type of load on relays
Anything that may be related to your problems.

Sorry didn’t think that much info would be needed with my having a restart question!
Here goes :slight_smile:
Some code attached (can only attach 4 files so have to post again).
Arduino Uno R3 board
Relay board http://www.ebay.co.uk/itm/170745298865?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
Load 13 Watt heat mat

Last file plus a picture of setup!

Lighting.ino (596 Bytes)

Lighting.ino (596 Bytes)

You appear to be using pin 13 to control the relay channel. This pin is used by the bootloader on the chip during a reset to blink the on-board pin 13 so it's commanding the relay board channel. Try moving the relay channel to another digital pin.

Lefty

retrolefty: You appear to be using pin 13 to control the relay channel. This pin is used by the bootloader on the chip during a reset to blink the on-board pin 13 so it's commanding the relay board channel. Try moving the relay channel to another digital pin.

Lefty

How simple! Champion, cheers Lefty!

Is there anyway of changing this so that I can use that pin? Quite pushed for pins with this project!

Also on a side note any idea why sometimes when I restart my LCD displays garbage? Usually cleared by pressing the reset button for a few seconds.

@retrolefty, Well spotted !

@indieflow You can use that pin for leds, or as input for buttons. With Version R3 of the Arduino Uno that pin can be used as input without problem.

About the display. I had a problem with it, but I don't know if you have the same problem. Sometimes garbadge was sent to the display (during reset). The normal initialization could not get the display out of that. I figured out a way to make it always work. But that was with my own functions. With the Arduino library, you could try to initialize it three times.

indieflow:

retrolefty: You appear to be using pin 13 to control the relay channel. This pin is used by the bootloader on the chip during a reset to blink the on-board pin 13 so it's commanding the relay board channel. Try moving the relay channel to another digital pin.

Lefty

How simple! Champion, cheers Lefty!

Is there anyway of changing this so that I can use that pin? Quite pushed for pins with this project!

Are you using up all your analog input pins? The can be easily used as digital input or output pins.

Also on a side note any idea why sometimes when I restart my LCD displays garbage? Usually cleared by pressing the reset button for a few seconds.

Initialization of the LCD takes a given finite amount of time that the supporting library code may not be tuned well enough maybe. Sometimes a well placed delay() in the startup function can help or maybe as suggested do more then a single LCD initialize command in a row. Sometimes there is variation from LCD manufactures so you just might have to play around with it to see if you can improve it's performace by some tweeking. Lefty

retrolefty:

indieflow:

retrolefty: You appear to be using pin 13 to control the relay channel. This pin is used by the bootloader on the chip during a reset to blink the on-board pin 13 so it's commanding the relay board channel. Try moving the relay channel to another digital pin.

Lefty

How simple! Champion, cheers Lefty!

Is there anyway of changing this so that I can use that pin? Quite pushed for pins with this project!

Are you using up all your analog input pins? The can be easily used as digital input or output pins.

Also on a side note any idea why sometimes when I restart my LCD displays garbage? Usually cleared by pressing the reset button for a few seconds.

Initialization of the LCD takes a given finite amount of time that the supporting library code may not be tuned well enough maybe. Sometimes a well placed delay() in the startup function can help or maybe as suggested do more then a single LCD initialize command in a row. Sometimes there is variation from LCD manufactures so you just might have to play around with it to see if you can improve it's performace by some tweeking. Lefty

Thanks for the responses!

So am I right in believing your recommending #include the library multiple times at the beginning of the sketch and include a delay in the void setup and seeing what works best?

Thanks for the responses!

So am I right in believing your recommending #include the library multiple times at the beginning of the sketch and include a delay in the void setup and seeing what works best?

No, you can only include a library once. I noted this line in the arduino IDE supplied LiquidCrystal library code:

// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
  // according to datasheet, we need at least 40ms after power rises above 2.7V
  // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
  delayMicroseconds(50000);

So perhaps your display needs more then that amount of time to initilize. So first just try adding as the first line in your setup() function a delay(1000); //wait one second to see if that changes your symptom or not.

Lefty

I checked the LiquidCrystal library source code and my code.
The LiquidCrystal.begin() function already has code to try a few times with delays to capture the LCD if the LCD was in a wrong state. That is very good. The code I made is different for 4-bit data.
Do you have the LCD in 4-bit mode ?
You could call lcd.begin() three times with a delay of 1ms in between. If that doesn’t help, something else is going on, like a voltage drop. The LCD displays need a steady 5V, not 4.5V.
Or perhaps you call lcd.begin() too fast after startup. Perhaps you could wait 500ms before calling it.

Adding a delay(1000) prior to writing to the LCD in setup() seems to have cleared the problem!

Thanks for the help guys :slight_smile:

retrolefty:

Thanks for the responses!

So am I right in believing your recommending #include the library multiple times at the beginning of the sketch and include a delay in the void setup and seeing what works best?

No, you can only include a library once. I noted this line in the arduino IDE supplied LiquidCrystal library code:

// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
  // according to datasheet, we need at least 40ms after power rises above 2.7V
  // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
  delayMicroseconds(50000);

So perhaps your display needs more then that amount of time to initilize. So first just try adding as the first line in your setup() function a delay(1000); //wait one second to see if that changes your symptom or not.

Lefty

delayMicroseconds() does not work as expected with large arguments - how large depending on the clock speed of your system - best not to pass a value larger than 10,000 or so. This means that the LiquidCrystal library has a bug that needs reporting.

Most probably a silly question though on a side note on my project can anyone explain how I would go about working out how much Wattage I could run through one of these relays safely?

I know P=V*I though what about spikes due to turning on and off!

I’m looking to run 240V heatmats through these relays and wondered how many I could control safely. The mats range from 8.5-30W at 230V depending on size.

indieflow: Most probably a silly question though on a side note on my project can anyone explain how I would go about working out how much Wattage I could run through one of these relays safely?

I know P=V*I though what about spikes due to turning on and off!

I'm looking to run 240V heatmats through these relays and wondered how many I could control safely. The mats range from 8.5-30W at 230V depending on size.

The power limit is simply the relay contact ratings on each relay. On the relay case there is both maximum voltage and current limits listed that can safely pass through the contacts. Try and stay below the maximum current rating for longer contact life. At 30 watt heating pad loads you have nothing to worry about, each relay can handle any of your mats. So unless you are going to power many pads on just one relay I don't see any problem. Lefty

retrolefty:

indieflow:
Most probably a silly question though on a side note on my project can anyone explain how I would go about working out how much Wattage I could run through one of these relays safely?

I know P=V*I though what about spikes due to turning on and off!

I’m looking to run 240V heatmats through these relays and wondered how many I could control safely. The mats range from 8.5-30W at 230V depending on size.

The power limit is simply the relay contact ratings on each relay. On the relay case there is both maximum voltage and current limits listed that can safely pass through the contacts. Try and stay below the maximum current rating for longer contact life. At 30 watt heating pad loads you have nothing to worry about, each relay can handle any of your mats. So unless you are going to power many pads on just one relay I don’t see any problem.
Lefty

Lefty
Thats exactly what I’m after knowing, how many pads could be run off one relay? For example if I wired a 5 way multi plug to the relay then plugged in multiple pads.

When I did the maths I worked out I could run 2400W through each relay which seems extremely high!
Also the relay says 10A though do you reckon the screw terminals and tracks can take that much current?

indieflow:

retrolefty:

indieflow: Most probably a silly question though on a side note on my project can anyone explain how I would go about working out how much Wattage I could run through one of these relays safely?

I know P=V*I though what about spikes due to turning on and off!

I'm looking to run 240V heatmats through these relays and wondered how many I could control safely. The mats range from 8.5-30W at 230V depending on size.

The power limit is simply the relay contact ratings on each relay. On the relay case there is both maximum voltage and current limits listed that can safely pass through the contacts. Try and stay below the maximum current rating for longer contact life. At 30 watt heating pad loads you have nothing to worry about, each relay can handle any of your mats. So unless you are going to power many pads on just one relay I don't see any problem. Lefty

Lefty Thats exactly what I'm after knowing, how many pads could be run off one relay? For example if I wired a 5 way multi plug to the relay then plugged in multiple pads.

When I did the maths I worked out I could run 2400W through each relay which seems extremely high! Also the relay says 10A though do you reckon the screw terminals and tracks can take that much current?

So what is that contact reading anyway?. Small picture, think it's 220vac at 10 amps max. That is 2,200 watts of load power, so you can do the math to see how many of your wimpy pads it takes to add up to 2,200 watts. I would not run 10 amps through the contacts, but rather limit it to half that for longer contact life, so 1,000 watts of load is a realistic relay limit in my opinion. Be sure you AC wiring through the contacts are of proper gauge thickness and insulation voltage rating and has no exposed bare wires that could be touched accidental.

Good luck on your contribution to global warming. ;)

Cheers Lefty, I'm sure my reptiles will feel like Borgs by the time I've finished wiring them up with Arduinos! lol

indieflow: Cheers Lefty, I'm sure my reptiles will feel like Borgs by the time I've finished wiring them up with Arduinos! lol

Ugh, snakes on planes reptile fear here. I might not of responded to your questions if I knew the end result would be happier reptiles. :D

Lefty