Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hackster is hosting Impact Spotlights: Edge AI. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Edge AI. Stream on Thursday!
denisfou
Published © GPL3+

Covid-19 quick distance mesurement

Indicates the distance between people

IntermediateShowcase (no instructions)2 hours4,211
Covid-19 quick distance mesurement

Things used in this project

Hardware components

Resistor, 510 ohm
Resistor, 510 ohm
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Plastic Enclosure, Hand-Held Plastic Box Style 1
Plastic Enclosure, Hand-Held Plastic Box Style 1
×1
Rocker Switch, Non Illuminated
Rocker Switch, Non Illuminated
×1
Arduino Nano R3
Arduino Nano R3
×1
9V Battery Clip
9V Battery Clip
×1
9V battery (generic)
9V battery (generic)
×1

Story

Read more

Schematics

covid19 schema

Covid schema

Code

Covid19

Arduino
this code is a simple code with fixed values (red for lower than 100 cm, yellow for lower than 150 cm and green for other distance)
// covid-19 denis fournier 2020-05-02
// V 1.0

// Digital pins of arduino nano
int trig = 4, echo = 5, LedRed=7, LedYellow=8 , LedGreen=9;
long lecture_echo, cm;

void setup()
{
  pinMode(trig, OUTPUT);
  digitalWrite(trig, LOW);
  pinMode(echo, INPUT);
  pinMode(LedRed,OUTPUT);
  pinMode(LedGreen,OUTPUT);
  pinMode(LedYellow,OUTPUT);  
  Serial.begin(9600);

}

void loop()
{
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  lecture_echo = pulseIn(echo, HIGH);
  cm = lecture_echo / 58;
  Serial.print("Distance en cm : ");
  Serial.println(cm);

  digitalWrite(LedRed,0);
  digitalWrite(LedYellow,0);
  digitalWrite(LedGreen,0);
  if (cm)
  {
      if (cm < 100)
         digitalWrite(LedRed,1);
      else
      {
          if (cm < 150)
              digitalWrite(LedYellow,1);
          else
              digitalWrite(LedGreen,1);
      }
  }
  else
     digitalWrite(LedGreen,1);
  delay(100);
}

Credits

denisfou
2 projects • 2 followers
French geek older than 50 years old, i’ve been a Unix system ingeneer for more than 20 years. I've always written code as a hobby.
Contact

Comments

Please log in or sign up to comment.