The Arduino is a wonderful little micro-controller that costs less than $50.

The Arduino

From the Arduino website:
[quote style=”1″]Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators.[/quote]

The scientific researcher is not limited to using Arduino “shields”; you can wire up just about anything to the Arduino, including existing expensive hardware such as shockers, doors, or food hoppers.

All of this makes the Arduino an ideal low-cost way of allowing Experimentor to sense and affect the environment. Of course, Experimentor will save all the input from the Arduino into the Experimentor database along with all of your other session data.


Configure the Arduino to work with Experimentor

Before you can use the Arduino from Experimentor, you must configure it to respond to commands from Experimentor, and to send incoming sensor data back to Experimentor.

Setting up the Arduino device in Experimentor

For each Arduino pin you want to use, you’ll need to define the port, pin, and pin type; for digital pins you’ll also need the pin’s direction, and for digital output pins also the pin’s output type:

define port = "COM3" Define which COM port you are trying to connect to, as a string;
the default is “COM3″.
define pin = 4 Define the Arduino pin number to use, as a number;
the default is pin 2.
define pinType = "digital" Defines if you are trying to use on of the digital pins or one of the analog pins;
valid values are “digital” or “analog”, and the default is “digital”.
define direction = "output" This setting defines if this pin will be an input or an output pin, as a string. Valid values are “input” or “output”; the default is “output”.
define outputType = "highLow" Valid only for digital output pins, this controls if the output pin will be a typical digital high/low output pin, or if it will use pulse width modulation (PWM).
The default is “highLow”, and the only other possible value is “pwm”. 

Only certain pins on the Arduino are capable of supporting PWM.  On the Arduino Uno these are pins 3, 5, 6, 9, 10, and 11.
On the Arduino Mega these are pins 2 – 13.

Any changes to these values after the device has been created are ignored.

There are also some advanced settings that you will probably never need.

Using the Arduino

There is only one variable for each Arduino “device”: the “Value”.  If the device is configured to an output pin then the “Value” variable will write the value out to the Arduino on that pin. If the device was configured as an input pin, then reading from “Value” will return the last input value reported by the Arduino.


Here’s a set of codes that use the Arduino. There is only a single Arduino hooked up to the computer through the USB cable, but we create two devices – one will control the output to pin 13, and the second will control the output to pin 6, which on the UNO is a pulse-width modulated pin. Then, the session loops through 2000 times, turning the Arduino’s on-board LED on and off, and slowly increasing the brightness of the pin 6 LED (which you will need to wire up as described here). The Arduino’s PWM pins only support values from 0 to 255 (8 bits of data), so once the counter is greater than 255 the value sent to the Arduino actually “loops around”, and starts at zero again – this is because only the bottom 8 bits of the counter are actually sent to pin 6. So if you do wire up an LED to pin 6 you’ll see it get brighter and brighter, and then suddenly go dark and slowly get brighter and brighter again repeatedly.