Introduction: HackerBox 0026: BioSense

BioSense - This month, HackerBox Hackers are exploring operational amplifier circuits for measuring physiological signals of the human heart, brain, and skeletal muscles. This Instructable contains information for working with HackerBox #0026, which you can pick up here while supplies last. Also, if you would like to receive a HackerBox like this right in your mailbox each month, please subscribe at HackerBoxes.com and join the revolution!

Topics and Learning Objectives for HackerBox 0026:

  • Understand theory and applications of op-amp circuits
  • Use instrumentation amplifiers to measure tiny signals
  • Assemble the exclusive HackerBoxes BioSense Board
  • Instrument a human subject for ECG and EEG
  • Record signals associated with human skeletal muscles
  • Design electrically safe human interface circuits
  • Visualize analog signals over USB or via OLED display

HackerBoxes is the monthly subscription box service for DIY electronics and computer technology. We are hobbyists, makers, and experimenters. We are the dreamers of dreams. HACK THE PLANET!

Step 1: HackerBox 0026: Box Contents

  • HackerBoxes #0026 Collectable Reference Card
  • Exclusive HackerBoxes BioSense PCB
  • OpAmp and Component Kit for BioSense PCB
  • Arduino Nano V3: 5V, 16MHz, MicroUSB
  • OLED Module 0.96 inch, 128x64, SSD1306
  • Pulse Sensor Module
  • Snap-Style Leads for Physiological Sensors
  • Adhesive Gel, Snap-Style Electrode Pads
  • OpenEEG Electrode Strap Kit
  • Shrink Tubing - 50 Piece Variety
  • MicroUSB Cable
  • Exclusive WiredMind Decal

Some other things that will be helpful:

  • Soldering iron, solder, and basic soldering tools
  • Computer for running software tools
  • 9V Battery
  • Stranded hook-up wire

Most importantly, you will need a sense of adventure, DIY spirit, and hacker curiosity. Hardcore DIY electronics is not a trivial pursuit, and we are not watering it down for you. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from learning new technology and hopefully getting some projects working. We suggest taking each step slowly, minding the details, and don't be afraid to ask for help.

Note that there is a wealth of information for current, and prospective, members in the HackerBox FAQ.

Step 2: Operational Amplifiers

An operational amplifier (or op-amp) is a high-gain voltage amplifier with a differential input. An op-amp produces an output potential that is typically hundreds of thousands of times larger than the potential difference between its two input terminals. Operational amplifiers had their origins in analog computers, where they were used to perform mathematical operations in many linear, non-linear, and frequency-dependent circuits. Op-amps are among the most widely used electronic devices today, being used in a vast array of consumer, industrial, and scientific devices.

An ideal op-amp is usually considered to have the following characteristics:

  • Infinite open-loop gain G = vout / vin
  • Infinite input impedance Rin (thus, zero input current)
  • Zero input offset voltage
  • Infinite output voltage range
  • Infinite bandwidth with zero phase shift and infinite slew rate
  • Zero output impedance Rout
  • Zero noise
  • Infinite common-mode rejection ratio (CMRR)
  • Infinite power supply rejection ratio.

These ideals can be summarized by the two "golden rules":

  1. In a closed loop the output attempts to do whatever is necessary to make the voltage difference between the inputs zero.
  2. The inputs draw no current.

[Wikipedia]

Additional Op-Amp Resources:

Detailed Video Tutorial from EEVblog

Khan Academy

Electronics Tutorials

Step 3: Instrumentation Amplifiers

An instrumentation amplifier is a type of differential amplifier combined with input buffer amplifiers. This configuration eliminates the need for input impedance matching and thus makes the amplifier particularly suitable for use in measurement and test equipment. Instrumentation amplifiers are used where great accuracy and stability of the circuit are required. Instrumentation amplifiers have very high common-mode rejection ratios making them suitable for measuring small signals in the presence of noise.

Although the instrumentation amplifier is usually shown schematically as being identical to a standard op-amp, the electronic instrumentation amp is almost always internally composed of THREE op-amps. These are arranged so that there is one op-amp to buffer each input (+,−), and one to produce the desired output with adequate impedance matching.

[Wikipedia]

PDF Book: Designer's Guide to Instrumentation Amplifiers

Step 4: HackerBoxes BioSense Board

The HackerBoxes BioSense Board features a collection of operational and instrumentation amplifiers to detect and measure the four physiological signals described below. The tiny electrical signals are processed, amplified and fed to a microcontroller where they can be relayed to a computer via USB, processed, and displayed. For microcontroller operations, the HackerBoxes BioSense Board employs an Arduino Nano module. Note that the next couple of steps focus on readying the Arduino Nano module for use with the BioSense Board.

Pulse Sensor modules feature a light source and a light sensor. When the module is in contact with body tissue, for example a fingertip or earlobe, changes in the reflected light are measured as blood pumps through the tissue.

ECG (Electrocardiography), also called EKG, records electrical activity of the heart over a period of time using electrodes placed on the skin. These electrodes detect the tiny electrical changes on the skin that arise from the heart muscle's electrophysiologic pattern of depolarizing and repolarizing during each heartbeat. ECG is a very commonly performed cardiology test. [Wikipedia]

EEG (Electroencephalography) is an electrophysiological monitoring method to record electrical activity of the brain. Electrodes are placed along the scalp while EEG measures voltage fluctuations resulting from ionic current within the neurons of the brain. [Wikipedia]

EMG (Electromyography) measures electrical activity associated with skeletal muscles. An electromyograph detects the electric potential generated by muscle cells when they are electrically or neurologically activated. [Wikipedia]

Step 5: Arduino Nano Microcontroller Platform

The included Arduino Nano module comes with header pins, but they are not soldered to the module. Leave the pins off for now. Perform these initial tests of the Arduino Nano module separately from the BioSense Board and PRIOR to soldering the header pins the Arduino Nano. All that is needed for the next couple of steps is a microUSB cable and the Nano module just as it comes out of the bag.

The Arduino Nano is a surface-mount, breadboard-friendly, miniaturized Arduino board with integrated USB. It is amazingly full-featured and easy to hack.

Features:

  • Microcontroller: Atmel ATmega328P
  • Voltage: 5V
  • Digital I/O Pins: 14 (6 PWM)
  • Analog Input Pins: 8
  • DC Current per I/O Pin: 40 mA
  • Flash Memory: 32 KB (2KB for bootloader)
  • SRAM: 2 KB
  • EEPROM: 1 KB
  • Clock Speed: 16 MHz
  • Dimensions: 17mm x 43mm

This particular variant of the Arduino Nano is the black Robotdyn design. The interface is by an on-board MicroUSB port that is compatible with the same MicroUSB cables used with many mobile phones and tablets.

Arduino Nanos feature a built-in USB/Serial bridge chip. On this particular variant, the bridge chip is the CH340G. Note that there are various other types of USB/Serial bridge chips used on the various types of Arduino boards. These chips allow you computer's USB port to communicate with the serial interface on the Arduino's processor chip.

A computer's operating system requires a Device Driver to communicate with the USB/Serial chip. The driver allows the IDE to communicate with the Arduino board. The specific device driver that is needed depends upon both the OS version and also the type of USB/Serial chip. For the CH340 USB/Serial chips, there are drivers available for many operating systems (UNIX, Mac OS X, or Windows). The maker of the CH340 supplies those drivers here.

When you first plug the Arduino Nano into a USB port of your computer, the green power light should come on and shortly after the blue LED should start to blink slowly. This happens because the Nano is pre-loaded with the BLINK program, which is running on the brand new Arduino Nano.

Step 6: Arduino Integrated Development Environment (IDE)

If you do not yet have the Arduino IDE installed, you can download it from Arduino.cc

If you would like additional introductory information for working in the Arduino ecosystem, we suggest checking out the instructions for the HackerBoxes Starter Workshop.

Plug the Nano into the MicroUSB cable and the other end of the cable into a USB port on the computer, launch the Arduino IDE software, select the appropriate USB port in the IDE under tools>port (likely a name with "wchusb" in it). Also select "Arduino Nano" in the IDE under tools>board.

Finally, load up a piece of example code:

File->Examples->Basics->Blink

This is actually the code that was preloaded onto the Nano and should be running right now to slowly blink the blue LED. Accordingly, if we load this example code, nothing will change. Instead, let's modify the code a little bit.

Looking closely, you can see that the program turns the LED on, waits 1000 milliseconds (one second), turns the LED off, waits another second, and then does it all again - forever.

Modify the code by changing both of the "delay(1000)" statements to "delay(100)". This modification will cause the LED to blink ten times faster, right?

Let's load the modified code into the Nano by clicking the UPLOAD button (the arrow icon) just above your modified code. Watch below the code for the status info: "compiling" and then "uploading". Eventually, the IDE should indicate "Uploading Complete" and your LED should be blinking faster.

If so, congratulations! You have just hacked your first piece of embedded code.

Once your fast-blink version is loaded and running, why not see if you can you change the code again to cause the LED to blink fast twice and then wait a couple of seconds before repeating? Give it a try! How about some other patterns? Once you succeed at visualizing a desired outcome, coding it, and observing it to work as planned, you have taken an enormous step toward becoming a competent hardware hacker.

Step 7: Arduino Nano Header Pins

Now that your development computer has been configured to load code to the Arduino Nano and the Nano has been tested, disconnect the USB cable from the Nano and get ready to solder.

If you new to soldering, there are a lot of great guides and videos online about soldering. Here is one example. If you feel that you need additional assistance, try to find a local makers group or hacker space in your area. Also, amateur radio clubs are always excellent sources of electronics experience.

Solder the two single row headers (fifteen pins each) to the Arduino Nano module. The six pin ICSP (in-circuit serial programming) connector will not be used in this project, so just leave those pins off.

Once the soldering is complete, check carefully for solder bridges and/or cold solder joints. Finally, hook the Arduino Nano back up to the USB cable and verify that everything still works properly.

Step 8: Components for BioSense PCB Kit

With the microcontroller module ready to go, it is time to assemble the BioSense Board.

Component List:

  • U1:: 7805 Regulator 5V 0.5A TO-252 (datasheet)
  • U2:: MAX1044 Voltage Converter DIP8 (datasheet)
  • U3:: AD623N Instrumentation Amplifier DIP8 (datasheet)
  • U4:: TLC2272344P OpAmp DIP8 DIP8 (datasheet)
  • U5:: INA106 Differential Amplifier DIP8 (datasheet)
  • U6,U7,U8:: TL072 OpAmp DIP8 (datasheet)
  • D1,D2:: 1N4148 Switching Diode Axial Lead
  • S1,S2:: SPDT Slide Switch 2.54mm Pitch
  • S3,S4,S5,S6:: Tactile Momentary Button 6mm X 6mm X 5mm
  • BZ1:: Passive Piezo Buzzer 6.5mm Pitch
  • R1,R2,R6,R12,R16,R17,R18,R19,R20:: 10KOhm Resistor [BRN BLK ORG]
  • R3,R4:: 47KOhm Resistor [YEL VIO ORG]
  • R5:: 33KOhm Resistor [ORG ORG ORG]
  • R7:: 2.2MOhm Resistor [RED RED GRN]
  • R8,R23:: 1KOhm Resistor [BRN BLK RED]
  • R10,R11:: 1MOhm Resistor [BRN BLK GRN]
  • R13,R14,R15:: 150KOhm Resistor [BRN GRN YEL]
  • R21,R22:: 82KOhm Resistor [GRY RED ORG]
  • R9:: 10KOhm Trimmer Potentiometer “103”
  • R24:: 100KOhm Trimmer Potentiometer “104”
  • C1,C6,C11:: 1uF 50V Monolithic Cap 5mm Pitch “105”
  • C2,C3,C4,C5,C7,C8:: 10uF 50V Monolithic Cap 5mm Pitch “106”
  • C9:: 560pF 50V Monolithic Cap 5mm Pitch “561”
  • C10:: 0.01uF 50V Monolithic Cap 5mm Pitch “103”
  • 9V Battery Clips with Wire Leads
  • 1x40pin FEMALE BREAK-AWAY HEADER 2.54mm Pitch
  • Seven DIP8 Sockets
  • Two 3.5mm Audio-Style, PCB-Mount Sockets

Step 9: Assemble the BioSense PCB

RESISTORS: There are eight different values of resistors. They are not interchangeable and must be carefully placed exactly where they belong. Start by identifying the values of each type of resistor using the color codes shown in the component list (and/or an ohmeter). Write the value on the paper tape attached the the resistors. This makes it a lot harder to end up with resistors in the wrong place. Resistors are not polarized and can be inserted in either direction. Once soldered into place, closely trim the leads form the rear of the board.

CAPACITORS: There are four different values of capacitors. They are not interchangeable and must be carefully placed exactly where they belong. Start by identifying the values of each type of capacitor using the number markings shown in the component list. Ceramic capacitors are not polarized and can be inserted in either direction. Once soldered into place, closely trim the leads form the rear of the board.

POWER SUPPLY: The two semiconductor components that make up the power supply are U1 and U2. Solder these next. When soldering U1, note that the flat flange is the device ground pin and heat sink. It must be soldered completely to the PCB. The kit includes DIP8 sockets. However, for the voltage converter U2, we strongly recommend carefully soldering the IC directly to the board without a socket.

Solder on the two slide switches and the 9V battery clip leads. Note that if your battery clip came with a connector plug on the leads, you can just snip the connector off.

At this time, you can plug on a 9V battery, flip the power switch on and use a volt meter to verify that your power supply is creating a -9V rail and a +5V rail from the supplied +9V. We now have three voltage supplies and a ground all from one 9V battery. REMOVE THE BATTERY TO CONTINUE ASSEMBLY.

DIODES: The two diodes D1 and D2 are small, axial-leaded, glassy-orange components. They are polarized and should be oriented so that the black line on the diode package lines up with the thick line on the PCB silkscreen.

HEADER SOCKETS: Separate the 40 pin header into three sections of 3, 15, and 15 positions each. To cut the headers to length, use small wire cutters to snip through the position ONE PAST where you want the socket strip to end. The pin/hole that you cut through is sacrificed. The three pin header is for the pulse sensor at the top of the board with pins labeled "GND 5V SIG". The two fifteen pin headers are for the Arduino Nano. Remember that the six pin ICSP (in-circuit serial programming) connector of the Nano is not used here and does not need a header. We also do not suggest connectorizing the OLED display with a header. Solder the headers into place and leave them empty for now.

DIP SOCKETS: The six amplifier chips U3-U8 are all in DIP8 packages. Solder a DIP8 chip socket into each of those six positions being sure to orient the notch in the socket to align with the notch on the PCB silkscreen. Solder the sockets without the chip inserted into them. Leave them empty for now.

REMAINING COMPONENTS: Finally solder the four push buttons, the two trimpots (note that they are two different values), the buzzer (note that it is polarized), the two 3.5mm audio-style jacks, and lastly the OLED display.

SOCKETED COMPONENTS: Once all of the soldering is complete, the six amplifier chips may be inserted (minding the orientation of the notch). Also, the Arduino Nano may be inserted with the USB connector at the edge of the BioSense Board.

Step 10: Electrical Safety and Power Supply Switches

In the schematic diagram for the HackerBoxes BioSense Board, note that there is a HUMAN INTERFACE (or ANALOG) section and also a DIGITAL section. The only trances that cross between these two sections are the three analog input lines to the Arduino Nano and the +9V battery supply which can be opened up using the USB/BAT switch S2.

Out of an abundance of caution, it is common practice to avoid having any circuit connected to a human body powered by wall power (line power, mains power, depending upon where you live). Accordingly, the HUMAN INTERFACE portion of the board is only powered by a 9V battery. However unlikely it may be that the computer suddenly puts 120V onto the connected USB cord, this is a little extra insurance policy. An added benefit to this design is that we can power the entire board from the 9V battery if we do not need a computer connected.

ON/OFF SWITCH (S1) serves to disconnect the 9V battery from the circuit entirely. Use S1 to turn the analog portion of the board completely off when not in use.

USB/BAT SWITCH (S2) serves to connect the 9V battery to the digital supply of the Nano and OLED. Leave S2 in the USB position when the board is connected to a computer via the USB cable and the digital supply will be provided by the computer. When the Nano and OLED are to be powered by the 9V battery, just switch S2 to the BAT position.

NOTE ON SUPPLY SWITCHES: If S1 is ON, S2 is in USB, and there is no USB power provided, the Nano will try to power itself through the analog input pins. While not a human safety issue, this is an undesirable condition for the delicate semiconductors and it should not be prolonged.

Step 11: OLED Display Library

As an initial test of the OLED display, install the SSD1306 OLED display driver found here into the Arduino IDE.

Test the OLED display by loading up the ssd1306/snowflakes example and programming it into the BioSense Board.

Be sure this works before moving ahead.

Step 12: BioSense Demo Firmware

Shall we play a game, Professor Falken?

There is also a cool Arkanoid game in the SSD1306 examples. For it to work with the BioSense board however, the code that initializes and reads the buttons must be modified. We have taken the liberty to make those changes in the "biosense.ino" file attached here.

Duplicate the arkanoid folder from the SSD1306 examples to a new folder that you have named biosense. Delete the arkanoid.ino file from that folder and drop in the "biosense.ino" file. Now compile and upload biosense to the nano. Hitting the rightmost button (button 4) will launch the game. The paddle is controlled by button 1 to the left and button 4 to the right. Nice shot there, BrickOut.

Hit the reset button on the Arduino Nano to go back to the main menu.

Step 13: Pulse Sensor Module

A Pulse Sensor Module may interface to the BioSense Board using the three pin header at the top of the Board.

The Pulse Sensor Module uses an LED light source and an APDS-9008 ambient light photo sensor (datasheet) to detect LED light reflected through a fingertip or earlobe. A signal from the ambient light sensor is amplified and filtered using an MCP6001 op-amp. The signal may then be read by the microcontroller.

Pressing Button 3 from the main menu of the biosense.ino sketch will relay samples of the pulse sensor output signal over the USB interface. Under the TOOLS menu of the Arduino IDE, select the "Serial Plotter" and make sure that the baud rate is set to 115200. Gently place your fingertip over the light on the pulse sensor.

Additional details and projects associated with the Pulse Sensor Module may be found here.

Step 14: ​Electromyograph (EMG)

Plug the electrode cable into the lower 3.5mm jack labeled EMG and position the electrodes as shown in the diagram.

Pressing Button 1 from the main menu of the biosense.ino sketch will relay samples of the EMG output signal over the USB interface. Under the TOOLS menu of the Arduino IDE, select the "Serial Plotter" and make sure that the baud rate is set to 115200.

You can test out the EMG on any other muscle groups - even the eyebrow muscles in your forehead.

The EMG circuit of the BioSense Board was inspired by this Instructable from Advancer Technologies, which you should definitely check out for some additional projects, ideas, and videos.

Step 15: Electrocardiograph (ECG)

Plug the electrode cable into the upper 3.5mm jack labeled ECG/EEG and position the electrodes as shown in the diagram. There are two basic options for ECG electrode placement. The first is on the inside of the wrists with the reference (red lead) on the back of one hand. This first option is easier and more convenience but is often a little noisier. The second option is across the chest with the reference on the right abdomen or upper leg.

Pressing Button 2 from the main menu of the biosense.ino sketch will relay samples of the ECG output signal over the USB interface. Under the TOOLS menu of the Arduino IDE, select the "Serial Plotter" and make sure that the baud rate is set to 115200.

The ECG/EEG circuit of the BioSense Board was inspired by the Heart and Brain SpikerShield from Backyard Brains. Check out their site for some additional projects, ideas, and this cool ECG video.

Step 16: Electroencephalograph (EEG)

Plug the electrode cable into the upper 3.5mm jack labeled ECG/EEG and position the electrodes as shown in the diagram. There are many options for EEG electrode placement with two basic options shown here.

The first is on the forehead with the reference (red lead) on the earlobe or mastoid process. This first option can simply use the same snap-style leads and gel electrodes used for ECG.

The second option at the back of the head. If you happen to be bald, the gel electrodes will also work here. Otherwise, forming electrodes that can "poke through" hair is a good idea. A lock-washer style solder lug is a good option. Use needlenose pliers on the small tabs (six in this case) inside the washer to bend then all to protrude in the same direction. Placement under an elastic headband will gently force these protrusions through hair and into contact with the scalp below. As necessary, conductive gel can be used to improve the connection. Simply mix table salt with a thick liquid such as petroleum jelly or a slurry of water and starch or flour. Salty water alone will also work but will need to be contained within a small sponge or cotton ball.

Pressing Button 2 from the main menu of the biosense.ino sketch will relay samples of the EEG output signal over the USB interface. Under the TOOLS menu of the Arduino IDE, select the "Serial Plotter" and make sure that the baud rate is set to 115200.

Additional EEG projects and resources:

This Instructable uses a similar design as the BioSense EEG and also demonstrates some additional processing and even how to play EEG Pong!

Backyard Brains also has a nice video for EEG measurements.

BriainBay

OpenEEG

OpenViBe

EEG signals can measure stroboscopic brainwave effects (e.g. using Mindroid).

Step 17: Challenge Zone

Can you display the analog signal traces on the OLED in addition to the Serial Plotter?

As a starting point, check out this project from XTronical.

It may also be useful to have a look at the Tiny Scope project.

How about adding text indicators for signal rates or other interesting parameters?

Step 18: BioBox Monthly Subscription Box

Applied Science Ventures, the parent company of HackerBoxes, is involved in an exciting new subscription box concept. BioBox will inspire and educate with projects in the life sciences, bio hacking, health, and human performance. Keep an optical sensor out for news and charter member discounts by following the BioBox Facebook Page.

Step 19: HACK THE PLANET

If you have enjoyed this Instrucable and would like to have a box of electronics and computer tech projects like this delivered right to your mailbox each month, please join the HackerBox revolution by SUBSCRIBING HERE.

Reach out and share your success in the comments below or on the HackerBoxes Facebook Page. Certainly let us know if you have any questions or need some help with anything. Thank you for being part of HackerBoxes. Please keep your suggestions and feedback coming. HackerBoxes are YOUR boxes. Let's make something great!