Arduino Optical Gate Protocol

This protocol controls an infrared optical gate connected to the microcontroller.

How to build a test circuit with a LED, a phototransistor and an Arduino Mega?
Arduino codes are included.

I. "Welcome" event from microcontroller

Example

c=welcome&id=4dgbhf&type=OzOpticalGateController&pos=2&t=3

Parameters

Parameter Type Range Functionality
c String "welcome" Identifies the welcome message.
type String "OzOpticalGateController" Determines the type of the devicehandler.
pos Byte 0-255 Determines the position of the device on the list of the ID manager of the microcontroller. Please make sure there are no other devices in the same position.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



II. Commands to microcontroller

'EnablePullup' command

Adds resistor to optical gate pin by setting it HIGH in INPUT mode. It is useful if there is a problem with the optical gate. Malfunctions can happen if the optical gate is not grounded, which can be prevented by using this command.

c=enablepullup&state=1&id=A47vvH&t=0

Parameters

Parameter Type Range Functionality
c String 'enablepullup' Identifies the command.
state Bool 0,1 With 1 you can add an integrated resistor, 0 disconnects the integrated resistor. If the optical gate is perfectly wired, it should work in both states.
id String 6 characters (numbers, uppercase and lowercase characters) Identifies the device. The ID is never changed during communication.
t Byte 0-255 Counts the number of commands. Counts from 0 to 255 then from 0 again.

Response

c=enablepullup_resp&state=1&id=A47vvH&t=4

Parameters

Parameter Type Range Functionality
c String 'enablepullup_resp' Identifies the event.
state Bool 0,1 If 1 the resistor is connected, 0 means the integrated resistor is disconnected. If the optical gate is perfectly wired, it should work in both states.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



'GetState' command

This command returns the actual state of the wired optical gate.

c=getstate&id=A47vvH&t=1

Parameters

Parameter Type Range Functionality
c String 'getstate' Identifies the command.
id String 6 characters (numbers, uppercase and lowercase characters) Identifies the device. The ID is never changed during communication.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.

Response

c=getstate_resp&state=1&id=A47vvH&t=5

Parameters

Parameter Type Range Functionality
c String 'getstate_resp' Identifies the response.
state Bool 0,1 It is the actual state of the optical gate. 0 means LOW STATE, 1 means HIGH STATE.
id String 6 characters (numbers, uppercase and lowercase characters) Identifies the device. The ID is never changed during communication.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



'SetMode' command

This command sets the mode of the 'ButtonStateChange' event.

c=setmode&mode=3&id=A47vvH&t=2

Parameters

Parameter Type Range Functionality
c String 'setmode' Identifies the command.
mode Byte 1: change
2: falling
3: rising
Sets which cases the 'ButtonStateChange' event should be sent.
id String 6 characters (numbers, uppercase and lowercase characters) Identifies the device. The ID is never changed during communication.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.

Response

The mode of the 'ButtonStateChange' event has been set.

c=setmode_resp&state=3&id=A47vvH&t=6

Parameters

Parameter Type Range Functionality
c String 'setmode_resp' Identifies the response.
mode Byte 1: change
2: falling
3: rising
Responds the mode of the 'ButtonStateChange' event.
id String 6 characters (numbers, uppercase and lowercase characters) Identifies the device. The ID is never changed during communication.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



'GetMode' command

Requests how the 'ButtonStateChange' event works.

c=getmode&id=A47vvH&t=3

Parameters

Parameter Type Range Functionality
c String 'getmode' Identifies the command.
id String 6 characters (numbers, uppercase and lowercase characters) Identifies the device. The ID is never changed during communication.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.

Response

The current mode of the 'ButtonStateChange' event.

c=getmode_resp&state=3&id=A47vvH&t=7

Parameters

Parameter Type Range Functionality
c String 'getmode_resp' Identifies the response.
mode Byte 1: change
2: falling
3: rising
Responds the mode of the 'ButtonStateChange' event.
id String 6 characters (numbers, uppercase and lowercase characters) Identifies the device. The ID is never changed during communication.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



III. Event from microcontroller

'ButtonStateChange' event

This event is sent from the microcontroller if the status of the optical gate changes. It depends on the mode you have previously set.

Example

//Button state changed to false
c=buttonstatechange&state=0&id=A47vvH&t=1

//Button state changed to true
c=buttonstatechange&state=1&id=A47vvH&t=2

Parameters

Parameter Type Range Functionality
c String 'buttonstatechange' Identifies the event.
state Bool 0,1 It is the actual state of the optical gate. 0 means LOW STATE, 1 means HIGH STATE.
id String 6 characters (numbers, uppercase and lowercase characters) Identifies the device. The ID is never changed during communication.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.

More information