Tom Minnich
Created June 6, 2020 © GPL3+

Social Distance Measuring Badge

The badge uses ultrasonic and infrared sensors to measure distance accurately and IoT to log time spent in proximity to other badges,

AdvancedOver 1 day34
Social Distance Measuring Badge

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
onsemi infrared led
×1
infrared detector
×1
ultrasonic transmitter receiver set
×1
Quad Comparator
Texas Instruments Quad Comparator
×1
Texas Instruments JFET Op Amp
×1

Software apps and online services

Arduino IDE
Arduino IDE
Bluez Bluetooth Stack

Story

Read more

Schematics

peak detector

Used to detect ultrasound ping for measurement of distance

Code

BadgeButtonLED

Arduino
Arduino sketch blending BLE ButtonLED example and Ultrasonic and IR LED pinging
#include <ArduinoBLE.h>

const int ledPin = LED_BUILTIN; // set ledPin to on-board LED
const int buttonPin = 4; // set buttonPin to digital pin 4

BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service

// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
// create button characteristic and allow remote device to get notifications
BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);

void setup() {
  Serial.begin(9600);
  Serial1.begin(80000); // Special baud rate for Ultrasonic pinging
  while (!Serial);

  pinMode(ledPin, OUTPUT); // use the LED as an output
  pinMode(buttonPin, INPUT); // use button pin as an input

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  // set the local name peripheral advertises
  BLE.setLocalName("BadgeButtonLED");
  // set the UUID for the service this peripheral advertises:
  BLE.setAdvertisedService(ledService);

  // add the characteristics to the service
  ledService.addCharacteristic(ledCharacteristic);
  ledService.addCharacteristic(buttonCharacteristic);

  // add the service
  BLE.addService(ledService);

  ledCharacteristic.writeValue(0);
  buttonCharacteristic.writeValue(0);

  // start advertising
  BLE.advertise();

  Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() {
  // poll for BLE events
  BLE.poll();

  // read the current button pin state
  char buttonValue = digitalRead(buttonPin);

  // has the value changed since the last read
  boolean buttonChanged = (buttonCharacteristic.value() != buttonValue);

  if (buttonChanged) {
    // button state changed, update characteristics
    ledCharacteristic.writeValue(buttonValue);
    buttonCharacteristic.writeValue(buttonValue);
  }

  if (ledCharacteristic.written() || buttonChanged) {
    // update LED, either central has written to characteristic or button state has changed
    if (ledCharacteristic.value()) {
      Serial.println("LED on");
      digitalWrite(ledPin, HIGH);
    } else {
      Serial.println("LED off");
      digitalWrite(ledPin, LOW);
    }
  }
  Serial1.println("UUUUUUUUUUBADGE32256UUUUUUUUUU");
}

Nano Proof of Concept Code

Arduino
Produces ultrasonic and infrared signals for social distance measuring and IoT logging badge
void setup() {
  // put your setup code here, to run once:
 Serial.begin(80000);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(250);
  Serial.println("UUUUUUUUUUBADGE32256UUUUUUUUUU");   
}

Credits

Tom Minnich
19 projects • 82 followers
Embedded software guy for a long time
Contact

Comments

Please log in or sign up to comment.