We all have heard about AR(Augmented Reality) in our lives. We have even used that technology for couple of times. You don’t know about that? Well.. let me show a short introductory video about it.

So if you watched the video, you may already guessed about what we are going to make in the end. So let’s start our journey of combining two amazing technologies, AR & IOT to make futuristic project. Let’s get started….

Components Required

For Hardware part of the project you’ll need

  • ESP32 / NodeMCU board
  • 5V Relay Module

For Software part you’ll need

  • Blynk App
  • Unity Hub

Hardware Connection Diagram

IoT part of the project

For the IoT part, I have used Blynk IoT Platform. In which, I just made a simple blynk project of adding a button in the dashboard which will send data 0 & 1 to virtual pin V1.

After that, we have made a code in which, if we receive the data 1 from virtual pin V1, we just send the signal high to digital pin of ESP32 board which ultimately turns on Relay. And as soon as we receive 0 the relay gets turned off. You can copy and paste the code from below


/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "YourTemplateID"


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#define relay 15  // Relay pin

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  digitalWrite(relay,pinValue);
  // process received value
}


void setup()
{
  // Debug console
  Serial.begin(9600);
  pinMode(relay,OUTPUT);
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
}

Just change these three parameters in the code, to make it work on your side as well.

Till this step, we will be easily able to control the relay using the Blynk App. But we want to control that using API so that later on we can integrate it with AR. And the good news is that, Blynk do provide us APIs.

So to send the data to virtual pin of our blynk device, the format of API is something like this.

http://blynk-cloud.com/auth_token/update/pin?value=value

For example, If I want to send data ‘1’ to virtual pin ‘V1’ of my blynk project, the API will be like this,

http://blynk-cloud.com/MY_AUTH_TOKEN/update/V1?value=1

So with this, we have successfully covered the IoT part of our project. Now let’s jump on to the AR part.

AR part of project

For AR, we will be using Unity Hub software on our computer. Just goto this link and download unity hub

There are some many steps involved in setting up our Unity Hub software. For that, I’ll suggest you to watch the video from 05:39 time. Click here to start with AR part in the video.

While Setting up unity, you’ll need three things, one is the target image, second is Frame Image and third is C# Script. All the things are provided below, so you can easily download and use them

Taget Image
Frame Image for canvas

C# Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class ClickUrl : MonoBehaviour
{
    public string url;
    public void open()
    {
        StartCoroutine(GetRequest(url));
    }
 
    IEnumerator GetRequest(string uri)
    {
        using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
        {
            // Request and wait for the desired page.
            yield return webRequest.SendWebRequest();
 
        }
    }
}

You need to save this code with the name, ClickURL

Full tutorial Video

We have prepared a full detailed tutorial video for AR+IOT which is uploaded on YouTube. So in case you want to understand it in more clear manner, I’ll suggest you to go through this video and do let me know your feedback in comment section.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *