My serial monitor isn't working

My Serial monitor isn't functioning it is coded to show me the water levels as an analog output and was functioning well the first tries but know it only shows "o" zero I need help

int pump =2;
int sensorPower =6;
int sensorpin =A0;
int threshold =700;
int waterdelay =750;
int waterpostdelay =5000;

void setup(){
     pinMode(sensorpin, INPUT);
     pinMode(pump, OUTPUT);
     Serial.begin(9600);
}

void loop(){
     int SensorValue = analogRead(sensorpin);
     if(SensorValue <=threshold){
           digitalWrite(pump, HIGH);
           delay(waterdelay);
           digitalWrite(pump, LOW);
           delay(waterpostdelay);
     }
     else{
      digitalWrite(pump, LOW);
     }
     Serial.print("Analog output: ");
     Serial.println(readSensor());
     delay(1000);
}

int readSensor() {
  digitalWrite(sensorPower, HIGH);
  delay(10);
  int val =analogRead(sensorpin);
  digitalWrite(sensorPower, LOW);
}
```That is the code I used but the serial monitor shows 
Analog output : 0   everytime I upload the code

Welcome to the forum

Your readSensor() function does not return a value. You will have received warnings about that if you have verbose reporting turned on

C:\Users\Bob2\AppData\Local\Temp\.arduinoIDE-unsaved202449-4916-8ytqwn.5cngt\sketch_may9a\sketch_may9a.ino: In function 'int readSensor()':
C:\Users\Bob2\AppData\Local\Temp\.arduinoIDE-unsaved202449-4916-8ytqwn.5cngt\sketch_may9a\sketch_may9a.ino:38:9: warning: unused variable 'val' [-Wunused-variable]
C:\Users\Bob2\AppData\Local\Temp\.arduinoIDE-unsaved202449-4916-8ytqwn.5cngt\sketch_may9a\sketch_may9a.ino:40:1: warning: no return statement in function returning non-void [-Wreturn-type]

Thanks it actually worked I had missed the return val

It's the compiler warning setting, not the verbose output :slight_smile:

@jayson45tfgjhvgytfjk, set it to All

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.