Irak MayerElizabeth VicarteStephanie Vicarte
Published © GPL3+

Watch Out!!!

A safety solution to solve the constant looking down at our portable devices screen, and lack of attention to where we are walking.

IntermediateFull instructions provided8 hours157

Things used in this project

Hardware components

MAX32630FTHR
Maxim Integrated MAX32630FTHR
×1
Pololu VL53L0X Time-of-Flight Distance Sensor
×2
Buzzer
Buzzer
×2
Red LED
×1
Green LED
×1
Adafruit Lithium Ion Polymer Battery - 3.7v 1200mAh
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Watch Out Cap!!!

Frontsensor ybkowz8drd

Code

Max32630 detect frontal and rear objects.

Arduino
Manage distance sensors as object detection, buzzers and lights as warning cues.
//Program MaximProjFinal
//Developer Visteli Labs
//This program controls two TOF VL53LOX distance sensors, LED and buzzers to 
//rely warning messages of front and rear obstacles.

#include <Wire.h>
#include <VL53L0X.h>


VL53L0X sensor;
VL53L0X sensor2;

//Global distance variables.
int front_distance =0;
int rear_distance=0;

//PIN definitions
#define FRONT_BUZZER_PIN  P5_5
#define REAR_BUZZER_PIN   P5_4

#define FRONT_LED_PIN  P1_5
#define REAR_LED_PIN   P1_4

//In case we want to display the distance values uncomment the following.
//#define _DEBUG
#define LONGRANGE

//Sample frequency
#define SAMPLETIME  40000

void setup()
{
//Let know the board that we want to use the battery as power.
  //DigitalOut pw_Hold(P2_2, POWER_HOLD_ON);
  pinMode(P2_2,OUTPUT);
  digitalWrite(P2_2,HIGH);

//Initialize the LED pins
  pinMode(FRONT_LED_PIN,OUTPUT);
  pinMode(REAR_LED_PIN,OUTPUT);

  digitalWrite(FRONT_LED_PIN,LOW);
  digitalWrite(REAR_LED_PIN,LOW);
  

#ifdef _DEBUG
  Serial.begin(9600);
#endif

//Start first distance sensor.
  Wire0.begin();
  Wire = Wire0;

//Initialize distance sensor
  sensor.init();
  sensor.setTimeout(500);

//Long range or continuous sampling blocks.
#ifdef LONGRANGE
  sensor.setSignalRateLimit(0.1);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange,18);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange,14);
  sensor.setMeasurementTimingBudget(SAMPLETIME);
#else
  sensor.startContinuous();
#endif

//Initialize distance sensor 2
  Wire2.begin();
  Wire = Wire2;
  
  sensor2.init();
  sensor2.setTimeout(500);

//Long range or continuous sampling blocks.
#ifdef LONGRANGE
  sensor2.setSignalRateLimit(0.1);
  sensor2.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange,18);
  sensor2.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange,14);
  sensor2.setMeasurementTimingBudget(SAMPLETIME);
#else
  sensor2.startContinuous();
#endif

  front_distance = 0;
  rear_distance = 0;
}



void loop()
{
  //Select distance sensor one
  Wire = Wire0;
  //Request the distance from sensor
#ifdef LONGRANGE
  front_distance = sensor.readRangeSingleMillimeters();
#else  
  front_distance = sensor.readRangeContinuousMillimeters();
#endif
#ifdef _DEBUG
  Serial.print(front_distance);
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
#endif
//if obstacle detected less than 80 cm 
  if (front_distance < 800)
  {
    //Play tone and light the LED
    tone(FRONT_BUZZER_PIN, (2048-front_distance), 40);
    digitalWrite(FRONT_LED_PIN,HIGH);
  }
  else
  {
    //stop tone and off LED
    noTone(FRONT_BUZZER_PIN);
    digitalWrite(FRONT_LED_PIN,LOW);
  }

  //Select distance sensor two
  Wire = Wire2;
#ifdef LONGRANGE
  rear_distance = sensor2.readRangeSingleMillimeters();
#else  
  rear_distance =sensor2.readRangeContinuousMillimeters();
#endif
#ifdef _DEBUG
  Serial.print(":");
  Serial.print(rear_distance);
  if (sensor2.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
#endif

//if obstacle detected less than 80 cm 
  if (rear_distance < 800)
  {
    //Play tone and light the LED
    tone(REAR_BUZZER_PIN, (4096-rear_distance), 20);
    digitalWrite(REAR_LED_PIN,HIGH);
  }
  else
  {
    //stop tone and off LED
    noTone(REAR_BUZZER_PIN);
    digitalWrite(REAR_LED_PIN,LOW);
  }
  
#ifdef _DEBUG
  Serial.println();
#endif
}

Credits

Irak Mayer

Irak Mayer

4 projects • 3 followers
Elizabeth Vicarte

Elizabeth Vicarte

3 projects • 3 followers
Stephanie Vicarte

Stephanie Vicarte

4 projects • 5 followers

Comments