HELP sensors Alarm

Hi for All

First i made source code its for sending sensors data to thingspeak over tcp/ip protocol using EthernetShield module its work 100% in this project i use 3 sensors ( MQ2 ,Ultrasonic,DHT11)

I want set a stable value for each sensor buzzer turn ON when the measured value is greater than the stable one

i tried this but the buzzer doesn’t work

how i fix it ?

#include <ThingSpeak.h>
#include <DHT.h>        // You have to download DHT11  library
#include <SPI.h>
#include <Ethernet.h>
#ifdef SPARK
#include "ThingSpeak/ThingSpeak.h"    // You have to download ThingSpeak  library
#else
#include "ThingSpeak.h"
#endif
#define WRITE_DELAY_FOR_THINGSPEAK 15000
#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define echoPin 9 // Echo Pin
#define trigPin 8 // Trigger Pin


// Stables Vlues
int gasLimit = 400;// stable value for gas sensor 
int distanceLimit = 5;// stable value for ultrasonic sensor 
int DHTLimit = 50;// stable value for DHT sensor (just temperature)
int waterLimit = 200;// stable value for gas sensor

int buzzer = 10; 
int smokeA0 = A5;
const int sensorPin = 0; //sensor pin connected to analog pin A0
int liquid_level;
long duration, distance; // Duration used to calculate distance
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 8, 20);                          //Check your router IP
EthernetClient client;

unsigned long mySensorsChannelNumber = xxxxx;            //Replase this code with your thingSpeak channel ID
//unsigned long myCommandsChannelNumber = xxxxx;           //Replase this code with your thingSpeak channel ID
const char * myWriteAPIKey_sensors = "xxxxxxxxxxxxx";  //Replace with your channel Write Key
//const char * myWriteAPIKey_commands = "LS2VSRY127ZZIH1H"; //Replace with your channel Write Key. This key is not used in this example
//Use this key from android device

long lastWriteTime = 0;
long lastReadTime = 0;
float responseValue = 0;

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  ThingSpeak.begin(client);
  dht.begin();

  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT); //Trigger    FW
  pinMode(9, INPUT);  //Echo
  pinMode(sensorPin, INPUT);//the liquid level sensor will be an input to the arduino
  pinMode(4, INPUT);
  Serial.println("Setup completed");
  delay(1000);
}
void loop() {

  //-------- Example 1 write DHT11 sensors' values to thingSpeak channel sensors
  long duration1, distance1;
  int analogSensor = analogRead(smokeA0);
  liquid_level = analogRead(sensorPin) - 565; //arduino reads the value from the liquid level sensor
  delay(1000);

  if (millis() - lastWriteTime > 20000) {   // every 20 secs.  Must be >15000.
    Serial.println("Read sensors' values...");
    // FW 1 pin distance calculation
    digitalWrite(8, LOW);
    delayMicroseconds(2);
    digitalWrite(8, HIGH);
    delayMicroseconds(10);
    digitalWrite(8, LOW);
    duration1 = pulseIn(9, HIGH);
    distance1 = (duration1 / 2) / 29.1;
    delay(500);

    float u = distance1 ;
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    float g = analogRead(smokeA0);
    float w = liquid_level;

    if (isnan(t) || isnan(h)) {
      Serial.println("Failed to read from DHT");
    }
    else {
      Serial.println("Temp=" + String(t) + " C");
      Serial.println("Humidity=" + String(h) + " %");
      Serial.println("distance=" + String(u) + " cm");
      Serial.println("gas=" + String(g) + " Btu");
      Serial.println("level water=" + String(w) + " ml");
      ThingSpeak.setField(1, t);
      ThingSpeak.setField(2, h);
      ThingSpeak.setField(3, u);
      ThingSpeak.setField(4, g);
      ThingSpeak.setField(5, w);
      ThingSpeak.writeFields(mySensorsChannelNumber, myWriteAPIKey_sensors);                  // write two values
      lastWriteTime = millis();             // store last write time
    }
  }
  delay(8000);
  
    if(analogSensor > gasLimit)//for gas sensor 
{
  tone(buzzer,1000);
  
}
else{
  noTone(buzzer);
  
 }
 delay(100);
  
    if(liquid_level > waterLimit)//for water level sensor 
{
  tone(buzzer,1000);
  
}
else{
  noTone(buzzer);
  
 }
 delay(100);
 
  if(distance1 > distanceLimit)//for ultrasonic sensor 
{
  tone(buzzer,1000);
  
}
else{
  noTone(buzzer);
  
 }
 delay(100);
   if(dht.readTemperature() > DHTLimit)//for ultrasonic sensor 
{
  tone(buzzer,1000);
  
}
else{
  noTone(buzzer);
  
 }
 delay(100);
 
}

Can you post some errors you get ehn compiling the code?

Qoutroy:
Can you post some errors you get ehn compiling the code?

Qoutroy:
Can you post some errors you get ehn compiling the code?

there is no errors in compiling