Dirk
Published

DiWa Corona Belt - Enforce Social Distancing

Module measures if distance to others is less than 1.5m. If so, the alarm starts with sound and LED. Stay home, stay safe.

IntermediateShowcase (no instructions)3 hours1,495
DiWa Corona Belt - Enforce Social Distancing

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
WS2812 Addressable LED Strip
Digilent WS2812 Addressable LED Strip
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Story

Read more

Code

Corona Belt Arduino Code

C/C++
// DiWa Corona Belt
// March 25, 2020

int TriggerPin = 8; // Digital 8 -> HC-SR04 Trigger
int EchoPin = 9;    // Digital 9 -> HC-SR04 Echo
// HC-SR04 Vcc -> 5V, GNG -> GND
#include "FastLED.h"

#define ANZAHL_LEDS 26
#define LED_PIN 2
CRGB leds[ANZAHL_LEDS];

void setup()
{
  Serial.begin(9600);
  FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, ANZAHL_LEDS);
  for (int i = 0; i < ANZAHL_LEDS; i++) {
    leds[i] = CRGB::Black;
    FastLED.show();
  }
  delay (5000);
}

void loop()
{
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(TriggerPin, OUTPUT);
  digitalWrite(TriggerPin, LOW);
  delayMicroseconds(2);
  digitalWrite(TriggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(TriggerPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(EchoPin, INPUT);
  duration = pulseIn(EchoPin, HIGH);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);
  if (cm <= 500)
  {
    Serial.print(cm);
    Serial.println("cm");
  }
  else Serial.println("Ungueltige Messung ! Entfernung groesser als 5 Meter !!!");
  delay(100);
  
  if (cm < 150 && cm > 10){
    for (int blinken = 0; blinken <3; blinken++){
      for (int i = 0; i < ANZAHL_LEDS; i++) {
        leds[i] = CRGB::Red;
        FastLED.show();
      }
      tone(6, 400); // …spiele diesen Ton...
      delay(300); //…und zwar für eine Sekunde...
      noTone(6); // Ton abschalten
      for (int i = 0; i < ANZAHL_LEDS; i++) {
        leds[i] = CRGB::Black;
        FastLED.show();
      }
      tone(6, 700); // …spiele diesen Ton...
      delay(300); //…und zwar für eine Sekunde...
      noTone(6); // Ton abschalten
    }  
    cm = 0;  
  }
}

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;
}

Credits

Dirk

Dirk

1 project • 1 follower

Comments