[RISOLTO] sonda umidità unico led blinking millis

ORSO2001:
ciao...scusa mi sono un attimo perso...il fatto che lampeggi continuamente è quello che vuoi?

No, vorrei che il blink si verificasse solo per "value_A0<400".
Nel loop ho inserito quelle tre funzioni per prova ma non so come fare, mi potete aiutare?

ORSO2001:
tralasciando che la funzione la potevi dichiarare come void in quanto non torna alcunché...

Modifica eseguita "void indicator(int intervalBlink) {"

ORSO2001:
altro consiglio è quello di chiamare le tue funzioni con "nome" diverso da quello dello namespace standard...come vedi blink e read hanno colore diverso (arancio) da check (nero)...questo perchè sia blink che read sono presenti nella lista Keywords in quanto presenti in librerie in uso...

Modifica eseguita:
void read_soil(int interval) {
void check_soil() {
void indicator(int intervalBlink) {

Grazie in anticipo

ciao,

prova a spostare la funzione blink() all'interno dell'if value_A0<400 della funzione check() ...assicurati di inserire negli altri if della funzione check() un reset per il LED gestito da blink().

ORSO2001:
prova a spostare la funzione blink() all'interno dell'if value_A0<400 della funzione check()

Io l'ho intesa in questo modo

// Function check state soil himidity:
void check_soil() {
  if(value_A0>=400 && value_A0<=500) {
    digitalWrite(greenLED_A0,HIGH); // Swith on indicator led:
    Serial.print(F("humid soil, "));
  }
  if(value_A0<400) {
    indicator(200); // Led will blink every 200ms
    Serial.print(F("wet soil, "));
  }
  if(value_A0>501) {
    digitalWrite(greenLED_A0,LOW); // Swith off indicator led:
    Serial.print(F("dry soil, "));
  }
} // End check_soil:

ORSO2001:
...assicurati di inserire negli altri if della funzione check() un reset per il LED gestito da blink().

E qui viene il bello, come si fa a fare quello che dici?

Grazie in anticipo

PS Promesso metto i karma a tutti

Secondo me non hai bisogno di gestire il reset del led in quanto per qualsiasi valore di A0 hai associato uno stato di acceso/spento/lampeggiante quindi il led non rimane bloccato in qualche stato precedente.. o sbaglio qualcosa? :confused:

Secondo me non hai bisogno di gestire il reset del led in quanto per qualsiasi valore di A0 hai associato uno stato di acceso/spento/lampeggiante quindi il led non rimane bloccato in qualche stato precedente.. o sbaglio qualcosa? :confused:

vero...in quanto si agisce su unico pin per il LED....per qualche motivo avevo pensato che erano 2 i LED...

Ciao,
ho creato le tre funzioni ma ora come le metto assieme?

void loop() { // Start loop:

  ?
  
} // End loop:

ecco le tre funzioni

void read_soil(int interval) {
void check_soil() {
void indicator_soil(int intervalBlink) {

praticamente nel loop deve avvenire che:
faccia una lettura ogni 10 secondi (read_soil) e che verifichi l'umidità (check_soil) se value_A0<400 il led (unico) deve blincare fino alla prossima lettura.
Come si traduce?

Grazie mille

ciao...prova questo:

/*
  FILE:    hygrometer.05GIU17
  TAG:     LM393, FC28, HYGROMETER, SOIL, MOISTURE, LED, BLINK, MILLIS
  PURPOSE: Soil moisture test program
  PROBES:  LM393+FC28
  VERSION: 05GIU17
  DISPLAY: NC
  COMFORT: humid soil: 200 < value < 500
  LOCATION:Monteriggioni (200m slm)
  AUTHOR:  Antonio Cannavale

  Soil moisture sensor connected to Arduino as follow:
  GND -> GND
  VCC -> +5V
  D0  -> D12
  A0  -> A0
*/

// Initializing variables:

boolean blinkEnable = false;

unsigned long previousMillis = 0; // Store the last time read was updated:
unsigned long previousMillisBlink = 0; // Store last time LED was updated:

// Variables constant:
const int greenLED_A0 = 12; // Indicator green led connect at Digital PIN D12:

// Variables will change:
int ledState = LOW; // ledState used to set the LED

int soil_moisture_A0 = 0; // Read from Analog PIN A0:
int value_A0 = 0; // Store the value coming from the sensor A0:

float volts_A0 = 0; // Store the volt coming from the sensor A0:

// Set to true to print status messages to the serial:
boolean DEBUG = true;

// The setup function runs once when you press reset or power the board:
void setup() { // Start setup:

  // We start the serial library to output our messages:
  if (DEBUG) {
    Serial.begin(9600);
  } // End if:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only:
  } // End while:

  pinMode(soil_moisture_A0, INPUT); // Set analog pin as an INPUT:
  pinMode(greenLED_A0, OUTPUT); // Set digital pin as an OUTPUT:

  Serial.println(F("\nSoil moisture sensor"));
  Serial.println(F("--------------------"));

  digitalWrite(greenLED_A0, LOW); // Switch off Green LED Indicator:

  // Record the time once the setup has completed:
  previousMillis = millis();
  previousMillisBlink = millis();

} // End setup:

// The loop function runs over and over again forever:
void loop() { // Start loop:

  read_soil (10000); // Read value every 10s:
  check_soil (); // Check state soil humidity:
  if (blinkEnable) {
    indicator (200); // Blink led every 200ms.
  }
} // End loop:


// Function read soil hymidity:
void read_soil(int interval) {

  // Check whether it has been long enough:
  if (millis() - previousMillis >= interval) {

    // Read Soil Moisture values:
    value_A0 = analogRead(soil_moisture_A0); // Read from analog pin:
    volts_A0 = (value_A0 / 1023.0) * 5.0; // Conversion to volts:

    // Send soil Moisture values to serial communication:
    //Serial.print(F("Time : ")) & Serial.print(millis()) & Serial.print(F(", "));
    Serial.print(F("sensor A0: ")) & Serial.print(value_A0) & Serial.print(F(", ")) & Serial.print(volts_A0, 2) & Serial.println(F("V"));

    previousMillis = millis(); // Store the current time:
  }
} // End read:

// Function check state soil himidity:
void check_soil() {
  if (value_A0 >= 400 && value_A0 <= 500) {
    digitalWrite(greenLED_A0, HIGH); // Swith on indicator led:
    Serial.print(F("humid soil, "));
    blinkEnable = false;
  }
  if (value_A0 < 400) {
    indicator(200); // Led will blink every 200ms
    Serial.print(F("wet soil, "));
    blinkEnable = true;
  }
  if (value_A0 > 501) {
    digitalWrite(greenLED_A0, LOW); // Swith off indicator led:
    Serial.print(F("dry soil, "));
    blinkEnable = false;
  }
} // End check:

// Function blinking indicator led:
int indicator(int intervalBlink) {
  if (millis() - previousMillisBlink >= intervalBlink) {
    // If the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    }
    else {
      ledState = LOW;
    }
    // Set the LED with the ledState of the variable:
    digitalWrite(greenLED_A0, ledState);
    // Store the current value:
    previousMillisBlink = millis();
  }
} // End blink:

Ciao
Grazie ORSO2001, ho provato il tuo codice ma ottengo: una fila di messaggi della funzione check_soil e alla fine di ogni riga il valore di umidità.
Forse anche la funzione check_soil dovrebbe fare qualcosa, ma cosa?

Grazie mille

wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, wet soil, sensor A0: 1022, 5.00V

ciao...fa così perchè la funzione check_soil() è chiamata in continuazione nel loop(); adesso l'ho spostata all'interno di read_soil() quindi viene eseguita ogni 10 secondi...prova:

/*
  FILE:    hygrometer.05GIU17
  TAG:     LM393, FC28, HYGROMETER, SOIL, MOISTURE, LED, BLINK, MILLIS
  PURPOSE: Soil moisture test program
  PROBES:  LM393+FC28
  VERSION: 05GIU17
  DISPLAY: NC
  COMFORT: humid soil: 200 < value < 500
  LOCATION:Monteriggioni (200m slm)
  AUTHOR:  Antonio Cannavale

  Soil moisture sensor connected to Arduino as follow:
  GND -> GND
  VCC -> +5V
  D0  -> D12
  A0  -> A0
*/

// Initializing variables:

boolean blinkEnable = false;

unsigned long previousMillis = 0; // Store the last time read was updated:
unsigned long previousMillisBlink = 0; // Store last time LED was updated:

// Variables constant:
const int greenLED_A0 = 12; // Indicator green led connect at Digital PIN D12:

// Variables will change:
int ledState = LOW; // ledState used to set the LED

int soil_moisture_A0 = 0; // Read from Analog PIN A0:
int value_A0 = 0; // Store the value coming from the sensor A0:

float volts_A0 = 0; // Store the volt coming from the sensor A0:

// Set to true to print status messages to the serial:
boolean DEBUG = true;

// The setup function runs once when you press reset or power the board:
void setup() { // Start setup:

  // We start the serial library to output our messages:
  if (DEBUG) {
    Serial.begin(9600);
  } // End if:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only:
  } // End while:

  pinMode(soil_moisture_A0, INPUT); // Set analog pin as an INPUT:
  pinMode(greenLED_A0, OUTPUT); // Set digital pin as an OUTPUT:

  Serial.println(F("\nSoil moisture sensor"));
  Serial.println(F("--------------------"));

  digitalWrite(greenLED_A0, LOW); // Switch off Green LED Indicator:

  // Record the time once the setup has completed:
  previousMillis = millis();
  previousMillisBlink = millis();

} // End setup:

// The loop function runs over and over again forever:
void loop() { // Start loop:

  read_soil (10000); // Read value every 10s:
  //check_soil (); // Check state soil humidity:
  if (blinkEnable) {
    indicator (200); // Blink led every 200ms.
  }
} // End loop:


// Function read soil hymidity:
void read_soil(int interval) {

  // Check whether it has been long enough:
  if (millis() - previousMillis >= interval) {

    // Read Soil Moisture values:
    value_A0 = analogRead(soil_moisture_A0); // Read from analog pin:
    volts_A0 = (value_A0 / 1023.0) * 5.0; // Conversion to volts:
    check_soil ();
    // Send soil Moisture values to serial communication:
    //Serial.print(F("Time : ")) & Serial.print(millis()) & Serial.print(F(", "));
    Serial.print(F("sensor A0: ")) & Serial.print(value_A0) & Serial.print(F(", ")) & Serial.print(volts_A0, 2) & Serial.println(F("V"));

    previousMillis = millis(); // Store the current time:
  }
} // End read:

// Function check state soil himidity:
void check_soil() {
  if (value_A0 >= 400 && value_A0 <= 500) {
    digitalWrite(greenLED_A0, HIGH); // Swith on indicator led:
    Serial.print(F("humid soil, "));
    blinkEnable = false;
  }
  if (value_A0 < 400) {
    indicator(200); // Led will blink every 200ms
    Serial.print(F("wet soil, "));
    blinkEnable = true;
  }
  if (value_A0 > 501) {
    digitalWrite(greenLED_A0, LOW); // Swith off indicator led:
    Serial.print(F("dry soil, "));
    blinkEnable = false;
  }
} // End check:

// Function blinking indicator led:
int indicator(int intervalBlink) {
  if (millis() - previousMillisBlink >= intervalBlink) {
    // If the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    }
    else {
      ledState = LOW;
    }
    // Set the LED with the ledState of the variable:
    digitalWrite(greenLED_A0, ledState);
    // Store the current value:
    previousMillisBlink = millis();
  }
} // End blink:

Funziona, siiiiiiiiiiiiiiiiiiiiiiiii
Mitico

Grazie mille

10000000000 karma per te