I have a blynk esp8266 rf remote control working fine. I wanted to add led status to know whether relay is on or off
Can anybody help me to create code for the same. Thank you.
Can you start with posting what code you already have and some hardware descriptions? It’s kind of unclear now
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space ````#includ<
BlynkSimpleEsp8266.h>
#
include <
RCSwitch.h>
#
include <``stdio.h>
RCSwitch mySwitch = RCSwitch();
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “”;
void setup(){
mySwitch.enableTransmit(4);
mySwitch.setPulseLength(480);
Serial.begin(9600);
Blynk.begin(auth, “”, “”);
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(0) {
mySwitch.send(“010101010101010100000011”);
}
BLYNK_WRITE(2) {
mySwitch.send(“010101010101010100001100”);
}
BLYNK_WRITE(5) {
mySwitch.send(“010101010101010100001111”);
}
BLYNK_WRITE(12) {
mySwitch.send(“010101010101010100110000”);
}
BLYNK_WRITE(13) {
mySwitch.send(“010101010101010100110011”);
}
BLYNK_WRITE(14) {
mySwitch.send(“010101010101010100111100”);
}
BLYNK_WRITE(15) {
mySwitch.send(“010101010101010100111111”);
}
BLYNK_WRITE(16) {
mySwitch.send(“010101010101010111000000”);
}
This is my sample code, hardware I am using ESP8266 and RF module to transmit.
@sat with RF you can never be sure of the status of the device you are controlling and Blynk will never be able to handle this i.e. the device is in no way connected to the Blynk servers.
You can have an LED on the Blynk server that indicates what the possible state of the relay is but not as a 100% certainty. Take for instance your neighbour sending an RF signal at the same time you send yours. This means the relay will fail to activate even though you sent the signal and set the LED to be on.
We use Blynk for RF stuff (without libraries) and as we have several devices in the same location we have to be careful that they are not triggered at the same time. Two on signals sent a fraction of a second apart will not be interpreted as ON by the receiving device.
@Costas In that case you should handle this situation in code. This not related to Blynk itself. Blynk will always show what you have send to server.
@Dmitriy what I was trying to stress is that no amount of code can cover the status of RF devices. The nature of RF devices is that they are not connected to anything so the code can only state what has been sent to the device, not how the device responded or the current state of the device.
The RF receiving device would need to have a transmitter, which most don’t, to be able to provide the status of the device i.e. relay on / off back to the ESP or any other device connected to Blynk servers.
Even this wouldn’t be 100% foolproof as the RF transmission from the device with the relay might not be received, for a number of reasons, by the ESP.
RF devices have their uses but there will always be this limitation.
The workaround we use is to repeatedly send OFF signals to the receiving device when the system is rebooted. Still not 100% accuracy but near enough, and not ideal as you might not want to switch the remote device off just to be sure of the state.
Ah, see. Agree here.
What I really required is to show whether the hardware send the signal or not .Even though it is not accurate consider its for a learning purpose. please give an example code to achieve it.
LED widget has changed since it was first created so hopefully this info is correct.
Add an LED and tie it to say virtual pin 10 (assuming you are already using some of the lower numbers).
Add the following line in your definitions (where you have auth string):
WidgetLED led1(V10); //led on virtual pin V10
At the point you send your on signal you just need:
led1.on();
And led1.off(); when you send the off signal.
Than you for your advice, Let me try with the code, but on & off I am sending the same RF code since it is toggle mode.
You must have code that remembers your toggle state (I do the same). In this toggle area is where you toggle the LED’s.
Ok i’ll give you our toggle. With a virtual button say V1 you have:
if (CentralHeating == 0){ // central heating was off so turn it on
HeatingOn();
}
else{ // central heating was on so turn it off
HeatingOff();
}
Then 2 functions (remove LCD, digitalWrite etc):
void HeatingOn(){ // details for heating on
led1.on();
lcd.print(0, 0, "ON ");
digitalWrite(GreenLED, HIGH); // turn LED ON
CentralHeating = 1;
}
void HeatingOff(){ // details for heating off
led1.off();
lcd.print(0, 0, "OFF");
digitalWrite(GreenLED, LOW); // turn LED OFF
CentralHeating = 0;
}
Hope this helps.
Thanks a lot for your immediate reply let me try.