Timelimit and cooldown on pwm out

Hi!

Totally noob to Arduino but think I got the basics, so bare with me..

Long story short, I'm setting up a soilmoisture and automatic water system.

Got this code working out well. (post at the end)

Now I want to get going with the "if" and "else" commands.

if (sensorVal1 > 380 ){
digitalWrite(pump1, HIGH);
//I want this one to only stay HIGH for 10seconds, and then turn off and wait for another 15minutes to check the values again (and turn on again if the values are >380)

Should i read more about the "milli" coding?
All help appriciated :slight_smile:

CODE:

#define soilSensor1 A0
#define soilSensor2 A1

#define pump1 2
#define pump2 3

const int dry = 523;
const int wet = 297;

void setup() {
pinMode(pump1, OUTPUT);
pinMode(pump2, OUTPUT);

Serial.begin(9600);
}

void loop() {

int sensorVal1 = analogRead(soilSensor1);
int percentageHumididy = map(sensorVal1, wet, dry, 100, 0)
;Serial.print(" Sensor 1 = ");
Serial.print(percentageHumididy);
Serial.println("%");

int sensorVal2 = analogRead(soilSensor2);
int percentageHumididy2 = map(sensorVal2, wet, dry, 100, 0)
;Serial.print(" Sensor 2 = ");
Serial.print(percentageHumididy2);
Serial.println("%");

if (sensorVal1 > 380 ){
digitalWrite(pump1, HIGH);
} else {
digitalWrite(pump1, LOW);
}

if (sensorVal2 > 450 ){
digitalWrite(pump2, HIGH);
} else {
digitalWrite(pump2, LOW);
}
delay(1000);
}

Write a separate sketch having a play with millis(), using the blink with out delay example in the IDE , just switching say the built in led in and off .
Try writing something simple with if /else .

If you google say “ Arduino if” you will find examples in its use .

Get that working , then have a go at putting that in your sketch .

This is the best way to learn stuff , have a go and report back ..

If your Arduino doesn't have anything else to do, you can take care of the "on for 10 seconds" part with delay(10000);

I would use the BlinkWithoutDelay example for the "do every 15 minutes" part. Remember that once you get beyond 32 seconds you need to use 'unsigned long' variables instead of 'int'.

const unsigned long Seconds = 1000;
const unsigned long Minutes = 60 * Seconds;
unsigned long PreviousMillis = 0;

void loop()
{
  if (millis() - PreviousMillis >= 15 * Minutes)
  {
    PreviousMillis += 15 * Minutes;
    if (sensorVal1 > 380 )
    {
      digitalWrite(pump1, HIGH);
      delay(10000);
      digitalWrite(pump1, LOW);
    }
  }
}

Thanks, that worked out great for now :slight_smile:

YES
And addtional spend some time and study the usage of the instruction STRUC and ARRAY.
With these instructions for OOP you are able to design objects per soil sensor and pump. Thus will bring you to compact and maintaible sketch with groth potentioal for more pumps and soil sensors.
Have a nice day and enjoy coding in C++.

Thanks for the replies guys, much appreciated :slight_smile:

Now my plan is to get Visual studio to read these values.. Found a lot of videos on youtube, and forums all over, but I really dont know where to start on the coding/project. (read: I dont know exactly what to search for..)

What i want is the circular_progress_bar (or if you recommend something else, tell me) in Visual studio to show the soil moisture (analog 1 and analog 2 on the arduino)

As mentioned, I'm really new to this, but find it very interesting and want to learn more.

Questions related to this project:
If I use Visual studio and make a new project with Windows form app (.NET framework) visual basic, do I have to read up on C?
Is all programming through Visual studio if i want this to work, or can I keep the coding I allready have in the arduino software and take readings from this (noob talk sry :stuck_out_tongue: )?

Anyway, thanks for the replies so far! Fast learner, I just need the basics

Your desire to have a VB interface with your Arduino requires several steps of learning that would be difficult to include in a single post. Because this thread seems to be completed you really need to start another thread in a more appropriate category of this forum eg. Interfacing w/ Software on the Computer. If you create a thread there and name it something along the lines "Interface Arduino to VB for the beginner" I will attempt to answer some of your questions, just be sure to have Visual Studio on a PC that you have access to and tell us what experience you have with VB.

I see, thanks alot for the reply :slight_smile:

(post deleted by author)

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.