LEDs controle using IR remote and node mcu
(Code for the project.)
#include <IRrecv.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
uint16_t RECV_PIN = D5;
IRrecv irrecv(RECV_PIN);
decode_results results;
int LED1 = D0;
int LED2 = D1;
int LED3 = D2;
int LED4 = D3;
int LED5 = D4;
int LED6 = D5;
int swval[] = {0,0,0,0,0,0,0};
char auth[] = "auth token";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ssidname";
char pass[] = "paswward";
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
irrecv.enableIRIn(); // Start the receiver
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
}
void relayswitch(int i,int j){
if(swval[j]==1){
digitalWrite(i, LOW);
swval[j]=0;
}else{
digitalWrite(i, HIGH);
swval[j]=1;
}
}
void loop() {
//ir receiveing code, change with your ir codes
if (irrecv.decode(&results)) {
unsigned int ircode = results.value;
Serial.println(ircode);
if(ircode==392671089){
relayswitch(LED1,1);
}else if(ircode==3470051241){
relayswitch(LED2,2);
}else if(ircode==33468495){
relayswitch(LED3,3);
}else if(ircode==33452175){
relayswitch(LED4,4);
}else if(ircode==51945809){
relayswitch(LED5,5);
}else if(ircode== 33462375){
relayswitch(LED6,6);
}
else if(ircode==33441975){
relayswitch(LED1,1);
relayswitch(LED2,2);
relayswitch(LED3,3);
relayswitch(LED4,4);
relayswitch(LED5,5);
relayswitch(LED6,6);
}
Serial.println(ircode);
irrecv.resume(); // Receive the next value
}
delay(100);
{
Blynk.run();
}
}
Comments
Post a Comment