• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

The Coding Couple

Pair programming is a lifetime commitment.

  • Home
  • Categories
    • Arduino
    • JavaScript
    • Python
    • Raspberry Pi
  • About Us
    • Privacy Policy
  • Contact

Creation Crate Month 3: An Arduino Powered Distance Detector

August 14, 2016 by Ashley

Tinkering with microcontrollers has been on my “to try” list for quite some time.  I recently stumbled upon Creation Crate.  Creation Crate is a monthly tech education subscription box.  Each month you receive a Arduino UNO R3 and parts to complete a project. The instruction book includes the source code for the project.  The source code is licensed under the GNU General Public License.  Each month the projects increase in difficulty.  I thought Creation Crate would be a wonderful way to get my feet with wet with Arduino and programming electronics.

I was on the fence about signing up for the subscription box because I was not sure what to expect.  I intend to write a blog post for each Creation Crate I receive in case there is a reader out there on the fence like I was.

The Project

The project for month 3 is a distance detector! With the help of an ultrasonic sensor, the Arduino will provide visual (LEDs) and audio (buzzer) indicators of how away an object is.

Creation Crate Month 3: Distance Detector

Creation Crate Month 3: Distance Detector

What’s in the Box

Inside of month three’s box we have:

  • Arduino UNO R3
  • Breadboard
  • USB Cable
  • LEDs (red, white, yellow and green)
  • Resistors
  • Jumper wires
  • Buzzer
  • Ultrasonic sensor
Creation Crate Month 3's contents

Creation Crate Month 3’s contents

Building the Hardware

Assembling the project was pretty straightfoward.  However, there is a fun twist in this month’s project instructions.  Instead of providing a complete guide on how to wire up the project, the final steps on where to plug wires are omitted from the book.  Based on the source code, you are encouraged to figure out how to assemble the rest of the project.  (If you do get stuck there’s a way to see the complete diagram.)

Adding the hardware to the breadboard

Adding the hardware to the breadboard

Attaching jumper wires

Attaching jumper wires

Programming

The source code for the project is included in the instruction book.  The sketch to implement the distance detector is fairly simple.

// License: GNU General Public License
// Creation Crate Month 3 - Distance Detector
#define red2 13
#define red1 12
#define yellow2 11
#define yellow1 10
#define white2 9
#define white1 8
#define buzzer 3
#define trigPin 7
#define echoPin 6
int sound = 250;
long duration, distance;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(white1, OUTPUT);
pinMode(white2, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(red1, OUTPUT);
pinMode(red2, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// send out pulse waves for measuring the distance of an object
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// the amount of time it took for the pulse to return
duration = pulseIn(echoPin, HIGH);
// distance in cm
distance = duration / 58.2; //(duration / 2) / 29.1;
// manipulate leds based on distance calculated
if (distance <= 40) {
digitalWrite(white1, HIGH);
sound = 900;
}
else {
digitalWrite(white1, LOW);
}
if (distance < 30) {
digitalWrite(white2, HIGH);
sound = 1000;
}
else {
digitalWrite(white2, LOW);
}
if (distance < 20) {
digitalWrite(yellow1, HIGH);
sound = 1100;
}
else {
digitalWrite(yellow1, LOW);
}
if (distance < 15) {
digitalWrite(yellow2, HIGH);
sound = 1200;
}
else {
digitalWrite(yellow2, LOW);
}
if (distance < 10) {
digitalWrite(red1, HIGH);
sound = 1300;
}
else {
digitalWrite(red1, LOW);
}
if (distance < 5) {
digitalWrite(red2, HIGH);
sound = 1400;
}
else {
digitalWrite(red2, LOW);
}
Serial.print("Duration: ");
Serial.print(duration);
Serial.print(", ");
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(", ");
// if object is too far, turn buzzer off
if (distance > 40 || distance <= 0) {
Serial.println("Out of range");
noTone(buzzer);
}
else {
Serial.println("in");
tone(buzzer, sound);
}
delay(500);
}
view raw distance_detector.ino hosted with ❤ by GitHub

Final Thoughts

The Distance Detector is not my favorite project, but it was neat to finally play around with an ultrasonic sensor.

 

Related Posts

  • Creation Crate Month 4: An Arduino powered LED dice gameCreation Crate Month 4: An Arduino powered LED dice game
  • Creation Crate Month 2: An Arduino Powered Memory GameCreation Crate Month 2: An Arduino Powered Memory Game
  • Creation Crate Month 1: An Arduino powered Mood LampCreation Crate Month 1: An Arduino powered Mood Lamp
  • AdaBox 005: Break for Pi | Adafruit Subscription BoxAdaBox 005: Break for Pi | Adafruit Subscription Box
  • Using WSL on Corporate VPNUsing WSL on Corporate VPN
  • Trijam #261 Game Jam Diary: One Wrong MoveTrijam #261 Game Jam Diary: One Wrong Move

Filed Under: Arduino Tagged With: arduino, creation crate, distance detector, month 3, subscription box, ultrasonic sensor

Previous Post: « Getting started with Phaser and ES2015
Next Post: Creation Crate Month 4: An Arduino powered LED dice game »

Reader Interactions

Comments

  1. Christie says

    October 28, 2016 at 10:46 pm

    Thank you for reviewing and doing a great job explaining the Creation Crate projects. I just subscribed this past month and am glad your post are here of the kits to help me as I get a new one each month. Many thanks!

    • Ashley says

      October 29, 2016 at 3:07 pm

      Thank you for your comment. I was wondering if these posts were useful 🙂

Primary Sidebar

Social Media

  • GitHub
  • Instagram
  • Twitter
  • YouTube

Recent Posts

  • Pokémon Color Picker | A web app built with HTML/CSS + JavaScript
  • Pokéball Single DIV CSS Drawing | Tutorial
  • Error: [🍍]: “getActivePinia()” was called but there was no active Pinia
  • Trijam #261 Game Jam Diary: One Wrong Move
  • Using WSL on Corporate VPN

Recent Comments

  • Lizzy on Creation Crate Month 2: An Arduino Powered Memory Game
  • Ashley Grenon on Creation Crate Month 2: An Arduino Powered Memory Game
  • Lizzy on Creation Crate Month 2: An Arduino Powered Memory Game
  • kelly on Creation Crate Month 2: An Arduino Powered Memory Game
  • Ashley on Creation Crate Month 3: An Arduino Powered Distance Detector

Follow us on Instagram!

This error message is only visible to WordPress admins

Error: No feed found.

Please go to the Instagram Feed settings page to create a feed.

Categories

  • Arduino
  • Conferences
  • Debugging
  • Game Jams
  • HTML and CSS
  • JavaScript
  • Programming Languages
  • Python
  • Raspberry Pi
  • Today I Learned

Archives

  • May 2024
  • April 2024
  • March 2024
  • May 2022
  • December 2021
  • May 2021
  • March 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • June 2019
  • April 2019
  • September 2017
  • April 2017
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • April 2015
  • January 2015

Tags

adafruit arduino brackets c# code smell codestock coding standards conventions creation crate debugging developer devspace electronics es6 es2015 game development game jam gotcha hackathon hoisting html html5 javascript led naming conventions nintendo phaser pluralsight pokemon programmer python raspberry pi retro retropie scope self improvement single div single div drawing subscription box TIL today I learned troubleshooting vue vuejs windbg

Footer

About Us

We are the Coding Couple.  Two people who met in college and decided they wanted to pair program for the rest of their ...

Read More »

Most Recent Posts

Pokémon Color Picker | A web app built with HTML/CSS + JavaScript

Pokéball Single DIV CSS Drawing | Tutorial

Error: [🍍]: “getActivePinia()” was called but there was no active Pinia

Trijam #261 Game Jam Diary: One Wrong Move

Social Media

  • GitHub
  • Instagram
  • Twitter
  • YouTube

Copyright Notice

© The Coding Couple, 2015 – 2023. Excerpts and links may be used, provided that full and clear credit is given to The Coding Couple with appropriate and specific direction to the original content.

Copyright © 2025 · Foodie Pro Theme by Shay Bocks · Built on the Genesis Framework · Powered by WordPress