Go Down

Topic: using ethernet shield and relay shield at the same time with a UnoR3 (Read 118 times) previous topic - next topic

Dr_Nefario

Hey Arudinio Gurus

I am trying to use an ethernet shield and a 4 relay shield with an UnoR3 all stacked together. They all fit nicely together with the headers. I previously wrote a sketch for the ethernet shield and was able to control relays with it but the hardware was messy. I wanted to use the 4 relay shield from arduino so it would look nicer.

I started writing a quick test sketch for the relay board and was able to turn relays 1,2,3 and 4 on for one second each. After testing that, I added the preliminary ethernet part of the sketch but hit a roadblock when I added the command :

Ethernet.begin(mac, ip);

This apparently disabled the signal for relay coil 4 which is controlled by pin 12. I am not able to choose what pins to use being the relay shield has pins 4,7,8 and 12 as the power signals for the relays.

Something in that command affected relay 4 (pin 12). My code works ok if I delete that command. Of course I need that command to continue setting up the ethernet shield.

Any help would be great.
Thanks guys.

Darren

Code: [Select]
// relay board 1st project

//     Setting up the ethernet shield
#include <SPI.h>
#include <Ethernet.h> // Initialize the libraries.

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //I left the MAC address and IP address blank.
byte ip[] = { 192, 168, 2, 251 };                  // You will want to fill these in with your MAC and IP address.

EthernetServer server(80); // Assigning the port forwarded number. It's almost always 80.

String readString; // We will be using strings to keep track of things.

//*****************************************************************************************************************


const int RELAYCOIL1 = 4;
const int RELAYCOIL2 = 7;
const int RELAYCOIL3 = 8;
const int RELAYCOIL4 = 12;
void setup() {
  // put your setup code here, to run once:
pinMode (RELAYCOIL1, OUTPUT);     //sets the digital pin #4 as an output to power the coil of relay 1
pinMode (RELAYCOIL2, OUTPUT);     //sets the digital pin #7 as an output to power the coil of relay 2
pinMode (RELAYCOIL3, OUTPUT);     //sets the digital pin #8 as an output to power the coil of relay 3
pinMode (RELAYCOIL4, OUTPUT);     //sets the digital pin #12 as an output to power the coil of relay 4

 Ethernet.begin(mac, ip);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite (RELAYCOIL1, HIGH);     //powers relay 1
delay (1000);     //waits for 1 second
digitalWrite (RELAYCOIL1, LOW);     //powers down relay 1
delay (500);     //waits for half second

digitalWrite (RELAYCOIL2, HIGH);     //powers relay 2
delay (1000);     //waits for 1 second
digitalWrite (RELAYCOIL2, LOW);     //powers down relay 2
delay (500);     //waits for half second

digitalWrite (RELAYCOIL3, HIGH);     //powers relay 3
delay (1000);     //waits for 1 second
digitalWrite (RELAYCOIL3, LOW);     //powers down relay 3
delay (500);     //waits for half second

digitalWrite (RELAYCOIL4, HIGH);     //powers relay 4
delay (1000);     //waits for 1 second
digitalWrite (RELAYCOIL4, LOW);     //powers down relay 4
delay (500);     //waits for half second

}

Dr_Nefario

Hey guys,

No need to respond to this. I found it was just easier to re-wire the header arrangement.

Of course it looks a little messy but it runs the code and relays and is very stable.

Darren

Delta_G

Glad you figured something out.  That's about your only option.  Pin 12 is part of the SPI bus that the ethernet board uses for communication with the Arduino.  So you can't take 12 away from the ethernet board. 
If at first you don't succeed, up - home - sudo - enter.

jurs

Hey Arudinio Gurus

I am trying to use an ethernet shield and a 4 relay shield with an UnoR3 all stacked together.
DO NOT USE the same pins, which are used by the Ethernet Shield, for switching relays!

Ethernet shield uses the SPI interface.

So when using an UNO and Ethernet Shield, DO NOT use these pins for relays:
pin-10 (hardware slave-select
pin-11 SPI-MOSI
pin-12 SPI-MISO
pin-13 SPI-SCK

Also do not use pin-0 and pin-1 when using "Serial" in the sketch.

pin-4 is used for the SD card slot on the Ethernet shield

You can use pin-4 for relay when the SD card slot on the Ethernet shield is NOT occupied by an SD card.

This is NOT A PROGRAMMING QUESTION.

It is a question of which pins are occupied by which hardware.

Dr_Nefario

Thanks guys, I thought it was a programming question. I thought it could be done in the code but apparently I can't stack these boards (even though they fit great.)

And thanks for the advice on what not to do. That will solve some problems coming my way.

Darren

Go Up