Have you ever thought of controlling things with just your thoughts? Well, it is now possible!
The idea for this IoT project came while working on the BioSecure project wherein a unique pattern was created using a brain controlled EEG and EMG signals to act as a unique password. This led to the development of a machine learning (ML) model that understood brain signals and thereby created unique patterns using our thoughts. For example, when thinking in a particular language, the ML model is able to read those thoughts and translate them.
To achieve this, the brain data corresponding to the level of mental attention needs to be obtained using an EEG sensor. This level is then given a threshold value. When the attention level goes above this threshold value, lights or other IoT connected appliances (that were thought of) switch on/off.
This project does not end here. The journey of discovery will continue, which will later evolve into a brain-computer interface (BCI) and might become the world’s first thoughts translator that uses an ML model.
Sounds highly interesting and quite futuristic as well? If so, let us start the project by shopping for the components mentioned under Bill of Material.
There are various EEG sensors such as OpenBCI and NeuroSky MindWave available in the market. For this project, the NeuroSky MindWave Mobile 2 EEG sensor is being used.
Install Bluez driver into the Raspberry Pi. But if you have the latest version of the Raspbian OS, there is no need to do so as the driver and relevant software are pre-installed.
Open the Bluetooth devices in Settings and pair the EEG sensor via Bluetooth with the Raspberry Pi. On successful connection with serial ports, a message with the serial port name will be displayed. Note it down.
Retrieve the EEG sensor data over Bluetooth using Python. (Different sensors have different Python modules and libraries that read EEG sensor data.) Since we have used MidWave 2 here, install its Python module named NeuroPy. Open the terminal and install this module using pip using the command:
sudo pip3 install NeuroPy (for Python 3)
Since the library faces some problems with Python 3, Python 2 has been used instead with the help of command:
sudo pip install NeroPy (for python 2)
Because the EEG sensor is already paired with the Raspberry Pi, you can read the connected EEG sensor data. Now wear the EEG sensor on your head. To test the EEG sensor data, clone the library and then run the test example code using following sudo git clone:
The library will help you obtain the following EEG sensor data:
- Low theta waves
- High theta waves
- Low beta waves
- High beta waves
- High gamma waves
- Low gamma waves
To control the connected IoT devices such as electric lights or fans, use the Attention, Meditation, and Eyeblink data.
Include the NeuroPy and gpiozero Python modules in the code. Then set the COM port name for the EEG sensor. Next, set the pin number for controlling the electric lights, fans, etc.
Now create a function that checks the brain signals/waves like alpha waves, beta waves, gamma waves and so on, so that your attention value can be determined. If it exceeds the pre-set threshold value of 80 while thinking of switching on/off the desired electric device (in this case electric lights), it will occur automatically—like magic.
Connection and testing
After making the appropriate connections, run the code in an IDE or terminal and concentrate on switching a light bulb on or off with your thoughts. When your thoughts reach or exceed the set threshold value, the light bulb will glow instantly.
Congrats! You have just controlled an electric device using your thoughts.
Ashwini Kumar Sinha is a technology enthusiast at EFY
The prototype circuit was published on 9 September 2021 and was verified and reprinted in EFY magazine’s November 2021 issue.