help needed with millis()

hello,
for my school project i decided to make a watering system based on the uno board.
the system will read an analog value wich will be 2 electrodes planted in the soil (the signal is amplified with an op-amp) and will output a digital 1 that is hooked to a mosfet then to a relay to power the electro-vanne if the value is higher then 200.

also i have a 16*2 display that displays temp and soil moisture.

this is the code i wrote :

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  lcd.begin(16, 2);
  pinMode(10, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  Serial.println(1/(analogRead(A0)/1023.0));
  if(analogRead(A0)>=200){digitalWrite(10, 1);}           
  if(analogRead(A0)<200){digitalWrite(10, 0);}
  disp();
}
void disp(){
int rawvoltage1= analogRead(A1); //lm335 hooked to a1
float millivolts1= (rawvoltage1/1024.0) * 5000;
float humid =map(analogRead(A0), 0, 1023, 0, 50);
float humid2 = (1.0/(humid/100.0));
int kelvin= (millivolts1/10);
int celsius= kelvin - 278.15;
 lcd.setCursor(0,0);
 lcd.print("tp:");
 lcd.print(celsius);
 lcd.print(",hmd:");
 lcd.print(humid2);
 lcd.print("%");
 delay(100);
 lcd.clear();
}

Now i want to add a manual funtion that enables the user to set trought 3 push botons ( 2 to set value and 1 to confirm ) a value in minutes (from 1 to 100) , the relay needs to be turned on for that amont of time while he can turn it off at any moment.

thank you in advance .

Have you attempted to write such a program? If so please post it.

If not start with a new program that does the reading of the switches and counting.

Start using pseudo code to work out the logic then convert this to actual code.

If switchUp is pressed Increment minuteCount If switchDown is pressed Decrement minuteCount

Etc

Weedpharma

Usually, when you have a float data type on the left side of the equal sign:

float millivolts1 = (rawvoltage1/1024.0) * 5000;
float humid = map(analogRead(A0), 0, 1023, 0, 50);

it's a good idea to express all constants as floating point numbers:

float millivolts1 = (rawvoltage1/1024.0) * 5000.0;
float humid = (float) map(analogRead(A0), 0, 1023, 0, 50);

That may not fix your problem, but it can't hurt and it helps document what you're doing.

the probleme i have is that i know nothing about timers or the millis fonction. if i had a "minute" variable that stores the actual minutes that have passed my probleme will be technically solved.

Why do timers and the millis() function solve your problems? I don't see anything touching those topics in your code.

to refomulate my request .

how do i use millis() to make a int count(value){} that counts minutes and stores it in "minutes" variable then resets it to 0 if minutes is higher then value and returns 1.

Since 1000 millisecond is one second and you need 1 minute (or more), 60,000 milliseconds is a minute. So, start a timer with:

  long startTimer = millis();

   // do your code processing and when you're done...

  long endTimer = millis();

  int minutesPassed = (int) ( (endTimer - startTimer) / 60000L);

Your control logic depends upon what you want to do.

thank you econjack now i see what i need to do .

i will post the finished code when im done.

totalnewbie: to refomulate my request .

how do i use millis() to make a int count(value){} that counts minutes and stores it in "minutes" variable then resets it to 0 if minutes is higher then value and returns 1.

I don't think that is a sensible way to think of the problem. There is no technical advantage in converting millis() to minutes.

Have a look at how millis() is used to manage timing in several things at a time. You will probably also get some useful ideas for your project in planning and implementing a program.

You also need to keep in mind that millis() does not keep time as accurately as a Real Time Clock (RTC) module because the Arduino does not run at precisely 16 MHz. If you want to stay in step with clock time over a long period you will need an RTC.

...R