I tried to upload this sketch it contains vibration detector with other different detectors, but I have this problem that I don't understand in the void loop section of the vibration sketch

Here is the problem :

C:\Users\younes\Desktop\ALLTogether\ALLTogether.ino: In function 'long int vibration()':
C:\Users\younes\Desktop\ALLTogether\ALLTogether.ino:153:5: warning: return-statement with no value, in function returning 'long int' [-fpermissive]
return;

And the Program

#include "DHT.h"

#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define ventilo 4

int maxHum = 85;
int maxTemp = 30;

DHT dht(DHTPIN, DHTTYPE);

int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A0;
// Your threshold value
int sensorThres = 50;

#define LED_PIN 5
#define POWER_PIN 7
#define SIGNAL_PIN A5
#define THRESHOLD 300
int value = 0; // variable to store the sensor value

int vs=A4;// vibration sensor
int led=13;
int BUZZER=10;

void setup() {

Serial.begin(9600);
pinMode(LED_PIN, OUTPUT); // configure D2 pin as an OUTPUT
pinMode(POWER_PIN, OUTPUT); // configure D7 pin as an OUTPUT

digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
digitalWrite(LED_PIN, LOW); // turn LED OFF

pinMode(led,OUTPUT);
pinMode(BUZZER,OUTPUT);
pinMode(vs,INPUT);
Serial.begin(9600);

{Serial.begin(9600);
pinMode(ventilo, OUTPUT);

dht.begin();
}
{Serial.begin(9600);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(ventilo, OUTPUT);
pinMode(smokeA0, INPUT);

}
}

void loop() {

digitalWrite(POWER_PIN, HIGH); // turn the sensor ON
delay(10); // wait 10 milliseconds
value = analogRead(SIGNAL_PIN); // read the analog value from sensor
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF

if (value > THRESHOLD) {
Serial.print("The water is detected");
digitalWrite(LED_PIN, HIGH);// turn LED ON

} else {
digitalWrite(LED_PIN, LOW);   // turn LED OFF

}
long measurement=vibration();
delay(200);
Serial.println(measurement);
if(measurement>5000){
digitalWrite(led,HIGH);
digitalWrite(BUZZER,HIGH);
}
else{
digitalWrite(led,LOW);
digitalWrite(BUZZER,LOW);
}
}

long vibration(){
long measurement=pulseIn(vs,HIGH); //wait for the pin to get HIGH and returns measurement
return measurement;

// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C ");
{
int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");
Serial.println(analogSensor);
//Cheks if it has reached the threshold value
digitalWrite(buzzer, LOW);
digitalWrite(greenLed, HIGH);
digitalWrite(ventilo, LOW);
digitalWrite(redLed, LOW);
if(analogSensor > sensorThres)
{digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(ventilo, HIGH);
digitalWrite(buzzer, HIGH);
}else if(h > maxHum || t > maxTemp)
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
digitalWrite(ventilo, HIGH);
digitalWrite(buzzer, LOW);
}

}delay(100);

}

Your code is incomplete.
Please remember to use code tags when posting code.

Please don't post pictures of error messages, post error messages.

I changed it please take a look

You forgot to properly format the code in the IDE,
and did not use code tags as requested.

The compiler is correct.
I'm guessing you're missing another function

Please remember to use code tags when posting code

What are code tags I don't understand

All explained here

The error is pretty clear. You have a function, virbration() that returns a long value. The second line of the function does just that. Everything else after that never gets executed, but the compiler sees (one line 153) a bare return statement

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
...

and complains about it.

It makes no sense to have code after a return.

Is there a solution? I am a totale newbie at arduino

There is a solution for

  • unformatted code
  • posted code without code tags

Looking at that, your code will never reach the delay.

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.