Controlling the System

Last year, the group constructed the electronics system using Arduino UNO, which was used to control the solenoid valves. This year our plan was to upgrade the electronics by adding solenoid valves for a third order, a water delivery system and lick tracking. In this page we will explain what an Arduino is, how it works and how we built the set-up for this specific project.



How Arduinos work

Arduino is an open-source electronics platform, which is essentially an entire computer on a chip. It works in a very simple way, using three main things: inputs, programming and outputs. Inputs are sensors and switches connected to the controller. Their role is to give the information to the chip. The programming part takes these inputs and makes decisions and can be done in the Arduino IDE, VS Code and Python. Outputs represent the signal that Arduino sends to connected components. Sensors, as inputs, send information to the chip. We programmed our board to send a signal as the output so that a command is executed.

By way of a simple explanation, we can explore the fundamental workings of Arduino.

In this example, our objective is to create a setup that automatically turns off a light bulb when the surrounding temperature reaches a certain threshold, say 30°C. For this experiment, we will need an Arduino board, a breadboard, cables, a resistor, a temperature sensor, and an LED diode. Let's connect all the components as illustrated in the diagram below (for each experiment, connections will differ and for different experiments you can look connections at this web page).

4
Graphical abstract outlining how the Arduino set-up is connected.

Once the hardware setup is in place, we can proceed to write the code. In our program, the temperature sensor will continuously measure the temperature and transmit the readings to the computer, marking this as our input. Simultaneously, the LED diode will remain lit until the Arduino receives a specific command. When the temperature surpasses 30°C, the Arduino will execute this command, switching off the LED diode—this constitutes our output.

5
Graphical abstract outlining the working principal of an Arduino.

In any Arduino project, it's important to acknowledge that programming and setup may vary significantly. However, at its core, the essence of Arduino remains constant: the ability to gather information and deliver outputs.

As illustrated in the accompanying diagram, we can observe the structure of the Arduino UNO board and its key components.

Notes 3 Preview Rev 1
Key components of an Arduino.

This site and videos will help you better understand the basics of arduino.


2023 Arduino design

Comprising an Arduino board, soldering board, and relays, this setup regulates fluid flow efficiently. They initially tested one solenoid valve and the system's functionality was validated, ensuring proper connectivity between the valve, relay, and power source. The relay serves as a switch, controlled by the Arduino's signal, enabling activation or deactivation of the valve.

Graphical abstract of connection between the valve, relay, power source and Arduino.

The connection scheme involves specific pins on the Arduino, including signal, power supply (VCC), and Ground. Additionally, relay terminals like NC (Normally Closed), C (Common), and NO (Normally Open) regulate current flow to the valve.

Connections for two solenoid valves between Arduino, the relay, and the valve; Electronic setup in final design.

Expanding the system to accommodate multiple valves followed the same connection pattern, maintaining uniformity. The inclusion of a visual interface allows users to control operation modes and parameters, with a feedback section for real-time analysis. In essence, this Arduino-based system offers precise fluid control, scalability, and user-friendly interaction, making it valuable across various applications.


2024 Arduino design

To redesign their set-up, we first had to closely study the assembly of their previous system to understand the components, their functions, and the connections between the Arduino and the olfactometer.

IMG 20240221 WA0050

We concluded that we needed to adjust the Arduino set-up by adding additional valves as explained in the Olfactometer tab. To do this, we added 5 more valves compared to the previous year, and subsequently connected each of these to a relay. To ensure the system worked, we adjusted the code to account for the additional valves and odor.

Sale (4)

This year, we recognised the importance of a noise-free environment for mouse conditioning, so we replaced the noisy relay system with silent transistors. These transistors offer the same functionality as relays but without any disruptive sounds. The connection between the transistors, Arduino, and solenoid valves is depicted in the image above.

Additionally, we effectively tackled the overheating issue of solenoid valves from the previous year by adjusting the power supply voltage. This successful intervention ensures smoother operation and enhances the overall reliability of our system.


Graphical User Interface

The Olfactometer GitHub repository is accessible via the following link: GitHub Link.

GUI
This is the Graphical User Interface for controlling the Olfactometer System over the Computer.



We have divided the main window using smaller frames. To enhance the visual separation between the different control frames, we used various background colors.

Experimental Control

In this frame, the user can set the Parameters of the experiment. These include the names of the three odors, the name of the mouse and specifying the name of the protocol used for the experiment. There is also the option to import a previous protocol by clicking on the “Previous Setup” button. The “Save” button allows saving these Parameters in an excel file to a location on the server the user chooses. Moreover, there is the “Status:” function providing information about the experiment and the “Progress” bar, that will turn from grey to green depending on the progress of the experimental run.


Manual Control

The manual control frame allows for the user to choose the mode in which the olfactometer should run (“Resting”, “Purge”, “Odor 1”, “Odor 2”, “Odor 3”). It also lets the user choose the duration of the selected mode. If the user wishes to run a new set of experimental runs, the “Reset history”-button can be pressed to delete the history. While the “Run”-button will start the experiment, the “Purge and Stop”-button will immediately stop the odor delivery, followed by a 10 second purging mode.


Excel Control

This frame contains an “Add file”-button which, when clicked, will let the user choose an excel file with an experimental setup from the local repository. The “Run file”-button will immediately start running the experiment from the excel file.


Valve Setup

In this section, the user finds an overview of all valves in the olfactometer. Open valves are represented by green circles, while red circles represent closed valves. depending on themode selected on the “Manual Control”-frame, the valves will change their color according to the chosen setup to help the user understand the olfactometer configuration for the chosen mode.


Water Control

In this frame, the user is asked to choose a mode (“Odor 1”, “Odor 2”, “Odor 3”, “None”) to be coupled to water release. When the chosen odor is delivered, the water valve will be opened and the mouse will have access to water during the mode.


Plot Experiment

While the experiment is running, the modes will be plotted against their duration in this frame. That way, the user can visually follow the progress of the experiment.


Miniscope Feedback and Camera Feedback

These frames provide feedback over whether or not a miniscope and camera have been detected by the system.

Cracking the Code: What's Behind this GUI?

Delving into the intricacies of our implementation process, we owe credit to the preceding team whose foundational work provided a robust framework. Leveraging their prior efforts, we retrieved the requisite codebase from our GitHub repository, accessible via the following link: GitHub Link.


app.py

Serving as the cornerstone, this Python script orchestrates the creation of a GUI application for olfactometer control using the tkinter library. It embodies the MVC paradigm, wherein the Olfactometer class governs device functionality, the View class oversees GUI presentation, and the Controller class acts as the intermediary. The script initialises and interconnects these components, subsequently initiating the event loop to sustain GUI functionality.


controller.py

This module encapsulates a Controller class tasked with managing interactions between the GUI (View) and the underlying device model (Olfactometer). It encompasses methods facilitating experimental mode activation, experiment loading from files, experiment execution, status retrieval, progress monitoring, and post-experiment cleanup.


experiment.py

Implemented in Python and leveraging tkinter and matplotlib for data visualization, this script generates bar charts depicting programming language popularity. Additionally, it updates a CSV file with simulated data reflecting pin states over time.


model.py

Central to the system, this Python file defines the Olfactometer class, facilitating communication with Arduino boards for component control. It initialises pins, configures experiment parameters, and furnishes methods for experiment execution, mode configuration, and pin status retrieval.


modes.py

This module introduces an enumeration, 'Modes', employing the enum module to delineate various system operation modes. Notably, it defines constants, 'CLOSE' and 'OPEN', signifying pin states. Each mode comprises a tuple specifying valve configurations, encompassing Resting, Purging, and distinct Odor modes.


view.py

Herein lies the graphical user interface (GUI) responsible for administering olfactometer experiments, as detailed above.


water.py

This Python script features a 'Bottle' class engineered to interface with Arduino boards, facilitating water dispensation control through the pyfirmata library. Functionality includes mode and duration configuration, pin initialization, and status retrieval. Additionally, 'open_water_valve()' is included, likely serving as a conduit for interaction with the graphical user interface or other system components.


water_modes.py

Finally, this script introduces an enumeration class, 'Water', employing the enum module to delineate states pertinent to water dispensation. It encompasses 'NO_WATER' and 'WATER' states, corresponding to 'CLOSE' (with a value of 1) and 'OPEN' (with a value of 0), respectively, likely serving as pivotal indicators for governing water flow within the system.

Ready, set, go! How to start the program:

To operate the olfactometer through the graphical user interface (GUI), follow these steps:

Import our GitHub repository to your local GitHub program on your computer by accessing the repository via the provided link.


Connect the olfactometer's power supply and then plug the Arduino into your computer's USB port. Ensure the port in the codes conforms the arduino's port. (If you change the arduino, the port might change. You can check the port with the Arduino IDE program.)


Open the Anaconda prompt and navigate to the folder where your olfactometer code is saved by using the "cd" command followed by the folder's path.


Once in the appropriate directory, execute the command "python app.py" to run the app.py file, which will initiate the GUI. Through the GUI, you can effectively manage and control the olfactometer.



The assembly

1. Building soldering board

We used ordered soldering board and pins for building it. It is very important to be very carefull while working with solder not to burn yourself or others. Soldering board helps with easier connections and better usage of space. In the picture below, you can see how we build our soldering board.

Sale (21)


2. Connecting

We connected all parts (transistors, the Arduino, power supply and valves together) together at the soldering board. Connections are explained at videos bellow.


3.Connection to codes

Once all manual connections are established, the Arduino is linked to the computer, ready to execute the programmed codes. Users are greeted with the crafted interface envisioned by our team. Within this interface, users are afforded the flexibility to choose between utilizing an Excel sheet or entering commands manually, tailored to their preferences and workflow.