Gary LiWinnie LiYiyang Xu
Published

Two-in-One Radar System

This system can be used as both a backup radar and a collision warning system.

BeginnerFull instructions provided513
Two-in-One Radar System

Things used in this project

Hardware components

EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Grove starter kit plus for Intel Edison
Seeed Grove starter kit plus for Intel Edison
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Schematics

wechatimg64_qKXeZMsklO.jpeg

Code

Source Code

C/C++
#include "Ultrasonic.h"
#define BUZZER_PIN               39            /* sig pin of the Grove Buzzer */
#define ULTRASONIC_PIN           38            /* pin of the Ultrasonic Ranger */


Ultrasonic ultrasonic(ULTRASONIC_PIN);    /* Ultrasonic Ranger object */
int distance = 0;                         /* variable to store the distance to obstacles in front */
int tempo = 200;

void setup() {
  // put your setup code here, to run once:
/* set buzzer pin as output */
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly: 
  distance = ultrasonic.MeasureInCentimeters();   /* read the value from the sensor */ 
  if (distance<30)
  {
    tempo=100;
    playTone(1200,tempo);
  }
  else if(distance<50)
  {
    tempo=200;
    playTone(1400,tempo);
  }
  else if (distance<80)
  {
    tempo=300;
    playTone(1500,tempo);
  }
  else if (distance<100)
  {
    tempo=400;
    playTone(1700,tempo);
  }
  else if (distance<150)
  {
    tempo=500;
    playTone(1900,tempo);
  }
  delay(tempo / 2);
}

/* play tone */
void playTone(int tone, int duration) 
{
  for (long i = 0; i < duration * 1000L; i += tone * 2) 
  {
    digitalWrite(BUZZER_PIN, HIGH);
    delayMicroseconds(tone);
    digitalWrite(BUZZER_PIN, LOW);
    delayMicroseconds(tone);
  }
}

Credits

Gary Li

Gary Li

1 project • 0 followers
Winnie Li

Winnie Li

1 project • 1 follower
Yiyang Xu

Yiyang Xu

1 project • 0 followers

Comments

Add projectSign up / Login