Ports and connections
This article covers the ports on the Behavior device, as well as how to connect the device to peripherals and external devices.
Ports

12V PWR (Barrel Jack) - This port powers the Behavior device and requires a 12 V power supply.
USB (USB-C) - This port connects the device to the control computer running Bonsai or the Behavior app.
CLKIN (Stereo Jack) - This Harp clock input accepts a clock output from any compatible Harp clock generator or synchronizer (e.g. Harp Timestamp Generator) for synchronization with other connected devices.
STATE - This status LED cycles on and off with a period of:
- 2 seconds when it's communicating with Bonsai
- 4 seconds when in standby
- 100 milliseconds when a catastrophic error occurs
P0, P1, P2 (RJ45) - These poke ports interface directly with the Mice Poke peripheral for poke detection and reward delivery. Alternatively, use the Breakout to interface with other accessories. Port P2 also has a quadrature counter for rotation tracking. Use it with the Rotary Encoder peripheral, or with a quadrature encoder connected through the Breakout.
ADC (Screw Terminal) - This connector carries the first analog input (AD0), a 5 V supply pin and two ground connections.
Output (Screw Terminal) - These general-purpose 5 V digital outputs can be used to communicate with external devices. DO0/DO1 can generate camera triggers and DO2/DO3 can control servo motors; all four support PWM.
Input (Screw Terminal) - This connector carries the second analog input (AD1), the digital input DI3 and one ground connection.
RGB (3-pin Flick Lock) - Connector for up to two addressable RGB LEDs (WS2812-type, e.g., NeoPixels). The LEDs are controlled as a serial chain on a single data line, with colors set with the RGB registers.
L0, L1 (Screw Terminal) - These connectors control two conventional single-color LED outputs. Each terminal pair is marked A (anode, the LED's long leg) and K (cathode, the short leg). The output current is configurable from 2 to 100 mA.
Connections

To connect a logic-level output to an external device:
- Wire a digital output from DO0–DO3 on the Output connector to the external device's digital input. Alternatively, use the Breakout to access more digital outputs on the poke ports.
- Connect the external device's ground to any GND pin.
- Refer to the Control digital outputs article to output digital events in Bonsai.

To connect a load such as a conventional LED:
- Wire a digital output from DO0–DO3 on the Output connector to one end of a series current-limiting resistor (100 to 330 Ω is typically used).
- Wire the other end of the resistor to the long leg (anode, A) of the LED.
- Wire the short leg (cathode, K) of the LED to any GND pin.
- Refer to the Control digital outputs article to control the output in Bonsai.
Note
Conventional LEDs can also be connected on the L0/L1 connector, where the current is configurable and no series current-limiting resistor is needed.

Before connecting the Photodiode peripheral, insert the stereo plug cable into the stereo jack on the peripheral. The other end of the cable has three color-coded wires for the signal, 5 V supply and ground.
For an analog reading:
- Use the switch on the side of the casing to select ANA.
- Wire the signal wire to either AD0 on the ADC connector or AD1 on the Input connector.
- Connect the ground wire to any GND pin.
- Wire the supply wire to the +5V pin on the ADC connector.
- Refer to the Acquire analog data article to read the light intensity as an analog reading in Bonsai.

For a digital reading:
- Use the switch on the side of the casing to select DIG.
- Wire the signal wire to DI3 on the Input connector. Alternatively, use the Breakout to access more digital inputs on the poke ports.
- Connect the ground wire to any GND pin.
- Wire the supply wire to the +5V pin on the ADC connector.
- Refer to the Read digital inputs article to read the light intensity as a digital input reading in Bonsai.
- Turn the adjustment screw on the side of the Photodiode casing to tune the light threshold for the low and high state of the digital output and monitor the response in Bonsai.
Note
Third-party photodiode modules that are powered with 5 V and output a 0 to 5 V signal can be wired the same way.

- Wire the + terminal of the Speaker peripheral to one of DO0–DO3 on the Output connector.
- Wire the - terminal to any GND pin.
- Refer to the Generate PWM article to play tones in Bonsai.
Note
Third-party passive buzzers or speakers can be controlled with PWM in the same way as the Speaker peripheral. Active buzzers generate a fixed tone, so switch them on and off using general purpose digital outputs, instead of PWM (see Control digital outputs). Add a current-limiting series resistor (100 to 330 Ω is typically used) to avoid overloading the 5 V supply.

- Wire the long leg (anode, A) of a conventional single-color LED to the A pin of either the L0 or L1 terminal pair. No series current-limiting resistor is needed as the supply current can be set in Bonsai.
- Wire the short leg (cathode, K) to the K pin of the same terminal pair.
- Refer to the Control LEDs article to configure and switch the LEDs in Bonsai.

- Connect the signal wire of an addressable RGB LED to S on the RGB connector. Analog RGB LEDs are not supported.
- Connect its ground wire to G.
- Connect its power wire to 5V.
- Up to two RGB LEDs can be controlled. Connect the second one as a serial chain with the same wiring configuration.
- Refer to the Control LEDs article to set the colors and switch the RGB LEDs in Bonsai.
Note
The RGB connector is a 2.54 mm Molex KK header with a friction lock. You can assemble a mating connector with a Molex KK crimp housing (22-01-3037) and three crimp terminals (08-50-0160). Dupont style female jumper wires also fit, but without a latch they hold by friction alone.

- Connect the Mice Poke peripheral to port P0, P1, or P2 with an RJ45 cable.
- If you are using a variant of the Mice Poke peripheral with the integrated water valve, connect the valve's inlet to the liquid container with tubing.
- Refer to the Control poke peripheral article to configure and use the Mice Poke peripheral in Bonsai.
No further wiring is necessary. The screw terminal blocks are only needed for external use; they share the same connections that are carried by the RJ45 connector.
Use them to connect an extra sensor, wire a solenoid valve, add an additional cue LED, or log the peripheral signals.
To connect a sensor like a lever:
- Wire one contact of the lever switch to DIO1. This line is not connected to any of the sensors onboard the Mice Poke peripheral and can be used as an active-low digital input (the functionality to toggle it to digital output has not been added yet).
- Wire the other end of the lever switch to GND.
- Refer to the Read digital inputs article to read the signal in Bonsai.
To wire a solenoid valve for reward delivery (for Mice Poke variants without integrated water valves):
- Wire a 12 V solenoid valve across the terminal pair. For standard coil-only solenoid valves, polarity does not matter.
To add an additional cue LED (for instance, at a different location):
- Wire the long leg (anode) of an LED to the LED terminal. No series current-limiting resistor is needed as the terminal already has one.
- Wire the short leg (cathode) to any GND terminal.
- The additional cue light is controlled by the same signals as the onboard cue LEDs, refer to the Control poke LEDs article to control them in Bonsai.
To log the peripheral signals on an external device:
- Wire the signals (5 V logic) to digital inputs on the external device:
- IR LED - Reports the status of the onboard infrared beam emitter.
- IR PHT - Reports the status of the onboard infrared photodetector.
- LED - Reports the status of the onboard cue LEDs.
- Share ground between the external device and any GND terminal.

- Connect the Rotary Encoder peripheral to port P2 with an RJ45 cable. This is the only port with the quadrature counter functionality.
- Refer to the Track rotary encoder article to read the encoder in Bonsai.
No further wiring is necessary to use the encoder with the Behavior device. The solder pads are only needed to access the raw quadrature signals for logging.
To log the raw quadrature signals:
- Wire the A quadrature signal (5 V logic) to a digital input on the external device.
- Wire the B quadrature signal (5 V logic) to a digital input on the external device.
- Share ground between the external device and the - pad.
Note
The Harp Behavior Rotary Encoder is meant to demonstrate simple rotational tracking. For applications in which high resolution tracking is needed, such as a running wheel, use a more precise quadrature encoder. We also recommend using the Breakout instead of the solder pads on this peripheral for an easier connection with external quadrature encoders.

- Check the camera specifications to ensure it has GPIO (general purpose input/output) and individual frame triggering capabilities.
- Refer to the camera manual to understand the connector pinout of the specific model you have. Locate a connector pin that can be configured as a digital input line for that camera. Locate its corresponding ground pin.
- Check that the camera input is compatible with the 5 V trigger signal from the Behavior device. For cameras with lower-voltage trigger inputs (e.g. 1.8 V or 3.3 V logic), add a level shifter between the output and the camera.
- Using the camera vendor's software, configure the camera to use the digital input line corresponding to the input pin you selected. Set the image capture mode to use the rising edges of the incoming pulse to trigger each frame capture.
- Insert the appropriate cable that mates with the connector on the camera and provides wire terminals for the connections.
- Connect the camera's digital input pin you selected to DO0 or DO1 on the Output connector. These are the only ports that support the camera trigger functionality.
- Connect the camera's ground pin corresponding to the digital input pin you selected to any GND pin.
- Refer to the Trigger cameras article to configure, start and stop the trigger in Bonsai.

- Connect the servo signal wire to DO2 or DO3 on the Output connector. These are the only ports that support the servo functionality.
- Connect the servo power wire to the +5V pin on the ADC connector. Alternatively, use the Breakout to access more power pins on the poke ports. For servos that draw more than 200 mA, or that require a supply voltage other than 5 V, power the servo from an external supply matching its rating instead. Never connect the external supply to the Behavior device's 5 V pin; it must power the servo only.
- Connect the servo ground wire to a GND pin. For servos requiring an external power supply, connect the external supply's ground to a GND pin.
- Refer to the Control servo motors article to move the servo in Bonsai.

This section describes the connections required for different uses of the Breakout. Note that some functionality is only available in specific versions of the Breakout.
To connect digital inputs and outputs (both v1.1 and v2.x):
- Connect the Breakout to port P0, P1, or P2 with an RJ45 cable.
- Wire the signal wire from external devices to the DI, DIO, or DO screw terminals.
- Wire the external device's ground to a GND terminal.
- If the external device needs power, wire its supply to the +5V terminal.
- Refer to the Read digital inputs and Control digital outputs articles to use these lines in Bonsai.
To connect an external quadrature encoder (both v1.1 and v2.x):
- Connect the Breakout to port P2 with an RJ45 cable. The quadrature counter is only available on this port.
- Wire the encoder's A channel to the DI terminal. Both channels must be 5 V logic.
- Wire the encoder's B channel to the DIO terminal.
- Wire the encoder's ground to a GND terminal.
- Wire the encoder's supply to the +5V terminal. For encoders that require a different supply voltage, power the encoder from an external supply instead and share only its ground with the GND terminal.
- Leave any index (Z) output of the encoder unconnected as the Behavior device does not support it.
- Refer to the Track rotary encoder article to read the encoder in Bonsai. If the count runs in the opposite direction to the rotation, swap the A and B wires.
To control valves for reward delivery (v1.1 only):
- Connect the Breakout to port P0, P1, or P2 with an RJ45 cable.
- Wire a 12 V solenoid valve between the +12V and SUP_RTN terminals.
- Refer to Deliver rewards on poke to pulse the valve line in Bonsai.
To stream the serial timestamp (v2.x only):
- Connect the Breakout to P2, the timestamp stream can only be transmitted on this port.
- Wire the TX terminal to the receiving device's RX input or to a logged digital input.
- Wire a GND terminal to the receiver's ground.
- Set the logic-level jumper of the Breakout to match the receiver's operating voltage level (3.3 V or 5 V).
- Refer to the Transmit serial timestamps section to enable the stream in Bonsai.

- Connect a CLKOUT of a Harp clock generator (e.g. the Harp Timestamp Generator) to the CLKIN jack with a stereo plug cable.
- The Behavior device adopts the generator's clock automatically. To verify the connection, check that the STATE LEDs of the connected devices blink simultaneously.
- Refer to the Harp synchronization clock documentation for how devices synchronize.
Documentation for release v3.4.0