//Global--------------------------------------------------------------––––––––––––––––––––––––––––––––––––––––––––––––
//PIN SETUP
//Moisture Read
int sensorPin = A0;
int Moisture_Feed = D0;
//Temperature
int Temp_Read = A2;
int Temp_Feed = D2;
//Light_Value = A1
int PR_Read = A1;
int PR_Feed = D1;
//LEDs
int Blue_LED = D6;
int Green_LED = D5;
//Timer
void print_every_second()
{
static int count = 0;
Serial.println(count++);
}
Timer timer(1000, print_every_second);
//SETUP--------------------------------------------------------------––––––––––––––––––––––––––––––––––––––––––––––––
void setup(){
//Creating feed for PR
//Moisture Feed
pinMode(Moisture_Feed, OUTPUT);
//Temperature Feed
pinMode(Temp_Feed, OUTPUT);
//Temperature Feed
pinMode(Temp_Feed, OUTPUT);
//LED Feed
pinMode(Blue_LED, OUTPUT);
pinMode(Green_LED, OUTPUT);
//Light
//3.3V
//Setting up Monitor
Serial.begin(9600); // set up serial port for 9600 baud (speed)
delay(500); // wait for display to boot up
}
//LOOP--------------------------------------------------------------––––––––––––––––––––––––––––––––––––––––––––––––
void loop(){
//Mositure FEED
digitalWrite(Moisture_Feed, HIGH);
//Sesnor Readins
//Moisture
int Moisture_Value;
Moisture_Value = analogRead(sensorPin);
if (Moisture_Value < 2500) {
digitalWrite(Blue_LED, HIGH);}
if (Moisture_Value > 2500) {
digitalWrite(Blue_LED, LOW);}
//Light
int Light_Value;
Light_Value = analogRead(PR_Read);
if (Light_Value < 300) {
digitalWrite(Green_LED, HIGH);}
if (Light_Value > 400) {
digitalWrite(Green_LED, LOW);}
//Temperature
int Temp_Value;
Temp_Value = analogRead(Temp_Read);
//Converts to Signal to Voltage
//sensorValue = ((analogRead(D1)/40));
//sensorValue = sensorValue/100;
//sensorValue = sensorValue*3.3;
//Publish Moisture
//Took between if function from:
//http://forum.arduino.cc/index.php?topic=327601.0
if (0 <= Moisture_Value && Moisture_Value <= 2500){ // between
Spark.publish("Moisture", String("Ready to be water.") + "");
//Timer Non-nagginess
timer.start();
};
delay(500);
if (2501 <= Moisture_Value && Moisture_Value <= 3500){ // between
Spark.publish("Moisture", String("Still moist.") + "");
timer.reset();
};
delay(500);
if (3501 <= Moisture_Value && Moisture_Value <= 5000){ // between
Spark.publish("Moisture", String("Wet.") + "");
timer.reset();
};
delay(500);
//Spark.publish("Moisture", String(Moisture_Value) + " fq");
//Publish Light
if (0 <= Light_Value && Light_Value <= 200){ // between
Spark.publish("Light", String("Too dark.") + "");
};
delay(500);
if (251 <= Light_Value && Light_Value <= 380){ // between
Spark.publish("Light", String("Dim.") + "");
};
delay(500);
if (381 <= Light_Value && Light_Value <= 600){ // between
Spark.publish("Light", String("Well Lit.") + "");
};
delay(500);
if (601 <= Light_Value && Light_Value <= 1000){ // between
Spark.publish("Light", String("Bright") + "");
};
delay(500);
//SERIAL DEBUG--------------------------------------------------------------––––––––––––––––––––––––––––––––––––––––––––––––
//Debugging Serial
//Moisture:
//Serial.print("Moisture:");
//Serial.println(Moisture_Value);
//Light
//Serial.print("Light:");
//Serial.println(Light_Value);
//Temperature:
//Serial.print("Temparature:");
//Serial.println(Temp_Value);
delay(500);
}
//--------------------------------------------------------------––––––––––––––––––––––––––––––––––––––––––––––––
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. .