Last active
February 20, 2020 06:59
-
-
Save suadanwar/b9ef096fd121b1c1aa134884e8962e6d to your computer and use it in GitHub Desktop.
This sample code is for Control Multiple Servo Using Blynk App's tutorial.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************* | |
Control multiple servo using a Blynk App! | |
App project setup: | |
*************************************************************/ | |
/* Comment this out to disable prints and save space */ | |
#define BLYNK_PRINT Serial | |
#include <ESP8266_Lib.h> | |
#include <BlynkSimpleShieldEsp8266.h> | |
#include <Servo.h> | |
// You should get Auth Token in the Blynk App. | |
// Go to the Project Settings (nut icon). | |
char auth[] = "YourAuthToken"; | |
// Your WiFi credentials. | |
// Set password to "" for open networks. | |
char ssid[] = "YourNetworkName"; | |
char pass[] = "YourPassword"; | |
// Hardware Serial on Mega, Leonardo, Micro... | |
//#define EspSerial Serial1 | |
// or Software Serial on Uno, Nano... | |
#include <SoftwareSerial.h> | |
SoftwareSerial EspSerial(2, 3); // RX, TX | |
// Your ESP8266 baud rate: | |
#define ESP8266_BAUD 9600 | |
ESP8266 wifi(&EspSerial); | |
Servo servo1; | |
Servo servo2; | |
Servo servo3; | |
boolean state1 = false; | |
boolean state2 = false; | |
boolean state3 = false; | |
BLYNK_WRITE(V1) | |
{ | |
if (state1 == false) { | |
state1 = true; | |
servo1.write(0); | |
} | |
else { | |
state1 = false; | |
servo1.write(90); | |
} | |
} | |
BLYNK_WRITE(V2) | |
{ | |
if (state2 == false) { | |
state2 = true; | |
servo2.write(0); | |
} | |
else { | |
state2 = false; | |
servo2.write(90); | |
} | |
} | |
BLYNK_WRITE(V3) | |
{ | |
if (state3 == false) { | |
state3 = true; | |
servo3.write(0); | |
} | |
else { | |
state3 = false; | |
servo3.write(180); | |
} | |
} | |
void setup() | |
{ | |
// Debug console | |
Serial.begin(9600); | |
// Set ESP8266 baud rate | |
EspSerial.begin(ESP8266_BAUD); | |
delay(10); | |
Blynk.begin(auth, wifi, ssid, pass); | |
// You can also specify server: | |
//Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80); | |
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080); | |
servo1.attach(11); | |
servo2.attach(10); | |
servo3.attach(9); | |
} | |
void loop() | |
{ | |
Blynk.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment