Pages: 1 [2]   Go Down
Author Topic: moisture sensors  (Read 1345 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

example please
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50039
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
example please
Code:
void loop()
{
   int val0 = analogRead(A0);
   int val1 = analogRead(A1);
   int val2 = analogRead(A1);
   int val3 = analogRead(A3);

   if(val0 < MOISTURE_LEVEL)
      digitalWrite(valvePin0, HIGH);
   else
       digitalWrite(valvePin0, LOW);

   // replicate for the other 3 valve pins

   if(val0 < MOISTURE_LEVEL ||
       val1< MOISTURE_LEVEL ||
       val2< MOISTURE_LEVEL ||
       val3< MOISTURE_LEVEL)
   {
      digitalWrite(pumpPin, HIGH);
   }
   else
   {
      digitalWrite(pumpPin, LOW);
   }
}

What this is doing is opening the correct valve if a sensor is dry, and then, if any sensor is dry, turning the pump on.

Notice that the action of opening a valve is separated from the action of turning the pump on, because the pump condition is dependent on any sensor, while the valves are dependent on a specific sensor.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanku ill give this a try....
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It works perfect thank u so much.....if i were to add buttons would i do them the same ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

again thank you....this is what i've come up with so for all of it works....
Code:

const int TxPin = 6;       //lcd pin
const int relayPin1 = 4;  //pins that are for
const int relayPin2 = 3;  //buttons to open valves
const int relayPin3 = 2;                       // and pumps
const int relayPin4 = 5;
const int relayPin5 = 7;
const int pumpPin = 9;        //pin that turns on the pump   
const int valvePin1 = 13;        //pins that run valves
const int valvePin2 = 12;       
const int valvePin3 = 11;
const int valvePin4 = 10;
const int PROBE1=A0, PROBE2=A1, PROBE3=A2, PROBE4=A3;
int MOISTURE_LEVEL = 250;                              //the value after the valves and pump goes ON


#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);



void setup() {

   pinMode(relayPin5, OUTPUT); 
   pinMode(relayPin4, OUTPUT);   
   pinMode(relayPin1, OUTPUT);   
   pinMode(relayPin2, OUTPUT);   
   pinMode(relayPin3, OUTPUT);   
   pinMode(pumpPin,OUTPUT);    // sets pumpPin to output
   pinMode(valvePin1,OUTPUT);    // sets valvePins to output
   pinMode(valvePin2,OUTPUT);
   pinMode(valvePin3,OUTPUT);
   pinMode(valvePin4,OUTPUT);
   pinMode(TxPin, OUTPUT);          //lcd pin to output
   digitalWrite(TxPin, HIGH);         
   digitalWrite(pumpPin, LOW);     
   digitalWrite  (valvePin1,LOW);
   digitalWrite(valvePin2,LOW);
   digitalWrite(valvePin3,LOW);
   digitalWrite(valvePin4,LOW);
   digitalWrite(relayPin1,LOW);
   digitalWrite(relayPin2,LOW);
   digitalWrite(relayPin3,LOW);
   digitalWrite(relayPin4,LOW);
   digitalWrite(relayPin5,LOW);
   mySerial.begin(9600);
   mySerial.write(22);                // turns display on
   mySerial.write(17);                // turn on lcd back light   
   mySerial.write(12);                 // Clear  LCD
   delay(5);                          //required delay after clear Lcd
}





void loop()
{
   int val0 = analogRead(A0);
   int val1 = analogRead(A1);
   int val2 = analogRead(A2);
   int val3 = analogRead(A3); 
   
   mySerial.write(128);
  mySerial.print("S1-");
   mySerial.write(148); 
  mySerial.print( "S2-"); 
  mySerial.write(168);
  mySerial.print("S3-");
   mySerial.write(188); 
  mySerial.print( "S4-"); 
   mySerial.write(132); 
  mySerial.print (analogRead(A0));
   mySerial.write(152); 
  mySerial.print (analogRead(A1));
   mySerial.write(172);
  mySerial.print (analogRead(A2));
    mySerial.write(192);
  mySerial.print (analogRead(A3));
   
   
   if(val0 < MOISTURE_LEVEL)
 {
      digitalWrite(valvePin1, HIGH);
      digitalWrite(relayPin1, HIGH);
 }     
 else
 {
       digitalWrite(valvePin1, LOW);
       digitalWrite(relayPin1, LOW);
 }   
   if(val1 < MOISTURE_LEVEL)
  {
      digitalWrite(valvePin2, HIGH);
      digitalWrite(relayPin2, HIGH);
  }
   else
   {
       digitalWrite(valvePin2, LOW);
       digitalWrite(relayPin2, LOW);
   }       
   if(val2 < MOISTURE_LEVEL)
   {
      digitalWrite(valvePin3, HIGH);
      digitalWrite(relayPin3, HIGH);
   }
   else
   {
       digitalWrite(valvePin3, LOW);
       digitalWrite(relayPin3, LOW);
   }           
   if(val3 < MOISTURE_LEVEL)
   {
      digitalWrite(valvePin4, HIGH);
      digitalWrite(relayPin4, HIGH);
   }
   else
   {
       digitalWrite(valvePin4, LOW);
        digitalWrite(relayPin4, LOW);
   }
   if(val0 < MOISTURE_LEVEL ||
       val1< MOISTURE_LEVEL ||
       val2< MOISTURE_LEVEL ||
       val3< MOISTURE_LEVEL)
   {
      digitalWrite(pumpPin, HIGH);
      digitalWrite(relayPin5, HIGH);
   }
   else
   {
      digitalWrite(pumpPin, LOW);
      digitalWrite(relayPin5, LOW);
   }
}
i would love to add buttons to control each valve..
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50039
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should create an lcdInit() function, and another function to write that data to the LCD. Why are you reading from the analog pins again? You should be printing the values in val0, val1, val2, and val3.

You have not defined any switch pins, set them to INPUT, enabled any pullup resistors, or read any switch states.

What do the relay pins control? What do the valve pins control? Will the switch pins override the moisture sensors?

When do you plan to learn about arrays? Functions?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the valvepin  are  leds to show which valves are open and the pump is on...the relaypins control one pump and four valves. i ve been reading about arrays but really dont understand them or how i would use them....
Logged

Pages: 1 [2]   Go Up
Jump to: