Reading Ultrasonic Sensor Data to FireFly

Introduction: Reading Ultrasonic Sensor Data to FireFly

About: Hello everyone, Thanks for checking out my work on here. I am a Graduate Architecture student at the Academy of Art University in San Francisco currently working on my thesis. I am looking at ways of creatin…

This Instructable will be looking at how to configure a Ultrasonic Sensor using Arduino and Firefly for the purpose of detecting an objects distance and either changing geometry within Rhino and eventually how to use the data for clash detection within an autonomous machine.

What you need:

  • Rhino 5
  • Grasshopper 3D Version 0.9.0075
  • Firefly Version
  • Arduino
  • Firefly Firmata
  • Arduino Uno
  • Breadboard
  • USB A to B
  • 3 Jumper wires
  • Ultra Sonic Sensor (I used RadioShack® Ultrasonic Range Sensor but any will work)

Step 1: Loading the Firefly Firmata Onto Your Arduino Uno

  1. Loading the Firefly Firmata_ Ping onto the Arduino Uno
    1. Connect the Arduino Uno to your computer and launch the Arduino software
    2. Open the Firefly Firmata into the Arduino software and upload it to your Arduino Uno.
    3. Not what port your Arduino Uno is connected to by going to:
      • Tools > Serial Port
      • Close the Arduino Software

Step 2: Connecting the Ultra Sonic Sensor to You Arduino Uno

What you'll need:

  • Arduino Uno
  • Ultra Sonic Sensor
  • Bread Board
  • 3 Jumper Wires
  1. Plug your sensor into the Bread board so there are still open holes behind it
  2. Insert 3 different colored jumper wires behind the connecting pins of the Sensor in the Bread Board.
  3. Noting which cable corresponds to which sensor insert the correct wire into the Arduino Uno Board
    • GND to GND
    • VCC to the correct power (in my case 5V)
    • SIG to a Digital Pin (I am using Digital Pin 2)

Step 3: Starting Your Sketch and Opening a Port

  1. Launch Rhino and Grasshopper
  2. Start your Firefly sketch by navigating to the Firefly tab in Grasshopper
    1. Opening the Port
      1. Click on the Port node and bring it into your sketch
      2. Create a Panel and connect it to the "Ports Available" node.
        • This will let you see what ports are available on your machine, and is why you will need to know what port your Arduino Uno is connected to
      3. Create a "Value List" node and double click on it
      4. Enter the Value's item you see in your Panel
        1. In my case I will enter "0" and "1" and click "OK"
        2. select the port that your Arduino Uno is on by clicking on the down arrow
      5. Insert a "List Item" node
        1. Connect your Panel to the L input
        2. Connect the Value List to the i input
      6. Insert a "Open Port" node into the sketch
        1. Connect the "List Item" node to the "Port" input
      7. Insert a "Boolean Toggle" to the Sketch
        1. Connect it to the "Open" input
      8. Create a "Value List" and edit the values to include and connect it to the "Baud" input on the "Open Port" node
        • 2400, 4800, 9600, 14400,19200, 28800, 38400, 57600 and 115200
        • Select the 115200 value
      9. Connect a Panel to the "Msg" output of the "Open Port" node
      10. Double Click on the False Button in your Toggle node to turn it to true
      11. You should now see your panel coming from the open port reading
        • "Hooray! The serial port is open and you may now begin reading or writing data to the serial port."

Step 4: Reading From the Arduino Board

Now that you have your Port opened the next step is to read the data that the Ultra Sonic Sensor is collecting.

  1. Insert a "Uno Read" and another "Boolean Toggle" node into the sketch
    1. Connect the newly added "Boolean Toggle" to "Start" input
    2. Connect the "List Item" that is calling out what port to the "Port" input
  2. Attach Panels to the outputs of the "Uno Read"
    1. I like to group my panels for the outputs I'm not using and leave the ones I am as individual
      1. Connect APin0 to APin5 to a Panel
      2. Connect DPin2 to a Panel
      3. Connect DPin4 and DPin7 to a Panel
      4. Connect Msg to a Pannel
        • You will see that these have the value of <null> and the Msg will read "The serial port is open so you may begin reading data by setting the Start boolean value to True."
        • Insert and Attach a "Timer" node to the "Uno Read" and set it to the time you want it to run commands
        • Double Click the Toggle attached to "Uno Read"
        • If you look in the DPin2 Panel as you move an object closer and further from the Scanner the values will change
          • The Default unit is Centimeters, you can either modify this in the Firmata or do conversion within Grasshopper

Step 5: Converting to a Different Unit

If you don't want to use CM as your base unit you can convert the distance reading either in Firefly or the Firmata. I chose to use Firefly and use an add in called "TT Tollbox" but you can also do a multiplication function to accomplish this. The reason I am using the TT Toolbox plugin is because it lets you switch quickly between units.

  1. Navigate to the TT Toolbox tab and insert a unit converter node into the sketch
    1. Connect the output from the Panel attached to DPin2 to the "F" input
    2. Create a Value List node and edit the contents to:
      • MM
      • CM
      • M
      • IN
      • FT
    3. Create a duplicate and attach one to the "Target Unit" (TU) input and change it to the unit that you want to display, and the other to the "Source Unit" (SU) Input and change it to "cm".
    4. Attach a Panel to the "Value" output to see the converted number

Be the First to Share


    • Puzzles Challenge

      Puzzles Challenge
    • Lamps Challenge

      Lamps Challenge
    • CNC and 3D Printing Contest

      CNC and 3D Printing Contest



    7 years ago on Introduction

    Nice instructable, thanks.

    slightly off topic but have you tried to send data via ultrasonic? Would you know of any instructables where some one has and what sort of data rate you can get with a set up like yours ?