0% found this document useful (0 votes)
54 views3 pages

Define BLYNK

This document contains code for connecting an ESP8266 device to a Blynk server. It defines the necessary tokens and credentials for connecting to a WiFi network and making calls to the Blynk API. The code configures digital pins on the device to control outputs and monitors an analog pin connected to a smoke sensor. It will log events to Blynk if the smoke sensor or button detect issues and turn on LEDs to alert.

Uploaded by

Tarik Ghouldi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

Define BLYNK

This document contains code for connecting an ESP8266 device to a Blynk server. It defines the necessary tokens and credentials for connecting to a WiFi network and making calls to the Blynk API. The code configures digital pins on the device to control outputs and monitors an analog pin connected to a smoke sensor. It will log events to Blynk if the smoke sensor or button detect issues and turn on LEDs to alert.

Uploaded by

Tarik Ghouldi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#define BLYNK_TEMPLATE_ID "TMPLV8KVGbCH"

#define BLYNK_DEVICE_NAME "Quickstart Device"

#define BLYNK_AUTH_TOKEN "LDrQgUARQ8Pw23kDfMhtLzo3o1PIMUKV"

#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[] = "OPPO A16";

char pass[] = "kaoutar00";

BlynkTimer timer;

int mq2 = A0; // smoke sensor is connected with the analog pin A0

int data = 0;

// This function is called every time the Virtual Pin 0 state changes

BLYNK_WRITE(V0)

int value = param.asInt();

digitalWrite(5, value);

BLYNK_WRITE(V1)

int value = param.asInt();

digitalWrite(4, value);
}

BLYNK_WRITE(V2)

int value = param.asInt();

digitalWrite(12, value);

// This function is called every time the device is connected to the Blynk.Cloud

// This function sends Arduino's uptime every second to Virtual Pin 2.

void setup()

{pinMode(5,OUTPUT);

pinMode(13,OUTPUT);

pinMode(4,OUTPUT);

pinMode(14,OUTPUT);

pinMode(12,OUTPUT);

pinMode(12,OUTPUT);

pinMode(16,INPUT_PULLUP);

// Debug console

Serial.begin(115200);

Blynk.begin(auth, ssid, pass);

// You can also specify server:

//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);


// Setup a function to be called every second

void loop()

Blynk.run();

int isButtonPressed = digitalRead(16);

if (isButtonPressed==0 )

{Serial.println("Fire in the House");

Blynk.logEvent("alerte","feu");

digitalWrite(14,HIGH);

delay(10000);

else {digitalWrite(14,LOW);}

data = analogRead(mq2);

Blynk.virtualWrite(V4, data);

if (data > 300 )

Blynk.logEvent("alerte","gaz");

digitalWrite(13,HIGH);

else

{digitalWrite(13,LOW);}

You might also like