Arduino Ethernet shield stops working after digitalwrite


I am trying to receive data from a raspberry pi, and setup multiple relays (as much as possible, maybe around 16 but i am not sure yet).

I have a enc28j60 ethernet shield, and Arduino Nano and a relayboard (1 relay).
I am trying some demo’s and via upd i can get the program “working”.

Whenever i make a request to the arduino, the arduino receives the request and shows that a relay needs to be turned on or off. This works EXCEPT if i really turn on or off the relay via digitalWrite, after i turn ON the relay, the ethernet board stops working. I don’t get any message or crash, it just doesn’t receive any data anymore.

I have tested from D1 till D9, and A0 till A7, all of them act the same (D10 till D13 are being used by the ethernet board)

This is my modified example but it is not ready yet:

// Demonstrates usage of the new udpServer feature.
// You can register the same function to multiple ports,
// and multiple functions to the same port.
// 2013-4-7 Brian Lee <>
// License: GPLv2

#include <EtherCard.h>
#include <IPAddress.h>

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)
#define CH1pin 2
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

//callback that prints received packets to the serial port
void udpSerialPrint(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len){
  IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);
//  Serial.print("dest_port: ");
//  Serial.println(dest_port);
//  Serial.print("src_port: ");
//  Serial.println(src_port);
//  Serial.print("src_port: ");
//  ether.printIp(src_ip);
//  Serial.println("data: ");
  String relayValues(data);
  if(relayValues == "1") {
    digitalWrite(CH1pin, HIGH);
  else {
    digitalWrite(CH1pin, LOW);

void setup(){

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
    Serial.println(F("Failed to access Ethernet controller"));
  ether.staticSetup(myip, gwip);
  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

  //register udpSerialPrint() to port 1337
  ether.udpServerListenOnPort(&udpSerialPrint, 1337);

  //register udpSerialPrint() to port 42.
  //ether.udpServerListenOnPort(&udpSerialPrint, 42);
  pinMode(CH1pin, OUTPUT);
  digitalWrite(CH1pin, LOW);

void loop(){
  //this must be called for ethercard functions to work.
1 Like

Why is it unlisted?

Hi @bbuster. This was done accidentally by one of our moderators. I have now relisted it. I apologize for any inconvenience.

How is the relay board wired up? Could this be caused by a power problem?

I take the 5v from the arduino, i also changed from pc power to a 10w ipad power supply but that didn’t make a difference, or should i power the relayboard directly with 5v instead of the 5v from the arduino?

I would try the relay board powered directly.

I thought the power supply from the Arduino was limited and you already have the ethernet shield which draws a significant amount iirc.

It was the power supply, as soon as i used my bench power supply it works like a charm! Thanks a lot

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.