The Black Box

by MaxBrons in Circuits > Arduino

1269 Views, 6 Favorites, 0 Comments

The Black Box

The Black Box - Showcase
20230517_133104.jpg
20230517_133057.jpg

This device measures the distance between the object in front of it and itself. It will tell you how far the object is relative to the device by producing four different tones:

  • A low tone if the object is closer than one meter away.
  • A middle tone if the object is closer than half a meter away.
  • A high tone if the object is closer than 10 centimeters away.
  • No tone if the object is further than one meter away.

I designed this device to be used by blind people because I felt inspired to create a digital version of the canes blind people use.

Supplies

Soldering

Uitwerking Schema ITTT.png
20230505_210953.jpg

The first step is soldering the components to the experimental board. My soldering is not exactly the same as in the schematic because I wanted the power in/out and the info pins to be grouped closer together so I didn't have to bridge a huge gap between the soldering points.

I used the following color coding:

  • White (power in): male-male cable with one end cut off and soldered to the board.
  • Green long (power in for the buzzer): both ends are soldered to the board.
  • Green short (power out and to the transistor): both ends are soldered to the board.
  • Grey short (power out for the buzzer): both ends are soldered to the board.
  • Grey long (power out): male-male cable with one end cut off and soldered to the board.
  • Red (power in for the ultrasonic sensor): male-female cable with the male end cut off and soldered to the board.
  • Yellow (power out for the ultrasonic sensor): male-female cable with the male end cut off and soldered to the board.
  • Blue (power regulator for the buzzer): male-male cable with one end cut off and soldered to the board.

Code

For this project, I wanted to produce different tones depending on the distance you are from the object in front of you. I used a library called millisDelay to create a delay between the sounds that are produced. This creates a beeping effect. For the ultrasonic sensor, I used digital pin 4 for the trigPin and digital pin 3 for the echoPin. For the buzzer, I used digital pin 2.

 

Download the Arduino IDE file or copy and paste the code below into your favorite IDE (Arduino IDE, Visual Studio, etc.) and upload it to your Arduino to see the magic happen.

 

The code I have written for this project is as follows:


#include <millisDelay.h>

// Define the pins for the Ultrasonic sensor and the speaker
const int trigPin = 4;
const int echoPin = 3;
const int speakerPin = 2;

// Define the variables to store the duration of the pulse and the status of the echo pin
unsigned long pulseDuration;  // Duration of the pulse in microseconds
millisDelay repeatTimer;      // A delay at the end of each cycle to give the sonar sensor time to react.
millisDelay intervalTimer;    // A delay at the end of each cycle to create a gap in between the sounds.

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Set pin modes
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(speakerPin, OUTPUT);

  // Start the timers
  repeatTimer.start(100);
  intervalTimer.start(300);
}

void loop() {
  // Wait for the timer to complete before checking the distance and playing a sound.
  if (!repeatTimer.justFinished())
    return;

  // Send a 10us pulse to the trigger pin to start the measurement
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Wait for echo pulse to be received
  pulseDuration = pulseIn(echoPin, HIGH);

  if (intervalTimer.justFinished()) {
    // Calculate the distance in centimeters using the speed of sound in air (29.1 microseconds per centimeter)
    float distance = pulseDuration / 29.1 / 2;

    // Play audio based on the distance of the pulse
    if (distance > 100) {
      digitalWrite(speakerPin, LOW);  // No obstacles ahead
      noTone(speakerPin);             // Stop playing audio
    } else if (distance > 75) {
      tone(speakerPin, 400);  // Play audio with a sertain frequency
    } else if (distance > 25) {
      tone(speakerPin, 800);  // Play audio with a sertain frequency
    } else if (distance > 0) {
      tone(speakerPin, 1000);  // Play audio with a sertain frequency
    }

    // Print distance and frequency to serial monitor
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println(" cm");

    // Restart the interval timer
    intervalTimer.repeat();
  } else {
// Stop playing audio
    noTone(speakerPin);
  }

  // Repeat the small delay to give the sonar sensor time to react and the buzzer sound to be heard.
  repeatTimer.repeat();
}

Downloads

Creating the Box

20230508_195956.jpg
20230508_200015.jpg
20230508_200028.jpg

For the case, you need the following pieces:

  • Two 9x6 cm pieces of wood
  • Two 12.5x6 cm pieces of wood
  • Two 12.5x7.2 cm pieces of wood

Next, drill a small 10mm hole in one of the 9x6 cm pieces of wood in one of the four corners. This hole is used to guide the power cable from the battery case through it. After you have done that, drill two 15-mm holes in the other 9x6 cm piece of wood for the ultrasonic sensor. Make sure that the space between the holes is the same as the space between the sender and receiver units on the ultrasonic sensor.

Attaching the Boards

20230508_200052.jpg
20230508_203559.jpg

Next up, attach the Arduino and your soldered circuit board to the two 12.5x7.2 cm pieces of wood. I attached them by drilling small screws in the wood through the holes on the Arduino and circuit board.

Assembly

20230505_210833 - kopie.jpg
20230508_225007.jpg
20230517_133125.jpg
20230508_225026.jpg

For the last step, you will have to assemble all the pieces. First, connect the ultrasonic sensor to the Arduino (with two extra male-female wires, blue for the TrigPin and orange for the EchoPin) and to the circuit board. Next up, paint the wooden parts in a color and style of your liking and let them dry. After that, glue the wooden pieces together, but don't glue the 9x6 cm piece of wood with the 10mm hole in it to the rest of the box (we're gonna use velcro strips for that). Also, don't forget to put the ultrasonic sensor through the holes on the side. Next, glue the velcro pieces to the edges of the (now) assembled box and also glue them to the 9x6 cm piece of wood with the 10mm hole in it. After that, the only thing left is to glue the battery box (on/off switch side towards you) to the outside part of the 9x6 cm piece of wood with the 10mm hole in it, and then it is finished!

Final Results

20230517_133057.jpg
20230517_133104.jpg
20230517_133125.jpg
The Black Box - Showcase

This is the final result! I wish I could make it smaller for convenience, but besides that, I think it looks and works awesome.

Process and Evaluation

20230428_195904.jpg
20230505_210743 - kopie.jpg
20230506_203918.jpg
20230506_203933.jpg
20230508_225020.jpg

Process

To get to the end result, I went through a couple of iterations. First, I tested out the schematic I made using a breadboard. This was to see if my idea was even possible and if there were any issues. After that, I soldered the components to the circuit board and made a quick prototype box from cardboard to see what my layout was going to look like and what my alternative options were. After I successfully prototyped it and it worked, I began creating the final version.

Issues

During the process, I encountered two issues. The first issue was that the wires were very fragile, and two of them broke off, so I had to resolder them. The other problem was that the glue was not strong enough to hold the velcro in place when you pulled the top part from the box. The way I fixed that was by using super glue, so it would definitely stay stuck to the wood.

Evaluation

So, all in all, I am very pleased with the final result. As mentioned before, I would have liked to make it smaller, but the size of the Arduino and the circuit board were the limiting factors. During this project, I learned to use an Arduino, to solder, to create my own schematic, and to code for an Arduino in the C++ coding language.