{"id":19326606,"url":"https://github.com/thomasgladwin/malak","last_synced_at":"2026-04-29T16:01:25.972Z","repository":{"id":149526981,"uuid":"99688224","full_name":"thomasgladwin/malak","owner":"thomasgladwin","description":"Psychophysiology measurement via Arduino","archived":false,"fork":false,"pushed_at":"2017-08-21T22:34:13.000Z","size":511,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-06T07:12:06.353Z","etag":null,"topics":["arduino","biofeedback","elegoo","hardware","heart","light","microcontroller","ppg","processing","psychology","psychophysiology","python","rate","sensor"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomasgladwin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-08T12:04:49.000Z","updated_at":"2023-01-28T09:53:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"049e1ee6-b073-4771-9351-296126d93d49","html_url":"https://github.com/thomasgladwin/malak","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasgladwin%2Fmalak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasgladwin%2Fmalak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasgladwin%2Fmalak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasgladwin%2Fmalak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomasgladwin","download_url":"https://codeload.github.com/thomasgladwin/malak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240427460,"owners_count":19799498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","biofeedback","elegoo","hardware","heart","light","microcontroller","ppg","processing","psychology","psychophysiology","python","rate","sensor"],"created_at":"2024-11-10T02:14:17.946Z","updated_at":"2026-04-29T16:01:20.947Z","avatar_url":"https://github.com/thomasgladwin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# malak\nPsychophysiology measurement via Arduino\n\n# Hardware\nMicrocontroller: Elegoo Basic Starter Kit (really nice Uno R3 Arduino clone with jumper wires, breadboard, light\nsensor, etc),\nhttps://www.amazon.co.uk/gp/product/B01DGD2GAO/ref=od_aui_detailpages01?ie=UTF8\u0026psc=1. Around 14\npounds.\n\nPulse Sensor for heart rate: Pulse Sensor’s pulse sensor,\nhttps://www.amazon.co.uk/gp/product/B01CPP4QM0/ref=od_aui_detailpages01?ie=UTF8\u0026psc=1. Around 20\npounds. This sensor provides a photoplethysmogram (PPG): A voltage signal that reflects the changes in\nblood oxygen levels that occur as patterns between heart beats. The sensor exploits changes in light absorption measured at the skin on the finger, which occur due to subtle changes in the volume of blood vessels during the cardiac cycle.\n\nComputer to present tasks and save data.\n\n# Basic set-up\nElegoo has a tutorial for the microcontroller on elegoo.com. This goes through installing the Arduino\nprogramming IDE for the Processing language (this doesn't appear to require admin rights). Working on Windows 10, I plugged the board into a USB port using the USB cable, before installing the software. When I first opened the IDE, I could select the\nPort with the Arduino connected via Tools -\u003e Port, and everything worked without any problems.\nLesson 1 of the Elegoo tutorial perhaps goes into technical details a little much for first use, which you\ncan skip; but it’s a good resource. Lesson 2 is the classic “blink” function: Do that for a first introduction\nand test everything’s working.\n\nThen do a pulse sensor tutorial: www.pulsesensor.com has a Getting Started project. Just follow the\nvideo to get the very easy connections done and putting the velcro and vinyl stickers on. The video\nexplains how to get the necessary Processing code (the .ino file) from PulseSensor’s github repository.\nOpen the code and upload to the board. Using Tools -\u003e Serial Plotter shows the pulse signal!\n\n# Making it usable for experiments\n\nSo the data are already there! We just need to save them, and we might need to\nsynchronize the PPG to task events.\n\nIn preparation for this, we’re going to use the breadboard for connections instead of plugging into the microcontroller\ndirectly. Use jumper cables to power the breadboard by connecting the microcontroller’s ground and 5V\npins to the – and + columns (on the side of the board; pick either side), respectively. Pick a row, or \n“line”, on the breadboard and connect any pin to the A0 pin on the microcontroller. Then attach the pins\nof the pulse sensor to the breadboard: The 5V and ground to any line on the side-lines, and the purple\nwire to a pin on the same line, and the same side of the line, as the pin connected to A0. (The lines are\n“cut” down the middle so without, e.g., a resistor or button, pins on the left aren’t connected to pins on\nthe right.) Check whether the PPG is still coming through via Serial Plotter. Also have a look at the raw\nnumbers coming in with Serial Monitor.\n\n# Using a light sensor to synchronize task events and data\n\nThe Elegoo basic kit includes a light sensor. Its wiring is given in its chapter in the Elegoo tutorial. Use A1 instead of A0 (since A0 is used for the pulse sensor). Make sure you use a suitable resistor, otherwise the signal values can be attenuated or become zero.\n\nThe file malak.ino in this repository contains the Processing code to measure the PPG and light sensor data. Upload this code to the microcontroller (make sure you're using the right type via Tools-\u003eBoard, if you're using a Nano for instance) and open the Serial Monitor to see how sensitive the light sensor is. If we hold it up to some point of a black screen, it’s very clear if anything flashes white at that position. We can use that when programming tasks to synchronize the signal. For instance: The task lights up a rectangle or border at the start of every block and saves the exact time of the flash. If we save the light sensor signal together with the PPG signal, we can use the response to those flashes to synchronize the data. One nice thing is that this means we can use JavaScript tasks which wouldn’t allow triggers via a USB connection. Hence, we can use the same tasks for online and lab experiments. For an example online experiment with Javascript tasks, see https://github.com/thomasgladwin/onlineABM.\n\nWe do need to get the light sensor into position on the screen (at the time of synchronization at least) and program the task to send some suitable light signal via the screen. One possibility is to light up the border of the canvas at the\nIntroduction screen of the task, and save the time point when the border is removed and the edges turn\nblack. That would allow a procedure in which the task can start up, then wait at the Introduction screen\nuntil the sensor is positioned, and then the participant can continue with the task.\n\n# Using a Python program to save data\n\nInstall Python 3.x. If you use the Anaconda distribution, you don't need admin rights. Also install the libraries needed by malak.py and malak_sample.py. E.g., the pyserial library: From command line (search “cmd” or use Powershell or the Anaconda command line; make sure python.exe is in the path): python -m pip install pyserial. At the time of writing, the other libary not available by default is pygame, which you can install the same way.\n\nNow you can use the Python program malak.py from this repository: python malak.py. You may need to go into malak_sample.py to adjust the COM port to match your hardware.\n\nIt will ask for a base filename to save data to (base.log), open a window, and then keep on reading in what the microcontroller is sending and saving it to file. You should see a visual representation of the signal values coming in, as well as the peak detection for the PPG. There's also a visual and auditory representation of the heart rate over the last few seconds, which could be useful for biofeedback purposes. Measurement stops when you close the window.\n\nmalak.py calls malak_sample.py, but you can also run malak_sample.py directly: This only reads and prints the values coming in.\n\nSo the procedure would be something like:\n\n- Start the task, which must indicate where to hold the light sensor and wait for a response before continuing.\n- Attach the PPG to the participant's finger.\n- Start the measurement program.\n- Hold the light sensor to the correct area of the screen.\n- Press a button that changes the screen brightness at that location and then continues to the next instruction screen of the task.\n- Put away the light sensor.\n- The participant performs the task.\n- After the task ends, close the malak window to stop measurement.\n\n# Hardware design\n\nThe document Hardware_design.docx currently shows a probably useless photo of the wiring of a prototype. To be updated if I ever get round to making it nicer.\n\n# Citation\n\nPlease cite as Thomas Edward Gladwin. (2017, August 10). thomasgladwin/malak: malak version 1.2. Zenodo. http://doi.org/10.5281/zenodo.841125. \n\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.841125.svg)](https://doi.org/10.5281/zenodo.841125)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasgladwin%2Fmalak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomasgladwin%2Fmalak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasgladwin%2Fmalak/lists"}