Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by vauthier · Oct 24, 2016 at 03:14 AM · arduinosensor

Arduino PIR sensor to unity

Hi, I'm novice and I try to send Arduino Pir motion sensor values to Unity.5. What I want to do its: When someone approach, stay front and so activate the IR sensor that change the scene in Unity3D. When this person leaves the detection zone, the original scene or another scene is loaded. Without use UNIDUINO, how I can do this?

For the moment just my sketch arduino works, I follow this tutorial > https://www.youtube.com/watch?v=vJgtckLzoKM but it is really the good one for what i want to do?

Thanks community!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xflagx · Oct 24, 2016 at 09:03 PM

Here you will find an excellent tutorial targeting your case!

http://www.alanzucconi.com/2015/10/07/how-to-integrate-arduino-with-unity/

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vauthier · Oct 25, 2016 at 04:22 AM 0
Share

I try to understand this tutorial but finally Its not too easy for me. I have an arduino error about "errorhandler" and the final patches are too difficult to know. I'm lost in the code...@xflagx

avatar image xflagx · Oct 25, 2016 at 10:02 AM 0
Share

First at all, stay calm :)

I recommend to make the arduino part as simple as possible... just read the sensor data and send it over the serial port use a delay of 50-100ms between the sensor samples...

Post the arduino code here... so we could take a look at it... Please be a bit more specific towards the error... I will provide you an complete example which should work out of the box See here... https://github.com/xfleckx/ReactionTimeExperiment you just need to replace the logic for the button press with your sensor data...

avatar image vauthier xflagx · Oct 25, 2016 at 06:18 PM 0
Share

Thanks you to help me @xflagx i'm very novice and i am thinking is more easy to program. :) Ok I keep calm..

So, in beggining I try to make this arduino tutorial video https://www.youtube.com/watch?v=vJgtckLzo$$anonymous$$$$anonymous$$ ( i success ) and this https://www.youtube.com/watch?v=of_oLAvWfSI tutorial video and try to combine them and edit for my sensor ( for PIR sensor, not for buttons) but i did'nt success.

I buy UNIDUINO to help me but is not so clear and I have always errors. I make a simple count in arduino and via serialport i print this count in unity, thats works but how i can set up unity to read the on/off of my PIr sensor and use this on/off to make what i want?

Here my last messy script!!!! :DD

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using Uniduino;             
 using System.IO.Ports;
 
 [RequireComponent(typeof(AudioSource))]
 
 public class uniduinopotard : $$anonymous$$onoBehaviour {
 
     SerialPort str= new SerialPort("/dev/cu.usbmodem411", 9600);
     
     public Arduino arduino;
 
     private AudioSource audio;
     
     public $$anonymous$$ovieTexture movie1;
     public $$anonymous$$ovieTexture movie2;
     public bool loop;
     public int pin = 2;
     public int pinValue;
 
     
     void Start( )
     
     {
 
         str.Open();                                      // Ouvre le serialport str
         str.ReadTimeout = 1;
 
 //        GetComponent<RawImage>().texture = movie1 as $$anonymous$$ovieTexture;
 //        audio = GetComponent <AudioSource> ();
 //        audio.clip = movie1.audioClip;
 //        movie1.Play ();
 //        movie1.loop = true;
 
         arduino = Arduino.global;
         arduino.Setup(ConfigurePins);
         arduino.reportDigital(0, 1);
 
     }
     
     void ConfigurePins( )
     {
         arduino.pin$$anonymous$$ode(2, Pin$$anonymous$$ode.INPUT);
 
     }
 
     void readData ()
         
     {
         
         if (!str.IsOpen)             // Si str n'est pas ouvert, ouvre-le!
             
         {
             str.Open ();    
         }
         
         {
             try    
                 
             {
                 Debug.Log(str.ReadLine());
             }
             
             catch(System.Exception) {}
         }
     }
     
     void Update () 
     {       
         pinValue = str.ReadLine ();       //<<<<< i can do that but its precisely what i want to do how can i ???
 
             if (pinValue == 0)
     
         {
             GetComponent<RawImage>().texture = movie1 as $$anonymous$$ovieTexture;
             audio = GetComponent <AudioSource> ();
             audio.clip = movie1.audioClip;
             movie1.Play ();
             movie1.loop = true;
             
             movie2.Stop ();
 
         }
         if (pinValue == 1)
 
         {
             GetComponent<RawImage>().texture = movie2 as $$anonymous$$ovieTexture;
             audio = GetComponent <AudioSource> ();
             audio.clip = movie2.audioClip;
             movie2.Play ();
             movie2.loop = true;
             
             movie1.Stop ();
 
         }
 }
 }



avatar image xflagx vauthier · Oct 25, 2016 at 09:09 PM 0
Share

since C# is statical typed 'pinValue = str.ReadLine()' will not work... str.ReadLine() returns a String object which could be parsed to a Int with Int.Parse or Int.TryParse

var aStringFromSerialPort = str.ReadLine (); int aTempValue; if( ! int.TryParse(aStringFromSerialPort, out aTempValue)){ // do some Error Handling since the String did not contain a number }else{ pinValue = aTempValue; // the string could be parsed and can be interpreted... }

if this is not the only issue... please post all errors you get!

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I manage the information from a sensor photoresistor in arduino? 0 Answers

Read multiple sensor values independently from arduino to unity 2 Answers

Not Fully Understanding how To Correctly Receive LDR Arduino Data 0 Answers

Change Value Of UI Light Slider to Read At Specific Points Of Slider Value 1 Answer

How to use RaycastHit ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges