0% found this document useful (0 votes)
8 views7 pages

Code 021810

The document contains code for an IoT project using Blynk and ESP8266/ESP32 microcontrollers. It includes functionality for reading various sensors (temperature, gas, vibration, touch) and sending the data to the Blynk app. The code also handles interrupts and includes setup and loop functions for managing the device's operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Code 021810

The document contains code for an IoT project using Blynk and ESP8266/ESP32 microcontrollers. It includes functionality for reading various sensors (temperature, gas, vibration, touch) and sending the data to the Blynk app. The code also handles interrupts and includes setup and loop functions for managing the device's operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

CODE:

/////////////////////////////////////////////////////////////////////

#define BLYNK_TEMPLATE_ID "TMPLJJRibzJH"


#define BLYNK_TEMPLATE_NAME "HELMET"
#define BLYNK_AUTH_TOKEN "pRc_gfdMFD8J_J22ywnpdMfbfNX25wJ2"

/////////////////////////////////////////////////////////////////////

char auth[] = BLYNK_AUTH_TOKEN;


char ssid[] = "iot123456";
char pass[] = "iot123456";

/////////////////////////////////////////////////////////////////////

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
ESP8266 wifi(&Serial);
BlynkTimer timer;

////////////////////////////////////////

#include <DHT.h>
#define DHTPIN 3
#define DHTTYPE DHT11 // DHT11 TEMP
DHT dht(DHTPIN, DHTTYPE);
float Fahrenheit = 0.00;

float value=0; //rep pin2


float rev=0;
int rpm;
int oldtime=0;
int time;

void isr() //interrupt service routine, only in pin number 2 or pin


number 3
{
rev++;
}

#include <CapacitiveSensor.h>
CapacitiveSensor cs_6_9 = CapacitiveSensor(6,9); //9 pin sensor

//////////////////////////////////////////

void respsensor()
{
delay(1000);
detachInterrupt(0);
time=millis()-oldtime; //finding total time for one rev
rpm=(rev/time)*60; //calculating the rpm
oldtime=millis();
rev=0;

Blynk.virtualWrite(V0, rpm);

if (rpm >= 15)


{
digitalWrite(12, HIGH);
delay(1000);
}
else
{
digitalWrite(12, LOW);
}

attachInterrupt(0,isr,RISING);

}
/////////////////////////////////////////////

void gas()
{
int gas = analogRead(A0); //air
int g= gas*0.09775;//0.15
Blynk.virtualWrite(V1, g);

if(g <= 50)


{
Blynk.logEvent("gas_event");
}

}
////////////////////////////////////////////////////////

void vibsensor()
{
int vibsensor = analogRead(A2);
int v = vibsensor*0.09775;

Blynk.virtualWrite(V2, v);

///////////////////////////////////////////

void tempsensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Fahrenheit = ( t * 1.8 ) + 32; //T(°F) = T(°C) × 9/5 + 32

Blynk.virtualWrite(V3, t);
Blynk.virtualWrite(V4, h);
}

/////////////////////////////////////////////

////////////////////////////////////////

void touchchecking()
{
long sensor = cs_6_9.capacitiveSensor(50);
int p = digitalRead(11);
Blynk.virtualWrite(V7, sensor);

if(sensor >= 100)


{
Blynk.virtualWrite(V6, " NOT SAFELY ");
Blynk.logEvent("earth_event");
digitalWrite(7, HIGH);
}
else
{
Blynk.virtualWrite(V6, " GOOD EARTHING ");
digitalWrite(7, LOW);
}

//////////////////////////

if (p == LOW)
{
Blynk.virtualWrite(V5, " No shock");
digitalWrite(7, LOW);
}
else
{
Blynk.virtualWrite(V5, " shock");
Blynk.logEvent("shock_event");
digitalWrite(7, HIGH);
}
}
//////////////////////////////////////////

void setup()
{

pinMode(7, OUTPUT);
pinMode(12, OUTPUT);

digitalWrite(12, LOW);
digitalWrite(7, LOW);

pinMode(11, INPUT);
pinMode(3, INPUT);
dht.begin();
cs_6_9.set_CS_AutocaL_Millis(0xFFFFFFFF);

Serial.begin(9600);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);

timer.setInterval(1000L, respsensor);
timer.setInterval(1000L, gas);
timer.setInterval(1000L, vibsensor);
timer.setInterval(1000L, tempsensor);
//timer.setInterval(1000L, shock);
timer.setInterval(1000L, touchchecking);

attachInterrupt(0,isr,RISING);
}

void loop()
{
Blynk.run();
timer.run();

respsensor();
gas();
vibsensor();
tempsensor();
// shock();
touchchecking();
}

Blynk 2.0 and ESP32 Code:


// Template ID, Device Name and Auth Token are provided by the
Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID “TMPLlh8o1jPo”
#define BLYNK_DEVICE_NAME “Getting started”
#define BLYNK_AUTH_TOKEN
“57xQ3I8tMFX5tsqzAuleqJsI0xU2wfaA”
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
charauth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to “” for open networks.
charssid[] = “AndroidAP3DEC”;
char pass[] = “electroniclinic”;
BlynkTimer timer;
int pot=26;
BLYNK_WRITE(V0)
{
intpinValue=param.asInt();
digitalWrite(25,pinValue);
}
void setup()
{
pinMode(pot,INPUT);
pinMode(25,OUTPUT);
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
intpotvalue=analogRead(36);
Blynk.virtualWrite(V1,potvalue);
}

You might also like