hello again as im a newbie , i need some help adding in to the Sketch 1e] below
const int analogPin = A2; // if water level sensor module attached to analog pin A0 of Arduino Uno
//const int digitalPin = 7; // if water level sensor module attached to digital pin 7 of Arduino Uno
int thresholdValue = 200;//you can adjust the threshold value
const int relayPin = 6;//5v relay module attached to digital pin 6 of Arduino Uno
/********************************/
void setup() {
Serial.begin(9600); // initialize serial communications at 9600 bps
pinMode(relayPin, OUTPUT);//sets the relayPin as OUTPUT
digitalWrite(relayPin, HIGH);
}
void loop() {
int analogValue = analogRead(analogPin);//analog value from soil moisture sensor
// int digitalValue = digitalRead(digitalPin);//digital value from soil moisture sensor
Serial.print("Sensor value: ");// send the value from the sensor to serial monitor
Serial.print(analogValue);// send the value from the sensor to serial monitor
Serial.print(" ;");
// Serial.print("Sensor status:");
// Serial.println(digitalValue);// send the value from the sensor to serial monitor
if (analogValue >= thresholdValue) {
Serial.print(" - Water level is HIGH");
digitalWrite(relayPin, HIGH);
Serial.println(" - Pump is off");
}
else {
Serial.print(" - Water level is LOW");
digitalWrite(relayPin, LOW);
Serial.println(" - Pump is on");
/*
if (digitalValue = 1) {
Serial.println(" - Alarm!!! Water level is high");
}
else {
Serial.println(" - Water level is low");
}
*/
}
delay(200); //sets delay for 200 ms
}
now how i would power on the sensor only for short moments .Im trying follow the example from sketch 2 .
// Define our pins.
const int soil = A0;
const int power = 12;
// Define our timer.
const int TIMER = 60; // in seconds
const int RESET = TIMER - 1;
const int SENSOR_DELAY = 10; // in milliseconds
int counter;
void setup() {
pinMode(soil, INPUT);
pinMode(power, OUTPUT);
// Start with sensor OFF
digitalWrite(power, LOW);
// Setup timer.
counter = RESET;
// Setup serial plotter.
Serial.begin(9600);
}
void loop() {
// If the counter is at the end of a cycle
// take a new reading and reset counter.
if (counter <= 0) {
// Turn sensor ON and wait a moment.
digitalWrite(power, HIGH);
delay(SENSOR_DELAY);
// Take reading, send to plotter.
Serial.println(analogRead(soil));
// Turn sensor OFF again.
digitalWrite(power, LOW);
// Start new countdown.
counter = RESET;
}
// If counter isn't at the end yet, pause for
// the same amount of time as if the sensor
// had been activated to keep things in sync.
else {
delay(SENSOR_DELAY);
}
// Decrement counter and delay until next second.
counter--;
delay(1000 - SENSOR_DELAY);
}
How would put this together .Thanks