88nikodem88ag2max
Published

ESP8266 NodeMCU light switch

Remote light on and off with ESP8266 NodeMCU and RemoteXY library

IntermediateFull instructions provided338
ESP8266 NodeMCU light switch

Things used in this project

Hardware components

ESP8266 NodeMCU
×1
ESP8266 NodeMCU Shield
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2

Software apps and online services

RemoteXY

Story

Read more

Schematics

ESP8266 NodeMCU lights switch diagram

Code

ESP8266 NodeMCU lights switch Code

C/C++
#define REMOTEXY_MODE__ESP8266WIFI_LIB_POINT
#include <ESP8266WiFi.h>
#include<Servo.h>
#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,1,0,0,0,20,0,13,24,1,
  2,1,21,26,22,11,2,26,31,31,
  79,78,0,79,70,70,0 };
  

struct {

    
  uint8_t switch_1; 

  uint8_t connect_flag;  

} RemoteXY;
#pragma pack(pop)


#define PIN_SWITCH_1 D5
#define PIN D4

Servo myservo1;
Servo myservo2;

void setup() 
{
  RemoteXY_Init (); 
  
  pinMode (PIN_SWITCH_1, OUTPUT);
  pinMode (PIN, OUTPUT);

  myservo1.attach(PIN_SWITCH_1);
  myservo2.attach(PIN);
 
}

void loop() 
{ 
  RemoteXY_Handler ();
  
  int poz = RemoteXY.switch_1;
  
  if (poz == 1){
    myservo1.write(30);
    myservo2.write(30);
   
  }
  else if (poz == 0){
    myservo1.write(165);
    myservo2.write(180);
 
  }
  else{
    
  }
  
  


}

Credits

88nikodem88

88nikodem88

0 projects • 0 followers
ag2max

ag2max

2 projects • 1 follower

Comments