Photocoupler Module

This documentation includes hardware info, installation guidelines and sample code for your hardware.

Overall Info

Turta Photocoupler Module provides two optically isolated input channels. You can read on / off state of these channels. Each input is capable of reading 24V DC input.



Module Connections

  • INT: Channel 1 Interrupt.

  • GPIO: Channel 2 Interrupt.

External Connections

  • PC1 +24V: Channel 1 +24V.

  • PC1 GND: Channel 1 GND.

  • PC2 +24V: Channel 2 +24V.

  • PC2 GND: Channel 2 GND.


LTV-827S' technical specifications are as follows:

  • Input Voltage range: 9V to 30V DC.

  • Response time: Approx. 4us.

  • Input - output isolation Voltage: 5.000Vrms


To get maximum performance from your hardware, please make sure you'll meet the following requirements.


Photocoupler Module is an add-in board for Turta Modular System. You'll need a compatible host device for your module. The following devices support Photocoupler Module:

  • Turta IoT Node - ESP32


For ESP32 based systems, we're currently supporting Arduino core. Please make sure you've installed the following:

  • Arduino IDE.

  • ESP32 Hardware libraries for the Arduino IDE.

  • Python for the compilation of Arduino projects.

  • Drivers for your host device, e.g., USB Virtual Serial Port driver.


You'll need to install a library to make Arduino IDE support the module. This library includes drivers for the LTV-827S and sample code for you to jumpstart your project.


Please download the library archive from

Then, copy its contents to your Arduino Libraries folder.

You can find the Arduino Libraries folder inside your Arduino sketch directory. It is generally located inside the My Documents folder.


The library comes with included samples. There is no need to download additional files for the examples.

Source Code

The hardware, its drivers and the sample code are open source. You can use them under the terms of the MIT license. Please feel free to customize and prototype them for your projects.

Arduino Library

Turta_Photocoupler_Module library is responsible for reading the photocoupler inputs.

To use the library on Arduino IDE, add the following #include statement to the top of your sketch.

#include <Turta_Photocoupler_Module.h>

Then, create an instance of the Turta_Photocoupler_Module class.

Turta_Photocoupler_Module pc

Now you're ready to access the library by calling the pc instance.


To initialize the module, call the begin method.


This method configures the interrupt pins to read input state.

Basic Members

Read Input

Returns the state of the photocoupler inputs.

bool readInput(uint8_t ch)
  • Parameters

    • uint8_t: ch - Input channel, 1 or 2.

  • Returns

    • Bool: Input state


You can open the example from Arduino IDE > File > Examples > Examples from Custom Libraries > Turta Photocoupler Module. There is one example of this sensor.

Photocoupler Input

This application demonstrates the isolated input reading function of the module. It uses Arduino IDE's Serial Monitor and IoT Node's onboard LED to display input states.

To run the example:

  1. Open the IoT_Node_Photocoupler sketch from the examples menu.

  2. Select Turta IoT Node from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Open Serial Monitor from Tools > Serial Monitor.

  5. Select 115.200 baud from the Serial Monitor's status bar.

  6. Upload the code to your device.

Sample Code

#include <Turta_Photocoupler_Module.h>
#define LED 13
// Global variables.
bool input1State = false;
bool input2State = false;
bool oldInput1State = false;
bool oldInput2State = false;
// Create Photocoupler Module instance.
Turta_Photocoupler_Module pc;
void setup() {
// Initialize onboard LED.
pinMode(LED, OUTPUT);
// Initialize Photocoupler Module.
// Configure serial port.
void loop() {
// Read input states.
input1State = pc.readInput(1);
input2State = pc.readInput(2);
if (input1State || input2State) {
digitalWrite(LED, HIGH);
else {
digitalWrite(LED, LOW);
// On input 1 change.
if (oldInput1State != input1State) {
Serial.print("Input 1 State: ");
Serial.println(input1State ? "High." : "Low.");
// On input 2 change.
if (oldInput2State != input2State) {
Serial.print("Input 2 State: ");
Serial.println(input2State ? "High." : "Low.");
// Store last input states.
oldInput1State = input1State;
oldInput2State = input2State;
// Delay 10ms.


After the application is uploaded to the device, it writes input state to the Serial Monitor if the state is changed. The onboard LED is lit if any of the input channels are high. The example output should be like this:

Input 1 State: High.
Input 1 State: Low.
Input 2 State: High.
Input 2 State: Low.

The application runs forever until you clear it from memory.


If you're experiencing difficulties while working with your device, please try the following steps.

Problem: You connected a button to the photocoupler, but it does not read any input. Cause: The photocoupler module needs external 24V to be activated. Solution: Please consider using 24V power supply in your circuit.