Vrishak VemuriKrishna Vemuri
Published © GPL3+

Distance Device

Ensures two people are at least 6ft apart unless they are part of the same family.

IntermediateFull instructions provided3.5 hours1,513
Distance Device

Things used in this project

Hardware components

Arduino Nano
×1
HC-05
×1
LCD
×1
Active Buzzer
×1
Potentiometer 10K Ohm
×1
220 ohm resistor
×1
9V battery (generic)
9V battery (generic)
×1
9V battery connector to breadboard
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Tape, Scotch
Tape, Scotch
Tape might be necessary to tape battery to back of breadboard for handheld device.

Story

Read more

Schematics

Distance Device Diagram

How to wire the Distance Device

Distance Device Schematic

Schematic for Distance Device

Code

Arduino Code

Arduino
Final Arduino Code to be run
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int buttonstate = 0;
void setup() {
  pinMode(13,OUTPUT);
  lcd.begin(16, 2);
  Serial.begin(9600);


  Serial.println("Enter AT commands:");

  mySerial.begin(38400);
  //AT+RESET
  mySerial.write(int('A'));
  mySerial.write(int('T'));
  mySerial.write(int('+'));
  mySerial.write(int('R'));
  mySerial.write(int('E'));
  mySerial.write(int('S'));
  mySerial.write(int('E'));
  mySerial.write(int('T'));
  mySerial.write(13); // CR
  mySerial.write(10); // NL
  while (!mySerial.available()) {}
  while (mySerial.available()) {
    Serial.println(mySerial.readString());
  }
  //AT+INIT
  mySerial.write(int('A'));
  mySerial.write(int('T'));
  mySerial.write(int('+'));
  mySerial.write(int('I'));
  mySerial.write(int('N'));
  mySerial.write(int('I'));
  mySerial.write(int('T'));
  mySerial.write(13); // CR
  mySerial.write(10); // NL

  while (!mySerial.available()) {}
  while (mySerial.available()) {
    Serial.println(mySerial.readString());
  }

  //AT+IAC=9e8b33
  mySerial.write(int('A'));
  mySerial.write(int('T'));
  mySerial.write(int('+'));
  mySerial.write(int('I'));
  mySerial.write(int('A'));
  mySerial.write(int('C'));
  mySerial.write(int('='));
  mySerial.write(int('9'));
  mySerial.write(int('e'));
  mySerial.write(int('8'));
  mySerial.write(int('b'));
  mySerial.write(int('3'));
  mySerial.write(int('3'));
  mySerial.write(13); // CR
  mySerial.write(10); // NL

  while (!mySerial.available()) {}
  while (mySerial.available()) {
    Serial.println(mySerial.readString());
  }

  //AT+CLASS=0
  mySerial.write(int('A'));
  mySerial.write(int('T'));
  mySerial.write(int('+'));
  mySerial.write(int('C'));
  mySerial.write(int('L'));
  mySerial.write(int('A'));
  mySerial.write(int('S'));
  mySerial.write(int('S'));
  mySerial.write(int('='));
  mySerial.write(int('0'));
  mySerial.write(13); // CR
  mySerial.write(10); // NL

  while (!mySerial.available()) {}
  while (mySerial.available()) {
    Serial.println(mySerial.readString());
  }

  //AT+INQM=1,9,48

  mySerial.write(int('A'));
  mySerial.write(int('T'));
  mySerial.write(int('+'));
  mySerial.write(int('I'));
  mySerial.write(int('N'));
  mySerial.write(int('Q'));
  mySerial.write(int('M'));
  mySerial.write(int('='));
  mySerial.write(int('1'));
  mySerial.write(int(','));
  mySerial.write(int('9'));
  mySerial.write(int(','));
  mySerial.write(int('4'));
  mySerial.write(int('8'));
  mySerial.write(13); // CR
  mySerial.write(10); // NL

  while (!mySerial.available()) {}
  while (mySerial.available()) {
    Serial.println(mySerial.readString());
  }
}


unsigned int hexToDec(String hexString) {

  unsigned int decValue = 0;
  int nextInt;

  for (int i = 0; i < hexString.length(); i++) {

    nextInt = int(hexString.charAt(i));
    if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
    if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
    if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
    nextInt = constrain(nextInt, 0, 15);

    decValue = (decValue * 16) + nextInt;
  }

  return decValue;
}


int OK = 1;
void loop()

{

  
  if (OK) {
    mySerial.write(int('A'));
    mySerial.write(int('T'));
    mySerial.write(int('+'));
    mySerial.write(int('I'));
    mySerial.write(int('N'));
    mySerial.write(int('Q'));
    mySerial.write(13); // CR
    mySerial.write(10); // NL
    OK = 0;
  }
  while (!mySerial.available()) {}
  while (mySerial.available()) {
    
    String x = String(mySerial.readString());
    int slashn = x.indexOf("\n");
    Serial.println(slashn);
    int nod = 0;
    int countf = 0;
    int counto = 0;
    int countd = 0;
    int xlen = x.length()/(slashn+1);
    if (x.endsWith("OK\r\n")) {
      x = x.substring(0, x.length() - 4);
      OK = 1;
    }
    for (int i = 0; i < xlen; i++) {
      if (i != 0) {
        x = x.substring(slashn+1);
      }
      slashn = x.indexOf("\n");
      String rssi = x.substring(slashn-5, slashn-1);
      int decNO = hexToDec(rssi);
      lcd.setCursor(0, 1);
      lcd.print("RSSI:" + String(decNO));
      Serial.println(x.substring(5,slashn-11));
      if (x.substring(5, slashn-11) == "20:2:2011FB") {
        countf++;

      }
      else {
        counto++;
        if (decNO > -76.91) {
          countd++;
        }
      
        
      }
      if (decNO > -76.91) {
        Serial.println("near");
      }
      else {
        Serial.println("far");
      }
      Serial.println(decNO);
    }


    Serial.println("Family: " + String(countf) + " Outsider: " + String(counto) + " Danger: " + String(countd));
    if (counto/2<countd) {
          lcd.setCursor(10, 1);
          lcd.print("DANGER");
          Serial.println("DANGER");
          digitalWrite(13,HIGH);
        }
        else {
          lcd.setCursor(10, 1);
          lcd.print("      ");
          Serial.println("Fine");
          digitalWrite(13,LOW);
        }
  }
  delay(100);
}

Credits

Vrishak Vemuri

Vrishak Vemuri

3 projects • 3 followers
Your avid electronics enthusiast =D // Making magic blue smoke since summer 2018 // Currently in high school (class of 2025)
Krishna Vemuri

Krishna Vemuri

3 projects • 2 followers

Comments