BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Arduino Mega + Ethernet Shield W5100


#1

Hello good night again I with problems

I am having problems with my arduino mega and my relays (digital outputs)

It’s weird, some of them are not … I can not make more than 4 digital outputs of the 53 work.

Example

http://kevinescudero.net:8080/xxxxxxxxxxxxx3/update/D31?value=0

http://kevinescudero.net:8080/xxxxxxxxxxxxx3/update/D31?value=1

its WORK.

But

BLYNK_WRITE(V25) {
  EstadoAperturaPorton = param.asInt();
  digitalWrite(AperturaPorton, EstadoAperturaPorton);
}

It does not work, when I click on the APP the “Arduino receives, because I made a few PRINTS but it does not do anything about the pin …”

It’s very strange…

Test up by putting this directly in the SETUP:

digitalWrite(AperturaPorton, EstadoAperturaPorton);

And it does not work either …

Full Code

#define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>
#include <Wire.h>
#include <DHT.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

char auth[] = "xxxxxxxxxxxxxxxx";

#define W5100_CS  10
#define SDCARD_CS 4
#define DHTPIN 23
#define DHTTYPE DHT11     // DHT 11

BlynkTimer timer;
DHT dht(DHTPIN, DHTTYPE);
WidgetRTC rtc;
WidgetTerminal terminal(V100);

bool isFirstConnect = true;

const int SensorPorton = 8; //
const int SensorBombaAgua = 7; //
const int BotonCuarto = 6;

const int ReflectorPorton = 5; 
const int ReflectorTerreno = 4; 
const int AperturaPorton = 31; 
const int LuzCuarto = 2;


const int ReflectorPatio = 45; //
const int BombaAgua = 41; //
const int BombaPresurizadora = 43; //

int EstadoLuzCuarto, EstadoBotonCuarto,EstadoReflectorPorton,EstadoReflectorTerreno,EstadoAperturaPorton,EstadoSensorPorton,EstadoBombaAgua,EstadoSensorBombaAgua,EstadoReflectorPatio,EstadoBombaPresurizadora;


BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
    isFirstConnect = false;
  }
}

BLYNK_WRITE(V0) {
  EstadoLuzCuarto = param.asInt();
  digitalWrite(LuzCuarto, EstadoLuzCuarto);
}
BLYNK_WRITE(V3) {
  EstadoReflectorPorton = param.asInt();
  digitalWrite(ReflectorPorton, EstadoReflectorPorton);
}
BLYNK_WRITE(V4) {
  EstadoReflectorTerreno = param.asInt();
  digitalWrite(ReflectorTerreno, EstadoReflectorTerreno);
}
BLYNK_WRITE(V5) {
  EstadoReflectorPatio = param.asInt();
  digitalWrite(ReflectorPatio, EstadoReflectorPatio);
}
BLYNK_WRITE(V6) {
  EstadoBombaAgua = param.asInt();
  digitalWrite(BombaAgua, EstadoBombaAgua);
}
BLYNK_WRITE(V7) {
  EstadoSensorPorton = param.asInt();
}
BLYNK_WRITE(V25) {
  EstadoAperturaPorton = param.asInt();
  digitalWrite(AperturaPorton, EstadoAperturaPorton);
}
BLYNK_WRITE(V9) {
  EstadoSensorBombaAgua = param.asInt();
}
BLYNK_WRITE(V10) {
  EstadoBombaPresurizadora = param.asInt();
  digitalWrite(BombaPresurizadora, EstadoBombaPresurizadora);
}

void checkbotones()
{
  if (digitalRead(BotonCuarto) == LOW) {
    if (EstadoBotonCuarto != LOW) {
      EstadoLuzCuarto = !EstadoLuzCuarto;
      digitalWrite(LuzCuarto, EstadoLuzCuarto);
      Blynk.virtualWrite(V0, EstadoLuzCuarto);
    }
    EstadoBotonCuarto = LOW;
  } else {
    EstadoBotonCuarto = HIGH;
  }
}

void temperaturayhumedad()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    String currentTime = String(hour()) + ":" + minute() + ":" + second();
    String currentDate = String(day()) + "/" + month() + "/" + year();
    terminal.println("Error Temperatura Cuarto Kevin: ");
    terminal.print(currentTime);
    terminal.print(" ");
    terminal.print(currentDate);
    terminal.println();
    terminal.flush();
    return;
  }
  Blynk.virtualWrite(V2, h);
  Blynk.virtualWrite(V1, t);

}
void checkconnect()
{
  bool result = Blynk.connected();
  if (result == false) {
    Blynk.connect();
    Serial.println("Reconectando");
  }
}

void setup()
{
  Serial.begin(9600);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH);

  Blynk.begin(auth, IPAddress(192, 168, 1, 14), 8080);
  dht.begin();
  rtc.begin();

  pinMode(LuzCuarto, OUTPUT);
  pinMode(ReflectorPorton, OUTPUT);
  pinMode(ReflectorTerreno, OUTPUT);
  pinMode(BombaAgua, OUTPUT);
  pinMode(ReflectorPatio, OUTPUT);

  pinMode(BotonCuarto, INPUT_PULLUP);
  pinMode(SensorPorton, INPUT_PULLUP);
  pinMode(SensorBombaAgua, INPUT_PULLUP);

  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.flush();

  timer.setInterval(100L, checkbotones);
  timer.setInterval(100000L, temperaturayhumedad);
  timer.setInterval(1000L, checkconnect);
}

void loop()
{
  Blynk.run();
  timer.run();
}

EDIT:

I test this and Work Too :open_mouth:

http://kevinescudero.net:8080/0xxxxxxxx3/update/V25?value=1
http://kevinescudero.net:8080/0xxxxxxxxx3/update/V25?value=0


#2

I do not see a pinmode() command for AperturaPorton

You must have a properly set pinMode() for every digital pin you want to control/read from in your sketch. This is an Arduino requirement, not Blynk related.

That said, since Blynk does support direct pin manipulation (typically via the App), the API commands might still work despite the lack of pinMode() as they are processed by the server and the library, not the digitalWrite() or digitalRead() commands.


#3

im so rlly noob and retard hahaha , 4 hours spend for that…