Go Down

Topic: How to use EEPROM to save my settings value while the program is running. (Read 352 times) previous topic - next topic

UdDReX

I was trying to make an automated water pump control system using ultrasonic sensor and use Bluetooth for serial monitoring and to change settings(where I never used EEPROM before). But as I wrote the code, everything works except the settings part. I comment out the part which I had the problem. Also, any sort of extra help in optimizing the code is welcomed.

Plz, help me with this code running asap.

PaulS

Code: [Select]
    Serial.println(Serial.available());
Why are you doing that?

Code: [Select]
          realh=Serial.read();
You read ONE character. Must be a pretty short tank - less than 10 cm tall.

You don't seem to have a clue that the Arduino is not waiting (and should not wait) for serial data to arrive.

Code: [Select]
          Serial.print("Enter Your Minimum value (in cm)");
          while(Serial.available()>0)
          {
            if(Serial.available()>0)
            {
              maxi=Serial.read();

Why are you storing the minimum value in maxi?

Code: [Select]
              Serial.print("Enter Your Maximum value (in cm)");
              while(Serial.available()>0)
              {
                if(Serial.available()>0)
                {
                  mini=Serial.read();

Why are you storing the maximum value in mini?

The art of getting good answers lies in asking good questions.

UdDReX

10 cm is because the ultrasonic sensor will be at the top of the tank, so when the tank will be full when I want the distance between the ultrasonic sensor and water level to be 10 cm. 10 is not the depth of the tank.

Code: [Select]
Serial.println(Serial.available());

I used it for using the settings. Just for the beginning, I wanted to change the setting using serial monitor. so.

Quote
You don't seem to have a clue that the Arduino is not waiting (and should not wait) for serial data to arrive.
I know and that's my real problem. I'm not getting the idea how to make my Arduino wait. That's why the whole part is not working for me. I want you could make it work.

Quote
Why are you storing the minimum value in maxi?

Code: [Select]
              Serial.print("Enter Your Maximum value (in cm)");
              while(Serial.available()>0)
              {
                if(Serial.available()>0)
                {
                  mini=Serial.read();

Why are you storing the maximum value in the mini?
"minimum" is the minimum height water level can reach before the relay starts the pump. but since the ultrasonic sensor is at the top, so for it the value in greater...

Similarly "maximum" is how high the water level should reach before the pump stops. But for Arduino, that value is smaller.

The whole point is that I made it jst for my convenience.

I think that whole setting part might be wrong. I want help in correcting that whole part and make it work.

sterretje

Read the updated Serial Input Basics thread ti get ideas how to handle serial input.

The codes (example 2 and 3) use a flag (newData) to indicate that a complete message has arrived.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

PaulS

Quote
I'm not getting the idea how to make my Arduino wait.
Why should it wait? You posted on the forum. Are you sitting in front of your computer waiting for a response? Or are you able to do other things, like breathing, sleeping, and/or eating, while periodically checking for a reply? When you DO get a reply, can you remember what the question was?

Well, write your program the same way.
The art of getting good answers lies in asking good questions.

Go Up