Ciao tutti,
ho trovato un libro per creare progetti con Arduino e mi sono messo a lavorare sul progetto di giardinaggio.
Passiamo al sodo. Nel monitor seriale posso controllare il valore del sensore ma vorrei che accando ci fosse data e ora del PC.
Come posso fare?
Ecco il codice che utilizzo.
/* Arduino Projects for Dummies
* by Brock Craft
*
* Chapter 10: Building and Automated Garden
* A system that detects soil moisture and
* triggers a solenoid valve
*
* v0.1 30.04.2013
*/
int sensorPin = A0; // The input pin for the moisture sensor
int valvePin = 9; // The output pin to actuate the valve
const int dryThreshold = 730; // Set this threshold based upon your sensor tests. 1023 = bone dry, < 100 totally submerged
const long sampleInterval = 120000; // Sample every 2 minutes
const int irrigationTime = 5000; // Duration to let the water flow
boolean DEBUG=true; // Set to true if you want to read output on the Serial port
void setup() {
if(DEBUG){Serial.begin(9600);}
pinMode(sensorPin, INPUT); // Declare the sensor pin as an OUTPUT:
pinMode(valvePin, OUTPUT); // Declare the valve pin as an OUTPUT:
digitalWrite(valvePin, LOW); // Make sure the valve is closed.
}
void loop() {
int sensorValue = analogRead(sensorPin); // read the value from the sensor:
if(DEBUG){
Serial.print("Sensor A0 value: ");
Serial.println(sensorValue);
}
if (sensorValue>dryThreshold){
digitalWrite(valvePin, HIGH); // Open the water valve
delay(irrigationTime); // Keep it open for the irrigation time
digitalWrite(valvePin, LOW); // Close the valve
}
delay(sampleInterval); // wait until the next time to take a reading
}
Grazie in anticipo per l'aiuto.
--
Antonio