HC-SR04 Ultrasonic Sensors Power Super Mario Brothers Staircase

HCSR04 Ultrasonic sensors project in Upverter

Following is the Mind Your Steps project, which I am conducting student workshops for at SUIC Digital Communication Design students. The goal of these workshops is to explore the possibility of using technology to augment daily experiences and promote new productive human behaviors in day-to-day life.  

The workshop’s timeline is only 1 week, so things need to move as quickly as possible to meet that deadline. In the first class, all of the five students, who had never been exposed to the subject of physical computing before, were lectured with a lot of case studies and learned the explanation for the technology behind it. Students were then told to brainstorm and pick the location for their projects by the end of the very first day. 

The students came up with two locations. The first one was in front of the mirror in a women’s restroom. Female students noticed that other women were spending too much time in front of the mirror, and that maybe we could make an interactive installation to change that behavior. The second location was a staircase between the 8th and 9th floors of the CAT building (which is located at the university). The staircase seemed to be a better location for everyone to be able to participate in the installation and not be limited by lack of access to the women’s restroom. During the lecture period, students were inspired by the piano stairs in the Odenplan subway in Stockholm Sweden, which was implemented to promote the use of the staircase as opposed to the escalator. This interactive project continues to promote healthy behavior by reducing human traffic for the escalator and making the stairs an entertaining choice.

A screenshot from Super Mario Bros
Super Mario Bros offered a great player experience among many mid-eighties games.

If you can recall any popular mid-eighties platformer game in which players attempt to avoid certain objects and catch other objects, Super Mario Bros is sure to be one of the first games to come to mind. Our goal was to bring this fun experience from video game to reality. Since all of the students were too new to the technology for the project to succeed, I was responsible for the technical part and the students were responsible for the overall aesthetics of the project. The Super Mario Bros graphic on the wall around the staircase, the floor, and an electronics enclosure were created by the students. We chose an 8-bit style graphic to give a retro mood to audiences and remind them of the fun experiences 8-bit games provided in their youth. The content of the graphic had to relate to the context of the place, which is Silpakorn University International College in Bangkok, and it had to be relatable to students of the arts.

Wallpaper beside the college’s staircase
The design of the wallpaper beside the staircase is done by the students.

The picture above is the Super Mario Bros-esque graphic design the students came up with, including a lot of 8-bit pixellated buildings and other environmental features. The strawberry pattern above is the symbol that refers to the arts faculty.

Staircase steps are decorated with rewards and traps
Staircase steps are decorated with rewards and traps that provide feedback when stepped on.

The students chose four Mario-like rewards and traps; bombs and turtle shells as traps, and strawberries and coins as rewards. The audience receives audio feedback when stepping on the symbols.

View of the staircase from the higher floor
View of the staircase from above.

Here is what we ended up with on the first installation day. As you can see, we still had too much free space on the wall which needed to be filled. The banner describing the project also seemed to be tilted a bit, so the students had to come up with a clever way to solve it.

Close up view on some of the electronic equipment in the staircase
You could see an HC-SR04 ultrasonic sensors blending in with the buildings in the wallpaper.

For safety reasons, we hid the wires alongside the staircases so that bypassers wouldn’t trip over them.

Side view of the staircase
Close-up of equipment on staircase.

 

The Hardware

A table with hardware on it
The hardware used includes prototyping boards and loudspeakers.

Here is the prototype I built at home. The whole project required four. Each set included one microcontroller (AVR on the Arduino), one DFPlayer Mini MP3 Player for Arduino, one microSD card, one speaker and two HC-SR04 ultrasonic sensors. For the prototype I chose Arduino Uno for the ease of hooking up the wires to the peripherals. The MP3 module has no problem supporting a 3W speaker, so I used it in the project, but for the prototype I chose a higher watt speaker that required an amplifier module to drive them. The SD card is loaded with the mp3 files which are matched to each symbol. All of the electronics sets are running on 5V, so one 5V 30A power supply should be more than enough to power the project.

Watch the prototype test SUIC stair sweeper here.

Here is how the prototype basically works. The HC-SR04 ultrasonic sensors are set with the appropriate distances to detect when human stepping on the traps or rewards. After the HC-SR04 ultrasonic sensor detects any objects in range a sound will play according to the symbol the sensor is paired with. Four different symbols are mapped to four different sounds.

A team member soldering pin headers to an Arduino Nano
Here is an image of the first time soldering. On the right-hand is 3W speaker. After we finish assembly all of the units in the lab. Its time for on-site installation.

Here is the schematic of each unit. The units are powered by a 5V power supply, + for VIN pin and – to GND pin. The schematic of the staircase circuit, built on Fritzing platform, including two HC-SR04 ultrasonic sensors, an Arduino Nano, an SD card reader, and a 3W speaker.

The schematic of the staircase circuit.
The schematic of the staircase circuit.

Here is the schematic of each unit. The unit is powered by a 5V power supply, + for VIN pin and – to GND pin.

Schematic diagram for Mario Stairs project
The schematic of the staircase circuit, built on Fritzing platform, including two HC-SR04 ultrasonic sensors, an Arduino Nano, an SD card reader, and a 3W speaker.
PCB layout for the ultrasonic sensor and audio player board
PCB Layout
Photo of final PCB
Final PCB board ready to be soldered on.

We had to place each box at the exact location we were preparing, because if we misplaced them, the triggered sound would be wrong and we’d need to reopen the enclosure and reinstall the code. The wire length needed to be adjustable due to the measuring error. 

The Ultrasonic required 4 pins to function: Vin, GND, Echo, and Trig. I used two black power wires—each with red and black wires inside to connect the sensor modules to the Arduino microcontroller modules, as you can see in the image.

Final top view of the staircase with Super Mario inspired electronics
Final view of the staircase ready for students in the coming school year!

Here is how the staircase project looked when it was ready to be tested—no obstructive wires in sight. We spent one more day debugging code and rewiring an electronics.

And here is the project in action. We finished the project in the summer, so no students were present at the time. We’ll need to wait until the semester starts again to see whether we’ve achieved our goal or not.

Code

#include "Arduino.h"
#include "SoftwareSerial.h"

//Library that I chose to control mp3 module
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(10, 11);  // RX, TX
DFRobotDFPlayerMini myDFPlayer;

// Two ultrasonic pins setting up
#define trigPin1 9
#define echoPin1 8
#define trigPin2 7
#define echoPin2 6

long duration, distance, distance1, firstSensor, secondSensor;

void setup()
{
  mySoftwareSerial.begin(9600);
  Serial.begin(115200);

  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);

  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
 
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true);
  }
  Serial.println(F("DFPlayer Mini online."));

  myDFPlayer.volume(30);  //Set volume value. From 0 to 30

}

void loop() {

  // read distance data from both sensors
  SonarSensor(trigPin1, echoPin1);
  SonarSensor1(trigPin2, echoPin2);
  firstSensor = distance;
  secondSensor = distance1;

  // I prioritize the first ultrasonic first, so the two sounds will not be overlapped
  if (distance < 40 && distance > 10) {
    myDFPlayer.play(1);
    delay(1000);
  } else if (distance1 < 40 && distance1 > 10) {
    myDFPlayer.play(2);
    delay(500);
  }

}

void SonarSensor(int trigPin,int echoPin)
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
}

void SonarSensor1(int trigPin,int echoPin)
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance1 = (duration/2) / 29.1;
}


Future implementation

There are several ways this project can be implemented in the future. First, we can make question mark boxes like the ones in the Super Mario games in the areas between both floors that require humans to jump or hit them. When we hit the box, something might pop up above the box by a linear motor—or an LED might light up. Second, the symbol on the floor only has sound feedback right now. If we add tactile feedback when we step on the symbol, this will make the project much more fun to play with. 

This workshop is doing an experimental project that serves as a mind opener to students, encouraging them to recognize that technology is not limited to smartphones and the internet, but that technology can be applied to many areas in our life which usually go untouched. 

Salutes to all the kiddos Yong, Nat, Petch, Kim, Kap! 🙂

With so many aspects of our lives run by electronics, PCBs are like the glue that holds modern life together. Do you have an idea for a project? Try Upverter today, or get more inspiration about the types of projects you can do in Upverter. 

By Natthakit Kangsadansenanon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s