Serial monitor keeps printing "14"

Hello,
I was playing with a cheap soil humidity sensor, hooked it up properly and wrote a code, but no matter what I do the serial monitor keeps printing "14". I tried several codes and none of them seemed to change anything. I even tried another arduino board.

int sensorPin = A0;

void setup() {
  Serial.begin(9600);
  
  
}

void loop() {
  int hum = analogRead(sensorPin);
  serial.print(hum);
  delay(1000);

}

I'm a real noob when it comes to arduino and programming but I didn't find any answers on the internet and I want to learn how to avoid mistakes like this one.

Cheers, smart people :slight_smile:

It's pretty common for sensors to be associated with some form of library, often requiring a #include <libraryname.h> directive near the top of the source file. Does the sensor you're using not use any libraries in the code examples?

I've checked few tutorials and there is no libraries included, or I'm just extremely retarded.
Even if it needed one, why "14" over and over again? Maybe there's something wrong with the sensor.
I've done much much more complicated projects and had no problems, now I cant even get it to print sensor's value.

I'll keep trying to fix it.

Please post your actual code.
A0 == 14.

I did, that's all. I wanted to work further but if I cant get propper values there is no point in doing more of it.

No, post your code as it appears in the IDE, not some junk that doesn't compile, or what you think your code looks like.

Don't call my code junk, it DOES compile and that's really it.
Really, I didn't write anything more 'cause I got upset with what I have so far.
As I said I don't really know much about programming but all my projects went without problems.

serial.print(hum);

Tell me about "serial".

Honestly I changed the code so many times that I made this mistake probably after fifth take on it but it doesn't change anything at all.

So, post your code as it is now, and post the results it produces.

His point being that your posted code don't compile, therefore you couldn't possibly have tested it!

As I said the code I posted does compile in my case and it keeps repeating "14".
I'm a little ashamed that I got angry while You were trying to help me, I just got it to work, deleted the old code and wrote it differently.

    void setup(){
       
      Serial.begin(9600);
       
    }
     
    void loop(){
       
      Serial.print("Sensor Value:");
      Serial.println(analogRead(A0));  
      delay(500);
     
      }

Anyway, thanks for trying to help. I'll try to keep calm next time.

1 Like

Your code looks fine.
Are you sure you have this version uploaded into your Arduino?

Get out your multimeter and measure the voltage on A0.

Just maybe 14 is the correct number.

Connect A0 alternately to GND and to 5v and see what results you get - you should get 0 and 1023

And @LarryD has good advice. Not realizing that the new program has not uploaded has stumped me a few times.

...R

Nalesnik:
I just got it to work, deleted the old code and wrote it differently.

I've dealt with my problem, just sat down, wrote a new code and it works great.
Thank you all!

I would say it is rare to an analog sensor alllways giving you exactly the same reading 14. It means something like 14/1024*5V or so. Usually sensors can't make up their mind. Can you measure voltage from the sensor?

With new code it works, no need to measure anything.
Thank you for willing to help.

I would be interested in seeing the new code that works.

You're welcome

When I wrote that I got it to work I meant the sensor works. It's the second code that i posted.

    void setup(){
       
      Serial.begin(9600);
       
    }
     
    void loop(){
       
      Serial.print("Sensor Value:");
      Serial.println(analogRead(A0));  
      delay(500);
     
      }