Tanay ThakkarAditya ManiRupin Chheda
Published © GPL3+

Bat Sense

This device helps you to measure the distance between things using echolocation through an UltraSonic Sensor, Just like a Bat!

IntermediateShowcase (no instructions)1 hour1,006
Bat Sense

Things used in this project

Story

Read more

Code

Bat Sense

Arduino
It is a distance measurer and is performed and tested on the Arduino platform
/* Download Libraries :
    Adafruit SSD1306
    Adafruit GFX
    NewPing
*/

#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <NewPing.h>

#include <SPI.h>
#include <Wire.h> // For Smoother Functionality



#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);  // Define Function Display

#define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     7  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 450 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize Display
  display.setTextSize(3);
  display.setTextColor(WHITE); // Display Settings
}

int var;
int oldvar; //Declare 2 Variables

void loop() {


  var = sonar.ping_cm();  // Send ping, get distance in cm and print result (0 = outside set distance range)

  /*
   * If the distance is not same as the distance in the reading before,
   * 
   * it will replace "var" and loop again. This way, processing memory is reduced. 
   */

  if (var != oldvar ) { 
    oldvar = var;
    display.setCursor(0, 0); 
    display.print(" ");
    display.print(var); 
    display.println("cm");  // Print the Distance onto the Screen
    display.display(); 
    delay(100);
    display.clearDisplay(); // Clean The Screen
  }
}

Credits

Tanay Thakkar

Tanay Thakkar

1 project • 4 followers
Aditya Mani

Aditya Mani

1 project • 2 followers
Rupin Chheda

Rupin Chheda

35 projects • 83 followers
Resident Maker at CuriosityGym! Electronics Engineer, CAD Modeller, Educator

Comments