Project showcase
Bat Sense

Bat Sense © GPL3+

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

  • 121 views
  • 0 comments
  • 2 respects

Components and supplies

About this project

We have made an Ultrasonic Distance Sensor using Arduino and The Idiotware Shield. We have used the Adafruit SSD1306, NewPing and the AdafruitGFX libraries to do so. We have used an I2C OLED screen and an Ultrasonic Sensor(HC-SR-04). This will allow people to measure distances without using a measuring tape and do so in minimal time.

Code

Bat SenseArduino
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
  }
}

Comments

Similar projects you might like

Proximity Alarm Distance Meter

by Hassan Shettima Lawan

  • 3,711 views
  • 2 comments
  • 22 respects

Android Things Andy Robot Rasberry Pi3 And Arduino

Project showcase by Dwayne Hoang

  • 1,863 views
  • 0 comments
  • 7 respects

Distance Sensor and OLED

Project tutorial by javier muñoz sáez

  • 22,082 views
  • 22 comments
  • 65 respects

Phantom Bat

Project showcase by Alireza Karkon

  • 4,265 views
  • 3 comments
  • 25 respects

Smart IoT Postbox with the idIoTware Shield

Project tutorial by Ravi Parmar and Rupin Chheda

  • 4,431 views
  • 4 comments
  • 14 respects

Arduino + OLED + Encoder Simple Menu System

Project showcase by yilmazyurdakul

  • 3,461 views
  • 2 comments
  • 6 respects
Add projectSign up / Login