EchoDAR

Introduction: EchoDAR

As what it’s named, it’s an Echo Detection and Ranging. LCD will shows how far the object is away from you. And even you can estimate the distance by discerning the tone of the buzzer. Touch Sensor Switch make it easy to start or stop.

I get the idea from https://www.youtube.com/watch?v=kQRYIH2HwfYa, and it’s being equipped more sensors while I try to rebuild the work. Let’s start.

Supplies

Things you need to prepare:

For electronic part:

  • An Arduino uno board;
  • A bread board;
  • Lots of wires;
  • Touch Sensor;
  • Servo motor;
  • Ultrasonic Module;
  • LCD; Buzzer;

For the “Antenna” holder:

  • A pensil;
  • A binding clip;
  • A hard Cardboard;
  • Some Toothpick;

Perhaps some tools:

  • A knife;
  • An electric iron

Step 1: The "Antenna"

Because many tools and material are at school, and the Ultrasonic module will be serve for another use, i choose toothpicks and cardboard as connectors, and glue as less as possible.So you don't need to get the totally same materials as mine, anything at hand can be considered as the antenna holder.

Step 2: Connect All the Sensors to Arduino Via the Breadboard

I won't account the detail usage of the sensors as their programming skills are out of anywhere on the internet.

Step 3: Programming, Reference Code As Follow

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>
#include <Servo.h>
#define DEVTIME 5      //分时操作
#define TRIGGER_PIN  2  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     3  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
const int buzzerPin = 7; //the buzzer pin attach to
const int SensorPin=6; //touch switch attach to pin7
const int ledPin = 13; //pin13 built-in led

int ledState=0;
int SensorState=0; //store the value of touch switch
int lastSensorState=0;
int SensorCount=0;

int REST=1;//单片机睡眠
/************************************************/
Servo myservo;//create servo object to control a servo
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
LiquidCrystal_I2C lcd(0x27,16,2);//0x27   0x3F
/************************************************/
void setup()
{
  pinMode(buzzerPin,OUTPUT);//set buzzerPin as OUTPUT pinMode(SensorPin,INPUT);//set sensorPin as INPUT
  pinMode(ledPin,OUTPUT); // set ledPin as OUTPUT
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  lcd.init(); 
  lcd.backlight();
  myservo.attach(9);//attachs the servo on pin 9 to servo object
  myservo.write(0);//back to 0 degrees 
  delay(1000);//wait for a second
}
/*************************************************/
void loop()
{ 
  lcd.setCursor(0, 0);
  lcd.print("Distance:");
  lcd.setCursor(0, 1);
  lcd.print("             ");
  lcd.setCursor(12, 1);
  lcd.print("cm"); 
  SensorSwitch();
  if (REST)
    noTone(buzzerPin);
  else{
  int count=0;
  for(int i=0;i<=360;i++)
  {
    SensorSwitch();
    if (count<DEVTIME){
      if (i<180)
      {
        myservo.write(i);
      }
      else
      {
        myservo.write(360-i);
      }
      count++;
    }
    else
    {  
      echoonce();
      noTone(buzzerPin);
      count=0;
    }
  }
}}
/**************************************************/
void echoonce()
{
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  int cm = uS / US_ROUNDTRIP_CM;
  if (cm<=0 or cm>MAX_DISTANCE) cm=MAX_DISTANCE;
  Serial.print("Ping: ");
  Serial.println(cm); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
  beep(buzzerPin,cm); 
  lcd.setCursor(8, 1);
  lcd.rightToLeft();
  lcd.print(cm);
  lcd.leftToRight();
  delay(30);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
 }
 void beep(int pin,int distance){
  if (distance<10) {tone(pin,2000);}
  else if (distance<30) {tone(pin,1000);}
  else if (distance<50) {tone(pin,200);}
  else {;}
  }
 void SensorSwitch(){
    SensorState=digitalRead(SensorPin);//read the value of pin7 
  if (SensorState!=lastSensorState & SensorState==LOW){
    SensorCount++;
  }
  if (SensorCount % 2 ==1){
    ledState=HIGH; //turn on the led
    SensorCount = 1;
    }
  else {
    ledState=LOW; //turn on the led
    SensorCount =0;}
  digitalWrite(ledPin, ledState);
  REST=!ledState;
  lastSensorState=SensorState;
  }
Arduino Contest 2020

Participated in the
Arduino Contest 2020

Be the First to Share

    Recommendations

    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge
    • Plastic Challenge

      Plastic Challenge
    • Robots Contest

      Robots Contest

    Comments

    0
    noamf3
    noamf3

    1 year ago

    I suggest calling it a sonar as it is a better name