Arduino mega + enc28j60 virtualwrite problem

Hi, I need help about virtualwrite I am using Arduino + enc28j60 but after a while it’s disconnected for a minute and connect again.everything working fine but I am notice some delay in loop().

Enc28j60 3.3v – 3.3v external (ams3.3)
Anduino Mega – 5v external
External power 5v 2Amp adapter
Both uses same supply and gnd.

Also facing problem Getting delay :grimacing: and enc28j60 heats up even I can’t touch that this could be problem,too much power loss.please help

void setup () {
timer.setinterval(1000L, Send_data);

void loop() {;

void Send_data () {
virtualwrite (v1,value);
} //No delay at all

//But when use this function 
void Send_data () {
virtualwrite (v1,value);
virtualwrite (V2,value2);
virtualwrite (V3,value3);
virtualwrite (v4,value4);
} // Getting delay 😬 

it is normal for enc28j60 to heat-up to very hot.
add Ethernet.maintain(); to loop()

@Kayyum_Uddin if that’s the actual code you are running then you shouldn’t see anything in Blynk, as there is no Blynk connection code and no in your void loop.
I’d suggest that you post your actual code in full, minus your Blynk auth code.

As far as the enc28j60 is concerned, I’d take a look at it under a powerful magnifier or low magnification microscope and check for solder bridges or other problems. If you have access to a thermometer then measure the temperature and compare the results to the datasheet


That’s my code.

#include <Arduino.h>
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>

BlynkTimer timer;

const byte arduino_mac[] = {0xA8,0x61,0x0A,0xFE,0xFE,0xED};
IPAddress server_ip  (188,166,206, 43);
IPAddress arduino_ip (192,168, 68,102);
IPAddress dns_ip     (192,168, 68,  1);
IPAddress gateway_ip (192,168, 68,  1);
IPAddress subnet_mask(255,255,255,  0);

#include <OneWire.h>
#include <DallasTemperature.h>

OneWire oneWire(21);
DallasTemperature sensors(&oneWire);
DeviceAddress Thermometer = {0x28, 0x3C, 0x58, 0x77, 0x91, 0x0B, 0x02, 0x17};

#include <NewPing.h>
NewPing sonar(14, 16, 142);

#include <MedianFilter.h>
MedianFilter Up_Input(25, 0);

#include <SimpleKalmanFilter.h>
SimpleKalmanFilter Up_Filter(2, 2, 0.1);

struct SONAR_DATA {
  float uS, raw, litre, change, prev;
} up;

float tempC;

byte reconnect = 0;
bool ledState = LOW;
bool Connected = false;

#define led_check 10
#define blynk_server_green 11
#define blynk_server_red 12

void Ethernet_setup() {
  if (reconnect == 0) {
  Connected = Blynk.connect(); 
  if (reconnect == 5) {
    reconnect = 0;

void CheckConnection() {    
  if (!Connected) {

void Sonar() {
  if (Connected) {
    up.uS =;
    up.raw = Up_Filter.updateEstimate(up.uS/57.0);
    up.raw = (142-up.raw)/1.21;
    up.raw = constrain(up.raw, 0, 100);
    up.litre = up.raw*20;

void Change() {
  if (Connected) {
    up.change = up.litre - up.prev;
    up.prev = up.litre;

void TimerEvent() {
  if (Connected) {
    if (up.uS != 0) {
      Blynk.virtualWrite(V1, up.raw);
      Blynk.virtualWrite(V2, (int)up.litre);
      Blynk.virtualWrite(V3, up.change);

    if (tempC >= -10) {
      Blynk.virtualWrite(V4, tempC);

void Temperature() {
  if (Connected) {
    tempC = sensors.getTempC(Thermometer);  


void Arduino_status() {
  if (ledState == LOW) {
    ledState = HIGH;
  } else {
    ledState = LOW;
  digitalWrite(led_check, ledState);
  digitalWrite(blynk_server_red, Connected?LOW:HIGH);
  digitalWrite(blynk_server_green, Connected?HIGH:LOW);

void setup() { 
  byte pin[4] = {10,11,12,6}; //10,11,12 led 
  for (uint8_t i=0; i<4; i++) {
  } digitalWrite(pin[3],HIGH);
  Blynk.config(auth, server_ip, 8080);

  timer.setInterval(100L, Sonar);
  timer.setInterval(60*1000L, Change);
  timer.setInterval(1000L, Temperature);
  timer.setInterval(2000L, TimerEvent);
  timer.setInterval(1000L, Arduino_status);
  timer.setInterval(60*1000L, CheckConnection);

void loop() {
  Connected = Blynk.connected();
  if (Connected) {;

Using platformio because arduino ide so slow while compiling… : Average server response time about 80 - 110ms.if there is error in code or need improvement please suggest me.

You have lots of overlapping timers, and I’m surprised that you need to calculate whatever it is that’s being measured by your sonar function 10 times per second.
If measuring this volume is that critical then I think I would have a dedicated MCU just for that, and I’d choose something with more processing power and memory than the Arduino Mega.

Given the size of the enc28j60 library, I would start monitoring the free memory on the Mega to see if you are running out.


RAM: [== ] 20.0% (used 1642 bytes from 8192 bytes)
Flash: [= ] 12.7% (used 32296 bytes from 253952 bytes)

now what am i do, from you suggest the problem is overlaping timer @PeteKnight

I’m guessing that these numbers come from your compiler. I’m talking about free heap while the code is executing on the Mega, including any losses to memory leaks.

Why is it necessary to calculate the volume every 0.1 seconds?


So changing 100l to 1000(1sec) solve my problem,one another thing the hardware only disconnect after once in b/w 5 - 8 hour for a minute and connect automatically most of time it connect to blynk server without an issue :slightly_smiling_face::slightly_smiling_face: so I decided to implement local server to get rid from this problems. – Thanks pete

the UIPEthernet library uses the memory of enc28j60 to store the network packets. it is designed for MCU with 2kB dynamic memory. Mega has 8kB SRAM

1 Like

A local server will solve some problems, but not all.
Bad coding will cause issues in all situations.