Darkness And Light Detector Using Eog Signals

About the project

Develop an innovative system that determines the light environment (dark or light) based on EOG signals from the eyes.

Project info

Difficulty: Moderate

Platforms: Raspberry PiSTMicroelectronics

Estimated time: 1 hour

License: MIT license (MIT)

Items used in this project

Hardware components

Hexabitz STLINK-V3MODS Programmer (H40Rx) Hexabitz STLINK-V3MODS Programmer (H40Rx) x 1
Hexabitz Raspberry Pi Interface Module (HF1R0x) Hexabitz Raspberry Pi Interface Module (HF1R0x) x 1
Raspberry Pi 4 Model B Raspberry Pi 4 Model B x 1
Hexabitz Single-Lead, EXG Monitor (H2BR0x) Hexabitz Single-Lead, EXG Monitor (H2BR0x) x 1
Hexabitz BitzClamp Hexabitz BitzClamp x 1
Hexabitz 4-Pin USB-Serial Prototype Cable Hexabitz 4-Pin USB-Serial Prototype Cable x 1

Software apps and online services

Hexabitz 4-Port USB 2.0 Hub with Individual Power Switches Hexabitz 4-Port USB 2.0 Hub with Individual Power Switches
Hexabitz 5V / 8W Portable USB Soldering Iron Hexabitz 5V / 8W Portable USB Soldering Iron
Solder Wire, Lead Free Solder Wire, Lead Free
STMicroelectronics STM32CUBEPROG STMicroelectronics STM32CUBEPROG

Story

👁️ Project Idea:

Develop an innovative system that determines the light environment (dark or light) based on EOG (electrooculography) signals from the eyes. This project aims to use fluctuations in the electrical signals from the eyes to determine the ambient light level.

👁️ Electrooculography (EOG):

Electrooculography (EOG) is a technique for measuring the corneo-retinal standing potential that exists between the front and the back of the human eye. The resulting signal is called EOG.

To measure eye movement, pairs of electrodes are typically placed either above and below the eye or to the left and right of the eye. If the eye moves from center position toward one of the two electrodes, this electrode "sees" the positive side of the retina and the opposite electrode "sees" the negative side of the retina. Consequently, a potential difference occurs between the electrodes. Assuming that the resting potential is constant, the recorded potential is a measure of the eye's position.

In 1951 Elwin Marg described and named electrooculogram for a technique of measuring the resting potential of the retina in the human eye.

👁️ Key Components:
  • EOG Module: To measure the electrical activity of the eyes.
  • Analysis Software: Using Python to analyze EOG signals and determine the ambient light level.
  • User Interface: An application or control panel to display results.

🌟 Single-Lead, EXG Monitor (H2BR0x):

Hexabitz Single-Lead, EXG Monitor Module (H2BR0) is one of a kind module that can record publication-grade biopotential signals from your body be it from the heart (ECG), brain (EEG), eyes (EOG), and muscles (EMG).

What makes it different?

  • Record publication-quality biopotential signals like ECG, EMG, EOG, or EEG.
  • Small size allows easy integration into mobile and space-constrained projects.
  • Notch filter (second order) to remove 50 Hz AC mains.
  • H2BR0 is based on STM32G0 MCU.
  • Program advanced C code with our easy-to-use APIs.
  • You can connect to external hardware or combine with other Hexabitz modules!
  • The module is equipped with an open source MATLAB interface.

Hexabitz Single-Lead, EXG Monitor Module (H2BR0)

Hexabitz Single-Lead, EXG Monitor Module (H2BR0)

👁️ Project Steps:

Data Collection:

Use the EOG module to collect eye signals in different lighting conditions.Record data for several samples in both dark and light environments.

The ExG module main code:

This code is designed for interfaces with an EOG sensor, reading EOG signals and transmitting them to a Raspberry Pi via serial communication ( It initializes the sensor, reads samples, and sends them to port P4) 😊

  • The `UserTask` function is the main user-defined task.
  • It initializes the EOG (Electromyography) sensor using `EXG_Init(EOG)`.
  • Inside the infinite loop, transmit a sample via the designated port or route it to another module and scale the output accordingly.

- In case the topology file remains inactive, the module number defaults to 0

SampletoPort(0,P4,EOG);
  • Connect the ExG module to HF1R0 module.

1 / 2

  • Make sure to connect your Hexabitz module at the wright spot or left spot then put the HF1R0 Jumper JP1 and JP2 at right position.
  • Be sure to download the firmware on the module before soldering.

Data Analysis:

Develop algorithms to analyze EOG signals to identify differences between dark and light environments.

User Interaction:

This Python script is designed to create a graphical user interface (GUI) that detects whether the environment is light or dark based on eye signals read from a Hexabitz module via a serial connection. The script uses the tkinter library for the GUI and numpy for numerical operations.

Key Components of the Code:

1. Imports:

• serial: For handling serial communication with the Hexabitz module.

• struct: For converting byte data into Python data types.

• numpy: For handling arrays and performing mathematical operations.

• tkinter: For creating the GUI.

• font: For customizing font styles in the GUI.

2. Serial Connection Setup:

ser = serial.Serial(port='/dev/ttyS0', baudrate=921600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=0)

This line initializes a serial connection to the Hexabitz module. The parameters specify the port, baud rate, and other settings for communication.

3. EyeSignalProcessor Class:

• This class encapsulates the functionality for reading eye signals and determining the light environment.

• Initialization:

def __init__(self, samples_count=50, threshold=1.2):

This method initializes the processor with a specified number of samples to read and a threshold to determine light conditions.

• Reading Eye Signals:

def read_eye_signals(self):

This method reads eye signals from the serial port. It attempts to read 4 bytes at a time and unpacks them into a float, storing the values in an array.

• Determining Light Environment:

def determine_light_environment(self):

This method calculates the average of the read signals and compares it to the threshold to determine if the environment is "light" or "dark".

4. Check Environment Function:

def check_environment(processor, label):

This function calls the read_eye_signals and determine_light_environment methods of the EyeSignalProcessor instance. It updates the label in the GUI based on whether it determines the environment to be light or dark.

5. Close Application Function:

def close_app(root):

This function closes the tkinter application when called.

6. Main Function:

def main():

This function sets up the tkinter GUI components, including buttons for checking the light environment and exiting the application. It also initializes an instance of EyeSignalProcessor.

7. Running the Application:

if __name__ == "__main__":
main()

This conditional statement checks if the script is being run directly (not imported as a module) and calls the main() function to start the application.

👁️ Project Testing:

The system was rigorously tested by simulating both dark and light conditions through the act of closing the eyes (representing darkness🌙) and opening the eyes (representing light or daytime☀️). By analyzing the EOG signals generated during these actions, the system successfully determined the light environment with high accuracy. This testing method proved effective in validating the functionality of the system and ensuring its reliability in real-world scenarios. Further testing in different environmental settings could provide additional insights and improvements.

1 / 3

👁️ Future Developments and Applications

Developing an innovative system that determines the light environment (dark or light) based on EOG signals from the eyes opens up several exciting possibilities. Future developments could include refining the sensitivity of the system to detect subtle changes in lighting conditions, making it applicable in more diverse environments. Additionally, integrating this technology with smart home systems could automate lighting based on the user's eye movements, enhancing convenience and energy efficiency.

The application of this technology extends beyond just light detection. It could be adapted for use in assistive devices for visually impaired individuals, providing feedback on ambient lighting conditions. Moreover, it could find applications in medical diagnostics, where monitoring eye movements and responses to light could help in the diagnosis of certain neurological conditions.

Let’s celebrate the new year, come join the ride,

With the EXG module, let’s surge with pride!

Makers and engineers, united we stand,

Crafting the future, with our own hands!

So, here’s to all of you, dreamers and doers,

May the new year bring joy, to all the creators!

Now let’s get to work, with a smile on our face ^_^

In the world of Hexabitz, we’ve found our place!

Schematics, diagrams and documents

H2BR0x-Hardware

Code

H2BR0x-Firmware

GUI code

H2BR0x-main code

Credits

Photo of Aula_Jazmati

Aula_Jazmati

https://www.hackster.io/aula-jazmati

   

Leave your feedback...