ITTT - Project Distance - Jurre De Groot 1D

by Draganno in Circuits > Arduino

1155 Views, 0 Favorites, 0 Comments

ITTT - Project Distance - Jurre De Groot 1D

IMG_20210528_134014766.jpg

HKU Assignment

Hello all!
Welcome to my HKU ITTT - "If This Than That" Project.

For this assignment I created a simple eye test. The Distance Measuring Eye will give you a score based on the distance away from the eye.

In this Instructable I will show you my thought process and the steps I took in creating this project. Enjoy!

Supplies

Materials:

- Arduino Uno R3

- Ultrasonic Sensor

- 4 Cables

- Partible Styrofoam Ball

- Cardboard

- Paint (For the colors of the eye)

­

Tools:

- Scalpel

- Hot Glue Gun

- Blow-drier

­

Also Important, but optional if you just want the Distance Measuring Eye:

- PC/Laptop

- Unity (Game Making Program)

- Blender (For all your visual needs :D)

Getting Familiar

Knopje-lampje.jpg
Screenshot_2.png

In all honesty, it took me some time getting into the ITTT assignment. During the lessons I created the basic Arduino stuff, like a button that lights a little LED light. This was already somewhat of a challenge, but quite doable.

Initially I started thinking about letting the Arduino communicate with Unity. Ideas like; LED's as Hit Points, buttons moving your Unity Character, or using a servo to create some kind of game where the Unity Character could interact with the "outside" world. I soon realized this would be way too much coding work for me, so I put the assignment away for a bit.

Brainstorming & Initial Ideas

Iterations.png
IMG_20210522_173955384.jpg
unknown (1).png

Eventually I started talking to friends about recent (Non-ITTT) projects they worked on. One of them used the Ultrasonic Sensor to measure the height of a person, which gave me the idea to try something similar. I decided to ask him for help.

Using his help, I created the first basic functionality of what my project would become. He helped me through the process, just to get me started. But this would definitely not be the last time I needed to ask for help.

Connecting the Ultrasonic Sensor to the Arduino was easy enough. You just need 4 cables.

- Connect the Ground(GND) on the Arduino to the GND on the Sensor.

- Connect the Voltage(5V) on the Arduino to the Vcc on the Sensor.

- Connect the Digital 8 to the TrigPin on the Sensor.

- Connect the Digital 7 to the EchoPin on the Sensor.

With the Arduino and Ultrasonic Sensor properly connected, all I needed was the code.

Arduino code with the help of a friend:

#define echoPin 7
#define trigPin 8

float duration, distance;

//Hoogte van de sensor in CM
int hangHeight = 214;


void setup() {
  Serial.begin(9600);
  pinMode(echoPin,INPUT);
  pinMode(trigPin,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = (duration * .0343) / 2;
  Serial.print("Distance: ");
  Serial.println(distance);


  //hoogte persoon calc
  int persHeight = hangHeight - distance;

  Serial.print("Your Height: ");
  Serial.println(persHeight);

  if (persHeight < 150 && persHeight > 100){
    Serial.print("Tuindecoratie");
    delay(1000);
  }

  if (persHeight >= 150 && persHeight < 160){
    Serial.print("Afgewezen tuinkabouter");
    delay(1000);
  }

  if (persHeight >= 160 && persHeight < 170){
  Serial.print("Lichtelijk teleurstellend");
  delay(1000);
  }

  if (persHeight >= 170 && persHeight < 180){
  Serial.print("Normie");
  delay(1000);
  }

  if (persHeight >= 180 && persHeight < 190){
  Serial.print("Appelplukker zonder boomgaard");
  delay(1000);
  }

  if (persHeight >= 190 && persHeight < 200){
  Serial.print("Koelkastkijker");
  delay(1000);
  }

  if (persHeight >= 200 && persHeight < 210){
  Serial.print("Plafondruiger");
  delay(1000);
  }
}<br>

The code measures the distance between the top of your head and the Sensor and subtracts the given height of the Sensor. This then outputs texts in the serial monitor.

I knew I wanted to make something that was somewhat unique, so all I had to try to do was alter the code so it would suit my needs, but an idea had yet to really develop.

At this stage new ideas came to mind. Maybe I could create a device that automatically measures your height if you want to go in a roller coaster? No that would be too easy and too similar to his code. Plus, I wanted it to connect with Unity.

The idea of a goblin cave maybe? Maybe you would need to pass the goblin test to be allowed inside their cave? I still wasn't feeling this concept entirely.

But then, after just a couple days, it hit me...

The Idea

eye.png
Screenshot_4.png

One day I was talking with my dad, who wears glasses, about eyesight and how I "technically" need glasses, but only by a little bit. Up until a couple years ago I had no idea. If you only have a tiny bit of a bad eyesight some people would never even notice. This gave me the great idea of making something that is somewhat interactive, and shows how well your eyesight is in a way.

I decided to measure the travel distance, not the height.

This gave me the idea of an "All-Seeing-Eye" that would measure the distance between you and it.

­

I chose to stick with this idea, since I still had a lot to figure out. I rewrote parts of the code so it would suit what I needed.

My version of the Arduino code:

#define echoPin 7
#define trigPin 8

float duration, distance;

void setup() {
  Serial.begin(9600);
  pinMode(echoPin,INPUT);
  pinMode(trigPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = (duration * .0343) / 2;
  Serial.print("Distance: ");
  Serial.println(distance);

if (distance < 150 && distance > 100){
    Serial.print("Zwakzichtige");
    delay(2000);
  }

  if (distance >= 150 && distance < 160){
    Serial.print("Jij ziet HELEMAAL 0");
    delay(2000);
  }

  if (distance >= 160 && distance < 170){
    Serial.print("Jij hebt een bril nodig");
    delay(2000);
  }
}<strong><br></strong>

This code prints the distances in the Serial Monitor, and when it measures between a certain value it displays the corresponding text for 2 seconds. For me this was a big milestone. With the Arduino and Ultrasonic sensor set up, the code working, I know I was on the right way.

Uni-(ty)-fying

unknown.png
Screenshot_5.png
unknown3.png

The next big step was letting the Arduino communicate with Unity. I asked for help from a developer friend, I could never have figured this out on my own.

He helped me through the process, and actually connecting my Arduino to Unity proved easier than anticipated

Unity code that searches for the Arduino on COM4:

using UnityEngine.UI;
using System.IO.Ports;
using TMPro;

public class ArduinoTest : MonoBehaviour
{
    SerialPort sp;
    public Text txt;

    void Start()
    {
        txt.text = "Looking for Board";
        StartCoroutine(Search());
        InvokeRepeating("ScoreUpdate", 1f, 5f);
    }

    IEnumerator Search()
    {
        while (sp == null)
        {
            foreach (string str in SerialPort.GetPortNames())
            {
                if (str == "COM4")
                {
                    sp = new SerialPort("COM4", 9600);
                    sp.Open();
                    sp.ReadTimeout = 1;
                    txt.text = str;
                }
            }
            yield return new WaitForSeconds(1);
        }
    }
}<br>

While the SerialPort = null, the code searches for the Arduino on COM4, if Unity finds it, it shows "COM4". When "COM4" shows, Unity has established a connection with the Arduino on COM4.

Checklist:

The Ultrasonic Sensor is connected to the Arduino.

The Ultrasonic Sensor measures distance and displays those in a Serial Monitor.

Unity has established a connection with the Arduino.

Next I will make Unity read the data that's being printed to the Serial Monitor.

Reading Data

Screenshot_6.png
Screenshot_8.png

I, luckily, have a friend working in IT already. So for this particular issue I asked him for help. Getting the Arduino to give data to Unity is harder than I had originally thought it would be.

The Arduino sends certain strings, only consisting of numbers, to Unity. These numbers would need to be converted to do anything with them. Luckily my friend found some other ways of getting the data I want. I had the Serial Monitor data, so how could I just print those so Unity would understand?

Unity checking the lines of Serial Monitor Data:

void LateUpdate()
    {
        if (sp != null)
        {
            if (sp.IsOpen)
            {
                while (sp.BytesToRead > 0)
                {
                    char c = (char)sp.ReadChar();
                    CurrentLine += c;
                    if (c == '\n')
                    {
                        HandleLine (CurrentLine);
                        CurrentLine = "";
                    } 
                }
            }
        }
    }<br>

Unity writing a number from that given line:

  void HandleLine(string line)
    {
        if (float.TryParse(line, out var number))
        {
            CurrentValue = number;
        }
    }<br>

After all of this Unity finally prints the data to "Current Value". As seen in the picture above.

To create a simple points system, this "Current Value" value will have to be printed to a text in Unity.

­
Next step here we go!

Value to Text

Screenshot_7.png
unknown4.png

Lastly, as for the functionality, I wanted the values to be printed inside the running scene.

This way the people who use this product can easily see and track their points.

­

Since I was using TextmeshPro, I had to do things a little different when it came to the Public Variable. The code below shows how the Current Value gets refreshed every 5 seconds. In other code the Current Value changes a couple times each frame, and the InvokeRepeating command takes this value every 5 seconds and puts it in the Score variable.

public float CurrentValue = 0;
public TMPro.TMP_Text Score;

    void Start()
    {
        InvokeRepeating("ScoreUpdate", 1f, 5f);
    }

   private void ScoreUpdate()
    {
        Score.text = CurrentValue.ToString("0");
    }

So now Unity shows the values that "Current Value" prints!

Final Unity Code

Screenshot_3.png
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO.Ports;
using TMPro;

public class ArduinoTest : MonoBehaviour
{
    SerialPort sp;
    public Text txt;
    string CurrentLine = "";
    public float CurrentValue = 0;
    public TMPro.TMP_Text Score;

    void Start()
    {
        txt.text = "Looking for Board";
        StartCoroutine(Search());
        InvokeRepeating("ScoreUpdate", 1f, 5f);
    }

    void HandleLine(string line)
    {
        //Debug.Log (CurrentLine);
        if (float.TryParse(line, out var number))
        {
            CurrentValue = number;
        }
    }

    void LateUpdate()
    {
        if (sp != null)
        {
            if (sp.IsOpen)
            {
                while (sp.BytesToRead > 0)
                {
                    char c = (char)sp.ReadChar();
                    CurrentLine += c;
                    if (c == '\n')
                    {
                        HandleLine (CurrentLine);
                        CurrentLine = "";
                    } 
                    //Debug.Log((char)sp.ReadChar());
                }
            }
        }

    }

   private void ScoreUpdate()
    {
        Score.text = CurrentValue.ToString("0");
    }

    IEnumerator Search()
    {
        while (sp == null)
        {
            foreach (string str in SerialPort.GetPortNames())
            {
                if (str == "COM4")
                {
                    sp = new SerialPort("COM4", 9600);
                    sp.Open();
                    sp.ReadTimeout = 1;
                    txt.text = str;
                }
            }
            yield return new WaitForSeconds(1);
        }
    }
}

Final Arduino Code

Screenshot_9.png
#define echoPin 7
#define trigPin 8

float duration, distance;

void setup() {
  Serial.begin(9600);
  pinMode(echoPin,INPUT);
  pinMode(trigPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = (duration * .0343) / 2;
  Serial.println(distance);

//Previous code
//  if (distance < 150 && distance > 100){
//    Serial.print("Zwakzichtige");
//    delay(2000);
//  }
//
//  if (distance >= 150 && distance < 160){
//    Serial.print("Jij ziet HELEMAAL 0");
//    delay(2000);
//  }
//
//  if (distance >= 160 && distance < 170){
//    Serial.print("Jij hebt een bril nodig");
//    delay(2000);
//  }
//  
}

Burning the Pain Away

Screenshot_1.png
IMG_20210522_183104373.jpg

With all the code working I hit up a friend of mine who has a soldering iron. He taught me the basics and helped me remove the headers from the Ultrasonic Sensor and solder the cables to it as well. Removing the Ultrasonic Sensor headers meant I had to solder the cables directly onto the Sensor.

First I removed some of the plastic from the cables then I added some tin to the tips to "bind" the tiny copper cables together. This makes it easier to fit the tiny cables through the holes of the Ultrasonic Sensor. This went smoothly, and after a little test I knew it was working well.

The Making of the Distance Measuring Eye

IMG-20210525-WA0001.jpeg
IMG-20210525-WA0003.jpeg
IMG-20210525-WA0005.jpeg

For the eye I used a styrofoam partible ball, this meant I could open it up and fit the electronics inside, without much trouble at all!

Using a scalpel I cut out the holes for the Ultrasonic Sensor, as well as a hole in the back so the USB cable can go through out the back. I build a little platform for the Arduino to be attached to, so it fits neatly in the middle of the ball. It's also quite durable. The platform is being held together by hot glue, just as the Arduino.

Now that I knew how everything would fit together I started painting the actual eye.

Finalizing the Distance Measuring Eye

IMG_20210525_165000333.jpg
IMG_20210525_174646750.jpg
IMG_20210525_173908609.jpg
IMG_20210525_173930240.jpg
IMG_20210525_174706147.jpg

For the first layer I painted both parts completely white. I tried removing the little grooves that come naturally with styrofoam, but this didn't really work. I tried adding more white paint, but I soon ran out of paint and figured it'd be good enough.

Next-up I sketched the outlines of the pupil, iris and red parts of the eye. Then I layered in the first layer of colors. After each layer I blow-dried the paint so that I could work on it faster again. After a couple layers of paint I was happy with the results!

I added the Arduino construction to the insides, and was able to close the ball easily.

Meet the Distance Measuring Eye!

Frame by Frame...

Blender Anim
Screenshot_13.png
Screenshot_15.png
Screenshot_14.png

The Unity side of things was still... kind of bland. So I wanted to create a cool effect that would suit the points being displayed on the screen. I decided to try for an infinite looping video that would just play in the background.

Using Blender and a tutorial on infinite looping videos I created the looping background video.

Now to add it to Unity!

From Beast to Beaty

Screenshot_10.png
Screenshot_11.png
Screenshot_12.png

To spice up the Unity scene, I added the looping video background. Instead of using an mp4 video, which lagged for some reason, I decided to add all separate images, and then create an animation. This played at 12fps, which was too slow, so in the animator I just set the speed to play twice as fast.

That's how I got the looping background video!

Final Product

IMG_20210528_134031359.jpg
IMG_20210528_140952487.jpg

And this shows the final product!

During the presentations a group of people gathered around my project and really wanted to test their eyes, and of course I let them, that's what it was made for of course! As you can see in the scores, we have some range of different points, which suggests a lot of different eye sights.

Since my left eye is worse than my right eye, I do not have perfect vision. So I was really amused when people were able to spot the differences from so far away, so that was really fun to figure out.

Thanks for reading, I hope you enjoyed it!

What I've Learned

vectorafbeelding-van-een-archimedes-bad-duimt-eureka-griekse-wiskundige-oeroude-arts-170723680.jpg

There were many different road blocks during this project, I had yet to figure out how to even work with an Arduino.

During the project I learned many new things, like soldering, coding on the Arduino, connecting the Arduino to Unity, and of course how to make something interesting.

­

However,

I did find this project to be too disconnected from something useful for me personally, even though some parts were fun to work on. I spent a lot of time working on this project, only to learn that most of what I have been doing would not be useful for me in any way apart from iterating on design decisions. I was being held back by the lack of interest and motivation for the majority of the project. This might not be the right mindset, I know this, I am in school and have to follow the assignments. So of course I tried to do this.

If I were to put myself in the shoes of Developers, Designers and Interaction Designers, I could really see the implementation of a class/project like ITTT. Especially Interaction Designers have a great use for interactive projects like this. This project is a great way of getting a feel of what could be possible for interactive installations, while still feeling like a creative outlet for Game Artists/Artists that want to go in a direction like this.

My main focus is getting into the Concept Art industry for films and games, and I will focus most of my attention on this. Focusing on Concept Art is a high priority for me, and on some fronts spending a lot of time on this project held me back from reaching the goals that are important to me. I am really looking forward to the art related school classes, especially in the 2nd year, but to me this project felt too separated from my goals.

­

No hard feelings of course! I really enjoyed presenting my project to both my classmates and the teachers.

Thanks so much for reading till the end!

­

­

The End