//moisture resistor code
// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int moisturePin = A2;
// Create a variable to hold the light reading
int moistureReading = 0;
// Define a pin we'll place an LED on
int ledPinRed = D0;
// Define a pin we'll place an LED on
int ledPinGreen = D2;
// Create a variable to store the red LED brightness.
int ledBrightnessRed = 0;
// Create a variable to store the green LED brightness.
int ledBrightnessGreen = 0;
// create a threshold to light up red led
int threshold = 1000;
// create a variable to store time when last published
int lastPublished = -1;
//
void setup(){
// Set up the LED for output
pinMode(ledPinRed, OUTPUT);
// Set up the LED for output
pinMode(ledPinGreen, OUTPUT);
// Print the day for the current time
Serial.print(Time.day());
}
void loop() {
moistureReading = analogRead(moisturePin);
// test moisture level
if (moistureReading < threshold) {
digitalWrite(ledPinRed, HIGH); // Turn ON the red LED pins
digitalWrite(ledPinGreen, LOW); // Turn OFF the green LED pins
if (Time.day() != lastPublished) {
// publish event
Particle.publish( "water_your_plant_soon", "Water your plant soon." );
//update lastPublished
lastPublished = Time.day();
}
} else {
digitalWrite(ledPinGreen, HIGH); // Turn ON the green LED pins
digitalWrite(ledPinRed, LOW); // Turn OFF the red LED pins
}
// wait 1/10th of a second and then loop
delay(100);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .