AlexilandShijie FanHarry LiuArthurWuXiaoxun Wuuser1051274
Published © Apache-2.0

Nighttime Auxiliary Obstacle Avoidance Alarm

Our project is an auxiliary obstacle avoidance alarm during the night. It helps the driver to avoid small obstacles in dim light.

IntermediateShowcase (no instructions)14 hours88
Nighttime Auxiliary Obstacle Avoidance Alarm

Things used in this project

Hardware components

Grove - Light Sensor
Seeed Grove - Light Sensor
×1
Buzzer
Buzzer
×1
Grove - Ultrasonic Ranger
Seeed Grove - Ultrasonic Ranger
×2
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×2
Development Kit Accessory, DC Motor
Development Kit Accessory, DC Motor
×1
9V battery (generic)
9V battery (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)
Soldering Iron Tip, Knife
Soldering Iron Tip, Knife
3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

sensor part

This is the sensor part
Img 5605 gs782rnh1n

motor

this is the motor part
Img 5604 ifixn08w2r

Code

Main code

C/C++
/*
 Grove Light Sensor

 A simple program that display the value of light from the Grove Light Sensor
 on the Grove 4-Digit Display, this example is very similar to the Grove Rotary Angle Sensor example
 
 The circuit:
 * 4-Digit Display for light sensor attached to Pin 38 and 39 (J14 plug on Grove Base BoosterPack)
 * Light Sensor attached to Pin 24 (J6 plug on Grove Base BoosterPack)
 
 * 4-Digit Display for ultrasonic ranger attached to Pin 37 and 38 (J14 plug on Grove Base BoosterPack)
 * Ultrasonic Ranger attached to Pin 25 (J6 plug on Grove Base BoosterPack)
 * 
 * Buzzer attached to Pin 40 (J13 plug on Grove Base BoosterPack)
 * Note:   
 
 Created by Shijie Fan
 
*/

//4-Digit Display library
#include "TM1637.h" 
#include "Ultrasonic.h"

/* Macro Define */
#define CLK_2               38              /* 4-Digit Display clock pin */
#define DIO_2               37              /* 4-Digit Display data pin */
#define ULTRASONIC_PIN    25              /* pin of the Ultrasonic Ranger */

/* Global Variables */
TM1637 tm1637_2(CLK_2, DIO_2);                  /* 4-Digit Display object */
Ultrasonic ultrasonic(ULTRASONIC_PIN);    /* Ultrasonic Ranger object */
int distance = 0;                         /* variable to store the distance to obstacles in front */
int8_t bits_2[4] = {0};                     /* array to store the single bits of the value */

/* Macro Define */
#define CLK_1               39                  /* 4-Digit Display clock pin */
#define DIO_1               38                 /* 4-Digit Display data pin */
#define LIGHT_SENSOR      24                 /* pin connected to the Light Sensor */

/* Global Variables */
TM1637 tm1637_1(CLK_1, DIO_1);                  /* 4-Digit Display object */
int analog_value = 0;                     /* variable to store the value coming from Light Sensor */
int8_t bits_1[4] = {0};                     /* array to store the single digits of the value */

#define BUZZER_PIN               40           /* sig pin of the Grove Buzzer */

int length = 5;         /* the number of notes */
//char notes[] = "ccggaagffeeddc "; //notes in the song
char notes[] =   "cccccccccccccc "; //notes in the song
int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; //length of each note
int tempo = 200;

/* the setup() method runs once, when the sketch starts */
void setup() 
{
  /* Initialize 4-Digit Display */
  tm1637_1.init();
  tm1637_1.set(BRIGHT_TYPICAL);
  tm1637_2.init();
  tm1637_2.set(BRIGHT_TYPICAL);
  /* set buzzer pin as output */
  pinMode(BUZZER_PIN, OUTPUT);   
}

/* the loop() method runs over and over again */
void loop() 
{   
  analog_value = analogRead(LIGHT_SENSOR);        /* read the value from the sensor */
  int analog_copy =  analog_value;
  
  memset(bits_1, 0, 4);                             /* reset array before we use it */
  for(int i = 3; i >= 0; i--) 
  {
    /* Convert the value to individual decimal digits for display */
    bits_1[i] = analog_value % 10;
    analog_value = analog_value / 10;  
    tm1637_1.display(i, bits_1[i]);                 /* display value on 4-Digit Display */
  }

  distance = ultrasonic.MeasureInCentimeters();   /* read the value from the sensor */  
  int distance_copy = distance;
  
  memset(bits_2, 0, 4);                             /* reset array before we use it */
  for(int i = 3; i >= 0; i--) 
  {
      /* Convert the value to individual decimal digits for display */
      bits_2[i] = distance % 10;
      distance = distance / 10;  
      tm1637_2.display(i, bits_2[i]);                 /* display on 4-Digit Display */
  }

  if (analog_copy < 1300 and distance_copy < 50) {//Loop through each note
  for(int i = 0; i < length; i++) 
  {
    //space indicates a pause
    if(notes[i] == ' ') 
    {
      delay(beats[i] * tempo);
    } 
    else 
    {
      playNote(notes[i], beats[i] * tempo);
    }
    delay(tempo / 2);    /* delay between notes */
  }
  }
  delay(100);  //small delay so that the number doesn't change too quickly to read
}

/* 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);
  }
}

char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

void playNote(char note, int duration) 
{
  
  
  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) 
  {
    if (names[i] == note) 
    {
      playTone(tones[i], duration);
    }
  }
}

Credits

Alexiland

Alexiland

1 project • 1 follower
Shijie Fan

Shijie Fan

1 project • 2 followers
Harry Liu

Harry Liu

1 project • 0 followers
ArthurWu

ArthurWu

1 project • 0 followers
Xiaoxun Wu

Xiaoxun Wu

1 project • 0 followers
user1051274

user1051274

0 projects • 0 followers

Comments

Add projectSign up / Login