Devices & Components
SG90 Micro-servo motor
ESP8266 NodeMCU
ESP8266 NodeMCU Shield
Software & Tools
Arduino IDE
RemoteXY
Project description
Code
ESP8266 NodeMCU light switch code
c_cpp
1#define REMOTEXY_MODE__ESP8266WIFI_LIB_POINT 2#include <ESP8266WiFi.h> 3#include<Servo.h> 4#include 5 <RemoteXY.h> 6 7// RemoteXY connection settings 8#define REMOTEXY_WIFI_SSID 9 "RemoteXY" 10#define REMOTEXY_WIFI_PASSWORD "12345678" 11#define REMOTEXY_SERVER_PORT 12 6377 13 14 15// RemoteXY configurate 16#pragma pack(push, 1) 17uint8_t RemoteXY_CONF[] 18 = 19 { 255,1,0,0,0,20,0,13,24,1, 20 2,1,21,26,22,11,2,26,31,31, 21 79,78,0,79,70,70,0 22 }; 23 24 25struct { 26 27 28 uint8_t switch_1; 29 30 // other 31 variable 32 uint8_t connect_flag; 33 34} RemoteXY; 35#pragma pack(pop) 36 37 38#define 39 PIN_SWITCH_1 D5 40#define PIN D4 41 42Servo myservo1; 43Servo myservo2; 44 45void 46 setup() 47{ 48 RemoteXY_Init (); 49 50 pinMode (PIN_SWITCH_1, OUTPUT); 51 52 pinMode (PIN, OUTPUT); 53 54 myservo1.attach(PIN_SWITCH_1); 55 myservo2.attach(PIN); 56 57 58} 59 60void loop() 61{ 62 RemoteXY_Handler (); 63 64 int poz = RemoteXY.switch_1; 65 66 67 if (poz == 1){ 68 myservo1.write(30); 69 myservo2.write(30); 70 71 72 } 73 else if (poz == 0){ 74 myservo1.write(165); 75 myservo2.write(180); 76 77 78 } 79 else{ 80 81 } 82 83 84 85 86}
ESP8266 NodeMCU light switch code
c_cpp
1#define REMOTEXY_MODE__ESP8266WIFI_LIB_POINT 2#include <ESP8266WiFi.h> 3#include<Servo.h> 4#include <RemoteXY.h> 5 6// RemoteXY connection settings 7#define REMOTEXY_WIFI_SSID "RemoteXY" 8#define REMOTEXY_WIFI_PASSWORD "12345678" 9#define REMOTEXY_SERVER_PORT 6377 10 11 12// RemoteXY configurate 13#pragma pack(push, 1) 14uint8_t RemoteXY_CONF[] = 15 { 255,1,0,0,0,20,0,13,24,1, 16 2,1,21,26,22,11,2,26,31,31, 17 79,78,0,79,70,70,0 }; 18 19 20struct { 21 22 23 uint8_t switch_1; 24 25 // other variable 26 uint8_t connect_flag; 27 28} RemoteXY; 29#pragma pack(pop) 30 31 32#define PIN_SWITCH_1 D5 33#define PIN D4 34 35Servo myservo1; 36Servo myservo2; 37 38void setup() 39{ 40 RemoteXY_Init (); 41 42 pinMode (PIN_SWITCH_1, OUTPUT); 43 pinMode (PIN, OUTPUT); 44 45 myservo1.attach(PIN_SWITCH_1); 46 myservo2.attach(PIN); 47 48} 49 50void loop() 51{ 52 RemoteXY_Handler (); 53 54 int poz = RemoteXY.switch_1; 55 56 if (poz == 1){ 57 myservo1.write(30); 58 myservo2.write(30); 59 60 } 61 else if (poz == 0){ 62 myservo1.write(165); 63 myservo2.write(180); 64 65 } 66 else{ 67 68 } 69 70 71 72 73}
Downloadable files
ESP8266 NodeMCU light switch diagram
ESP8266 NodeMCU light switch diagram

Comments
Only logged in users can leave comments