Fiber optic using Arduino Uno

I have connected a Mikroe Fiber opt click board to an Arduino Uno for measuring the output voltage while measuring glucose in urine.

The fiber optic cable is coated with gold nanoparticles.

I have followed the following connection, 5 V and GND pins or Arduino to 5 V and GND pins of the Mikroe Fiber opt click board. Then connected the Tx of the Arduino to the Rx of the click board and vice versa.

I am getting the light passing through however, the output voltage is not changing at all. I am sharing the Arduino code and also the output. Please help me figure out where have I gone wrong.

#include <Wire.h>

// Fiber Opt Click I2C address
#define FIBER_OPT_CLICK_ADDRESS 0x28

// Registers
#define CONFIG_REG 0x00
#define STATUS_REG 0x01
#define DATA_MSB_REG 0x02
#define DATA_LSB_REG 0x03

void setup() {
  // Start I2C communication
  Wire.begin();
  Serial.begin(9600);

  // Set the maximum light output
  setLightOutput(0xFF);
}

void loop() {
  // Read the output voltage from the Fiber Opt Click module
  float voltage = readOutputVoltage();

  // Print the output voltage
  Serial.print("Output Voltage: ");
  Serial.print(voltage);
  Serial.println(" V");

  // Wait for 1 second
  delay(1000);
}

void setLightOutput(uint8_t lightValue) {
  // Set the light output by writing to the configuration register
  Wire.beginTransmission(FIBER_OPT_CLICK_ADDRESS);
  Wire.write(CONFIG_REG);
  Wire.write(lightValue);
  Wire.endTransmission();
}

float readOutputVoltage() {
  uint8_t msb, lsb;
  uint16_t data;

  // Read the data from the Fiber Opt Click module
  Wire.beginTransmission(FIBER_OPT_CLICK_ADDRESS);
  Wire.write(DATA_MSB_REG);
  Wire.endTransmission(false);

  // Request 2 bytes of data from the Fiber Opt Click module
  Wire.requestFrom(FIBER_OPT_CLICK_ADDRESS, 2);

  // Read the data bytes
  if (Wire.available() == 2) {
    msb = Wire.read();
    lsb = Wire.read();
  }

  // Combine the bytes into a 16-bit value
  data = (msb << 8) | lsb;

  // Calculate the output voltage based on the data value
  float voltage = (data * 5.0) / 1023.0;

  return voltage;
}


The idea is to study the change in the intensity of light at 650 nm in terms of output voltage. However, I dont see any change in the output voltage with or without the optical fiber placed between the photodiode and the LED

You request 2 bytes from your slave device and then immediately expect 2 bytes to be available for reading. This is most likely not true which means your variables are never set, yet you use them anyway.

If you look at other libraries for other i2c devices, you typically wait until 2 bytes are available... Communication takes a bit of time relative to the speed of the processor

while( Wire.available() < 2 ) {
  // wait
  }
msb = Wire.read();
lsb = Wire.read();
...

Looking at the data sheet for the linked FO device, there is no I2C device involved. The TX power is just on or off, no control of power level. On the receiver, you can access either the analog output or the digital output after it has gone through a comparator.

You would need to control the transmit with a GPIO line and connect the analog from the RX to one of the UNO's analog inputs (but I don't think you will get 16-bit resolution).

1 Like

Post a project schematic.
Arduino RX and TX are part of serial.

I think you can use the I2C or SPI interface.

In your code you are using the I2C interface.

Which arduino are you using?

Then you need to connect:
Arduino.......... Module
GND................GND
SCL................. SCL
SDA................ SDA

Ref: "https://download.mikroe.com/documents/add-on-boards/click/fiber-opt-5v/fiber-opt-click-5v-manual-v100.pdf

Thank you, I am using an Arduino Uno, I did connect the SDA of the click board to the SDA of UNO and SCL.....SCL however, in this state the LED was not turning ON at all. And when I connected the Tx......Rx and Rx.....Tx mode, the LED is on.

I am not able to see any change in the output voltage, clearly I can see the light intensity coming down when I was pulling the optical fiber

The I2C interface needs +- 4K7 pullup resistors on the SCL and SDA pins.
I don't know if they are mounted in this module.

PS:
Looking at the photo of the module in more detail, it seems that it doesn't have the SCL and SDA outputs available.
So you'll have to use his RX and TX, and use the softserial.h library to not compromise the arduino's native serial.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.