//Change only these values to change the code such as which pins are inputs/outputs and threshold values int Moist_in = A0; //Pin that will receive an analog signal for Moisture int Temp_in = A2; //Pin that will receive an analog signal for Temperature int Light_in = A3; //Pin that will receive an analog signal for Light int Moist_out_0 = 2;//Pin that will output a digital value for the Most Significant Bit for Moisture int Moist_out_1 = 3;//Pin that will output a digital value for the second bit for Moisture int Moist_out_2 = 4;//Pin that will output a digital value for the Least Significant Bit for Moisture int Temp_out = 6; //Pin that will output a digital value for Temperature int Light_out = 8; //Pin that will output a digital value for Light int Light_thresh = 5; //The analog threshold value for when the signal should change for Light int Temp_thresh = 155; //The analog threshold value for when the signal should change for Temperature int Moist_thresh = 850;//Larger value makes it water to a higher moisture level int DelayTime = 1000;//Delay Time in milliseconds //global variable for functions float Temp; float Light; float Moist; int Mst; void setup() { pinMode(Moist_in, INPUT); pinMode(Temp_in, INPUT); pinMode(Light_in, INPUT); pinMode(Moist_out_0, OUTPUT); pinMode(Moist_out_1, OUTPUT); pinMode(Moist_out_2, OUTPUT); pinMode(Temp_out, OUTPUT); pinMode(Light_out, OUTPUT); Serial.begin(9600); } void loop() { TmpSensor(); //Check Temperature (should output 1 bit) LightSensor(); //Check Light (should output 1 bit) MoistureSensor(); //Check Moisture (should output 3 bits) delay(DelayTime); //Delay Check Time Serial.println(); } void LightSensor(){ Light = analogRead(Light_in); Serial.print(" Light = "); Serial.print(Light); if (Light > Light_thresh){ //Too Bright digitalWrite(Light_out, HIGH); //outputs 1 } else{ //No Light digitalWrite(Light_out, LOW); //outputs 0 } } void TmpSensor(){ Temp = analogRead(Temp_in); Serial.print(" Temperature = "); Serial.print(Temp); if (Temp > Temp_thresh){ //Too Hot digitalWrite(Temp_out, HIGH); //outputs 1 } else{ //Good Temperature digitalWrite(Temp_out, LOW); //outputs 0 } } void MoistureSensor(){ Moist = analogRead(Moist_in); Serial.print(Moist); Serial.print(" "); if (Moist >= Moist_thresh){ digitalWrite(Moist_out_0, HIGH); digitalWrite(Moist_out_1, HIGH); digitalWrite(Moist_out_2, HIGH); Mst = 7; } else{ Mst = map(Moist,0,Moist_thresh,0,8); } Serial.print(Mst); if (Mst == 0){ digitalWrite(Moist_out_2, LOW); digitalWrite(Moist_out_1, LOW); digitalWrite(Moist_out_0, LOW); } else if (Mst == 1){ digitalWrite(Moist_out_2, HIGH); delay(5); digitalWrite(Moist_out_1, LOW); delay(5); digitalWrite(Moist_out_0, LOW); } else if (Mst == 2){ digitalWrite(Moist_out_2, LOW); delay(5); digitalWrite(Moist_out_1, HIGH); delay(5); digitalWrite(Moist_out_0, LOW); } else if (Mst == 3){ digitalWrite(Moist_out_2, HIGH); delay(5); digitalWrite(Moist_out_1, HIGH); delay(5); digitalWrite(Moist_out_0, LOW); } else if (Mst == 4){ digitalWrite(Moist_out_2, LOW); delay(5); digitalWrite(Moist_out_1, LOW); delay(5); digitalWrite(Moist_out_0, HIGH); } else if (Mst == 5){ digitalWrite(Moist_out_2, HIGH); delay(5); digitalWrite(Moist_out_1, LOW); delay(5); digitalWrite(Moist_out_0, HIGH); } else if (Mst == 6){ digitalWrite(Moist_out_2, LOW); delay(5); digitalWrite(Moist_out_1, HIGH); delay(5); digitalWrite(Moist_out_0, HIGH); } else{ digitalWrite(Moist_out_2, HIGH); delay(5); digitalWrite(Moist_out_1, HIGH); delay(5); digitalWrite(Moist_out_0, HIGH); } }