Arduino – Debug kode til fuktsensor

Her er programmet med kun tekst til serial. Koble til fuktsensoren på analog 0 og kjør «Seriell overvåker» for å se data som printes til serial.

int moistureSensor = A0; //--- Pin A0
int OutputValue = 0; //-------- Pin 0

void setup() {
// Serial Begin so we can get the serial data
Serial.begin(9600);

Serial.print("HofstadNET Debug Console");
delay(1);
Serial.println();
}

void loop(){
// Read the analog value on analog input 0
int sensorValue = analogRead(moistureSensor); 

//OutputValue = (SensorValue, SensorZero, SensorMax, 0, 100)
OutputValue = map(sensorValue, 270, 545, 100, 0); 

//Moisture is LOW, start to water it
if (sensorValue >= 430 && sensorValue < 1024) 
{
 Serial.println();
 Serial.print("Analog:");
 Serial.print(sensorValue);
 Serial.print(" Percentage:");
 Serial.println(OutputValue);
 Serial.print("Text on LCD:");
 Serial.println(" LOW");
 delay(1);
}

//Moisture is Medium, maybe the perfect moisture?
else if (sensorValue >= 350 && sensorValue < 430) 
{
 Serial.println();
 Serial.print("Analog:");
 Serial.print(sensorValue);
 Serial.print(" Percentage:");
 Serial.println(OutputValue);
 Serial.print("Text on LCD:");
 Serial.println(" Medium");
 delay(1);
}

//Moisture is Very HIGH, dont drown the plant 
else if (sensorValue >= 0 && sensorValue < 350) 
{ 
 Serial.println();
 Serial.print("Analog:");
 Serial.print(sensorValue);
 Serial.print(" Percentage:");
 Serial.println(OutputValue);
 Serial.print("Text on LCD:");
 Serial.println(" High");
 delay(1);
}
delay(1500);
}