Hi,
I am currently doing project to read the ultrasonic sensor and 3 gas sensors.
I use the proteus simulation software to run the program and not use hardware.
I have the problem where those sensor cannot display the value in blynk but if I commenting the void gas() and void car(), the blynk can read the sensor value in blynk.
I need to read those sensor in continuous time. Is there any wrong code or did I miss any code?
#include <Blynk.h>
#include<BlynkSimpleStream.h>
#include <SimpleTimer.h>
#define BLYNK_PRINT Serial
char auth [] = “YYSSwjp6dhd8EvFvK8me7vERbPbv”; // Put your Blynk Auth token
const int echo = 2;
const int trigger = 3;
int led_red = 12;
int led_green = 11;
int pir_in = A3;
int motor = 7;
int Gas1 = A0;
int toluene = 0;
int Gas2 = A1;
int acetone = 0;
int Gas3 = A2;
int ethanol = 0;
float duration, distance;
float paint_qnty = 0;
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
Blynk.begin(Serial, auth);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(2, INPUT);
pinMode(3, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, INPUT);
pinMode(7, OUTPUT);
timer.setInterval(1000L, getSendData);
}
void getSendData()
{
Blynk.virtualWrite(V3, paint_qnty);
toluene = analogRead(Gas1);
Blynk.virtualWrite(V4, toluene);
if (toluene > 1000 )
{
Blynk.notify(“Smoke Detected!”);
}
acetone = analogRead(Gas2);
Blynk.virtualWrite(V5, acetone);
if (acetone > 500 )
{
Blynk.notify(“Smoke Detected!”);
}
ethanol = analogRead(Gas3);
Blynk.virtualWrite(V6, ethanol);
if (ethanol > 1000 )
{
Blynk.notify(“Smoke Detected!”);
}
}
void loop()
{
timer.run();
Blynk.run();
gas();
car();
}
void car(){
int car_in = digitalRead(A3);
if (car_in == 1){
digitalWrite(3, LOW);
delayMicroseconds(2);
digitalWrite(3, HIGH);
delayMicroseconds(1000);
digitalWrite(3, LOW);
duration = pulseIn(2, HIGH);
distance = (duration / 2) / 29.1;
paint_qnty = (distance * 0.01);
//Blynk.virtualWrite(V3, paint_qnty);
// For Serial Monitor
Serial.print(“Paint Quantity (liter): “);
Serial.println(paint_qnty);
Serial.println(””);
if (paint_qnty > 5.5)
{
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
gas();
delay(100);
Serial.print("Toluene Gas Reading (PPM): ");
Serial.println(toluene);
Serial.print("Acetone Gas Reading (PPM): ");
Serial.println(acetone);
Serial.print(“Ethanol Gas Reading (PPM): “);
Serial.println(ethanol);
Serial.println(””);
delay(10);// Delay a little bit to improve simulation performance
}
else if (paint_qnty < 5.5)
{
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
gas();
delay(10);
digitalWrite(7, LOW);
delay(100);
}
}
else
if (car_in == LOW)
{
digitalWrite(3, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
gas();
delay(10);
digitalWrite(7, LOW);
delay(100);
}
}
void gas(){
toluene = analogRead(Gas1);
acetone = analogRead(Gas2);
ethanol = analogRead(Gas3);
if( (toluene > 1000) || (acetone > 500) || (ethanol > 1000) ){
digitalWrite(7, HIGH);
//Blynk.notify(“Hazardous gases detected”);
Serial.println("");
delay(100);
}
else
{
digitalWrite(7, LOW);
delay(100);
}
}