ESP-07S single relay


#1

Hi Guys,

I’m having problems getting a single relay to operate. I have it wired up to GPIO4 but can’t get it to switch (and running on 5v)…

Here is my code (probably something simple!)

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#define VIRTUAL_PIN 4
#define RELAY_DIGITAL_PIN 4

// WiFi network info.
char ssid[] = “My SSID”;
char wifiPassword[] = “IEatChicken”;

char username[] = “asdfasfasfdsafd”;
char password[] = “asdfsafdsafdasf”;
char clientID[] = “asdfasfdsafdsafd”;

unsigned long lastMillis = 0;

void setup() {
pinMode(RELAY_DIGITAL_PIN, OUTPUT);
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

CAYENNE_IN(VIRTUAL_PIN)

{
// get value sent from dashboard
int currentValue = getValue.asInt(); // 0 to 1

// assuming you wire your relay as normally open
if (currentValue == 0) {
digitalWrite(RELAY_DIGITAL_PIN, HIGH);
} else {
digitalWrite(RELAY_DIGITAL_PIN, LOW);
}
}

void loop() {
Cayenne.loop();

//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
if (millis() - lastMillis > 10000) {
lastMillis = millis();
//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
Cayenne.virtualWrite(0, lastMillis);
//Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}
}

//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“CAYENNE_IN_DEFAULT(%u) - %s, %s”, request.channel, getValue.getId(), getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

Thanks in advance!

Benny


#2

Can you post a link to the relay and how you have it wired?


#3

@bennyrut,

On some versions of the ESP-07, GPIO4 and GPIO5 labels are flipped.

I suggest you measure the outputs on GPIO4 and GPIO5 with a voltmeter to see if they toggle when you press the dashboard button, and adjust your circuit accordingly.

Cheers,

Craig


#4

Hi Adam,

I have the “IN” on the relay connnected to IO4, and its being powered by an external 5v source. I can post some crappy photos if that would help? LOL

Cheers


#5

Hi Kreggly,

I have tested all GPIO’s and there appears to be no change/spike in voltages. I have noticed when I’m monitoring the serial the button press is getting to the board, but not doing anything…


#6

Sure, lets see some pictures.


#7

@bennyrut,

Maybe try removing the default function. Could be this function is trapping all input changes and CAYENNE_IN(4) never gets called.

Cheers,

Craig


#8


#9

still no go Craig. I have commented out…

CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“CAYENNE_IN_DEFAULT(%u) - %s, %s”, request.channel, getValue.getId(), getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}
and still the same result, but obviously no output on the serial monitor.

I have a button configured like this…


Does the channel refer to the digital pin or the virtual pin? Maybe I’m missing something with the digital and virtual pins?

Ben


#10

What do you show under device settings?

Should be Virtual Channels when selecting GPIO.

Cheers,

Craig