Read values from a microcontroller digital input

The DigitalIn widget connects to digital inputs on the microcontroller and provides some processing of the sensor values. The default range for digital inputs 0 – 1, but this range is scaled by DigitalIn to any range desired by setting the min and max numbers. DigitalIn also has a button which allows the user to simulate the values of a sensor coming in, so the user can test other parts of their application with no external hardware hooked up.

For instructions on how to wire a switch for use with a microcontroller, see this page.

On Screen Features

  • connect: When on, reads data from the sensor at the selected port. When off, use the slider to set the value. The off mode is useful for when you don’t have the sensor and/or microcontroller hooked up, but still want to test what would happen. You can simulate the operation of the sensor clicking on the IN button.
  • in: A button display of the unprocessed data coming from the sensor. This can also be clicked on to simulate a hardware on or off when the widget is not connected.
  • max: Sets the highest value output. The highest raw value is scaled to this value
  • min: Sets the lowest value output. The lowest raw value is scaled to this value
  • smooth: When on, performs a median filter on the raw sensor readings so that the processed values are less jittery. This is helpful because many sensors produce rough readings that change more than you want.
  • invert: Makes a high raw value produce a low output value and visa versa. Useful for reversing the effect of a sensor
  • out: The value output by the widget after all processing is applied


  • controller – Determines where the input values come from – Device options are: Arduino, Xbee, iotnREST, OSC, accelerometer (mobile devices), mic, inputSource (values come from widget named in inputSource param), hubFeed (see the hubfeed Tutorial for more info), serial (any device that can connect to your computer via USB/Serial input can send numbers – see the serial tutorial)
  • controllerInputNum – Sets the analog input port on the controller – starts at 0 to use the first port on the controller. When using an inputSource such as OSC that may have multiple values, this number sets the argument used. E.g. in /acceleration/xyz 0.1 0.2 0.3, setting controllerInputNum to 2 would get the third argument for the Z value of 0.3.
  • controllerIP – Sets the IP address used to communicate with OSC or iotnREST.
  • controllerPort – Sets the IP Port used to communicate with OSC
  • hubFeedName – The name of the Hub feed to listen to. The hubFeed controller option allows the application to accept input from any arbitrary source that sends a feed to the Hub. See also the AnalogOut for sending a hub feed, and the HubFeed tutorial.
  • inputSource – Used if “inputSource” is selected in the CONTROLLER parameter, to get values from another widget this name.
  • invisible: If set to “true” or checked, the widget will disappear when the Flash movie is run – NOTE: you can make all the widgets invisible interactively when the Flash moving is running simply by pressing the backslash key “\”.
  • multiplier – This number is multiplied with the raw input number from the controller, if set to OSC, hubFeed, or accelerometer. Many OSC devices and software provide fractional values from 0-1. To work with other toolkit widgets, these numbers should be scaled up to an integer range, e.g. by setting multiplier to 1023.
  • remoteHubIP – This sets the IP address of the Hub where the widget will get input values from a microcontroller. Normally this would be for the Hub running locally. But set this to the IP address of another computer running a HUB, e.g. to access devices connected to that computer. Note that even if you are using a remote Hub, the Hub application must also be running locally on the same machine as the widgets.
  • sampleRate – The number of times per second the microcontroller port is queried for its value.
  • serialPort – For widgets set to communicate with an Arduino or XBee, the USB serial port name that the device is connected to. On the Mac, you can leave the default (/dev/cu.usb*) if only one device is hooked up. On the PC, replace this with the COM port used, e.g. COM7. For more detailed info on how to set this parameter, see the common features for all widgets discussion here.
  • smoothAmount – The size of the buffer for the smoothing. The larger the number, the more smooth the processed values will be, but the processed values output will have a longer delay from the actual sensor data.
  • urlString – This text is used for iotnREST and OSC inputs. For iotnREST, this is the URL sent to the remote device. For OSC, this is the OSC message that AnalogIn will listen for (e.g. “/slider/1” will listen for the message from iPhone app OSCemote’s first slider).
  • xbeeRemoteID – When using the Xbees, use this number to indicate which remote Xbee you wish to communicate with. (note, this is a decimal number, when configureing the XBee in XCTU the ID number you enter there is in hexedecimal).

Using OSC

The DigitalIn works with OSC, where any input value that equals 1 or great will be considered ON, and anything below 1 will be consider OFF. For more info on working with OSC, see the OSC tutorial page.

Code Interface


Causes the widget to connect to the controller, the same result as using the connect button.



Causes the widget to connect to the controller, the same result as using the connect button.


Last modified July 6th, 2014