PitCoVidDistMeter

Uno piccolo aiuto nell'epoca del Covid19.

 

Da anni lettore di Elettronica IN, nel numero di 246 (luglio/agosto 2020) ho trovato l'interessante articolo di Davide Scullino, che è stato quì liberamente interpretato sia nell'utilizzo del materiale a disposizione sia nella scrittura del codice di controllo.

Ovviamente il tutto potrà e dovrà essere perfezionato ma l'idea, nella sua semplicità, mi è sembrata intereressante, da mettere in campo a supporto del tentativo di limitare la ripresa del virus che ha chiaramente e indelebilmente marchiato quest'anno.

Immagini del primo prototipo del PitCoVidDistMeter (PitCVDM), delle connessioni, dell'origine dell'idea:

ozio_gallery_jgallery

Esempio di utilizzo:

Cosa serve:

  • Arduino Nano
  • Sensore HC-SR04
  • Buzzer
  • Led RGB
  • cavetti
  • contenitore per 4 batterie AAA con interruttore

Codice sorgente Receiver:


/*
  ----------------------------------------------------------------------------------------
  PitCoVidDistMeter
  Zappoco          - PitCVDM_20_07_02       11/07/2020 -- mappatura distanza in frequenza
  Piggy            - PitCVDM_20_07_01       11/07/2020 -- controllo falsi positivi
  Zappoco          - PitCVDM_20_07_00       11/07/2020 -- prima stesura dall'idea di Davide Scullino su Elettronica IN n. 246 pag.105 
  l'idea del PitCoVidDistMeter nasce dall'articolo di Davide Scullino pubblicato su Elettronica IN n. 246 a pag. 105
  e rielabora lo stesso con i componenti disponibili. In particolare il codice è stato scritto partendo dal codice di
  David A. Mellis per l'utilizzo del sensore HC-SR04.
  the idea of ​​PitCoVidDistMeter was born from the article by Davide Scullino published on Elettronica IN n. 246 on page 105
  and rework the same with the available components. In particular, the code was written starting from the code of
  David A. Mellis for the use of the HC-SR04 sensor.
*/
//#define OnSerial             //stampa sulla seriale
int covidDist = 30;
//Ultrasuoni
const int trigPin = 7;
const int echoPin = 4;
int control = 0;
//LED RGB
const int rPin = 11; // select the pin for the red   LED
const int gPin = 10; // select the pin for the green LED
const int bPin = 9 ; // select the pin for the blue  LED
//Buzzer
const int speakerPin = 8;
void setup() {
  // initialize serial communication:
  #ifdef OnSerial
    Serial.begin(9600);
  #endif  
  //Ultrasuoni
  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
  //LED RGB
  pinMode (rPin, OUTPUT);
  pinMode (bPin, OUTPUT);
  pinMode (gPin, OUTPUT);
  //Buzzer
  pinMode (speakerPin, OUTPUT);
}
void loop()
{
  long duration, inches, cm;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  // convert the time into a distance
  // inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  #ifdef OnSerial
    Serial.print(trigPin);
    Serial.print(" trigPin, ");
    Serial.print(echoPin);
    Serial.print(" echoPin, ");
    Serial.print(duration);
    Serial.print(" duration, ");
    //Serial.print(inches);
    //Serial.print("in, ");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
  #endif  
  if( cm >= covidDist){
    control = 0;
    rgb(000, 255, 000);
  }
  else{ 
    control++;
    if (control > 2){
      rgb(255, 000, 000);
      analogWrite (speakerPin, 255);
      delay (map(cm, 0 ,covidDist, 0,100));
      rgb(000, 000, 000);
      analogWrite (speakerPin, 0);
      delay (map(cm, 0 ,covidDist, 0,100));
    }
    else {
    }
  }
  delay(100);
}
/*
long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}
*/
long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
void rgb(int R, int G, int B){
  //Serial.print (R, HEX);Serial.print (G, HEX);Serial.print (B, HEX);Serial.println ("");
  analogWrite(rPin, R);
  analogWrite(gPin, G);
  analogWrite(bPin, B);
}

 

Scarica tutto quello che serve: