Skip to content

Instantly share code, notes, and snippets.

@tairea
Last active September 21, 2021 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tairea/4839b9efd12e55c4073b55887cf07f3d to your computer and use it in GitHub Desktop.
Save tairea/4839b9efd12e55c4073b55887cf07f3d to your computer and use it in GitHub Desktop.
Arduino: Blynk Traffic Light Sketch (NodeMCU + 3 leds)
#define BLYNK_TEMPLATE_ID "blynk_template_id"
#define BLYNK_DEVICE_NAME "Quickstart Device"
#define BLYNK_AUTH_TOKEN "blynk_auth_token"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "wifi_name";
char pass[] = "wifi_pass";
BLYNK_WRITE(V1) // Executes when the value of virtual pin 1 changes
{
if(param.asInt() == 1)
{
digitalWrite(D3,HIGH); // Set pin D3 HIGH
Serial.println("Red Led On");
}
else
{
digitalWrite(D3,LOW); /// Set pin D3 LOW
Serial.println("Red Led off");
}
}
BLYNK_WRITE(V2)
{
if(param.asInt() == 1)
{
digitalWrite(D2,HIGH);
Serial.println("Yellow Led On");
}
else
{
digitalWrite(D2,LOW);
Serial.println("Yellow Led off");
}
}
BLYNK_WRITE(V3)
{
if(param.asInt() == 1)
{
digitalWrite(D1,HIGH);
Serial.println("Green Led On");
}
else
{
digitalWrite(D1,LOW);
Serial.println("Green Led off");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(D3, OUTPUT); // Initialise digital pin D3 as an output pin. ---> Red Led
pinMode(D2, OUTPUT); // Initialise digital pin D2 as an output pin. ---> Yellow Led
pinMode(D1, OUTPUT); // Initialise digital pin D1 as an output pin. ---> Green Led
}
void loop()
{
Blynk.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment