Researchers show how ChatGPT can generate code to control lab equipment, allowing scientists to automate experiments without writing software manually.
(Nanowerk Spotlight) Scientific instrumentation is the foundation of experimental research, but building flexible, programmable control systems around these tools remains an underdeveloped frontier. While hardware innovations have yielded increasingly precise and sensitive instruments—from atomic-resolution microscopes to optoelectronic detectors—actual experimental workflows often remain constrained by rigid software and limited automation.
In many laboratories, critical devices are controlled by proprietary programs that cannot be adapted without extensive coding. Even where customization is possible, it typically demands programming expertise that lies outside the skillset of most researchers. As a result, substantial experimental potential is left unrealized not because of hardware limitations, but because of the friction between experimental goals and software access.
Efforts to overcome this barrier have drawn on artificial intelligence, particularly in automating parts of the scientific process such as data analysis, image recognition, or materials prediction. But these tools usually address downstream tasks—what happens after data is collected—rather than the core challenge of making instruments easier to control and integrate.
Robotic systems designed for lab automation have shown success in repetitive workflows, yet they often rely on custom-built architectures that are difficult to generalize. Fully autonomous systems that can adapt to new experimental setups, interpret ambiguous instructions, and control real hardware remain rare.
Large language models present a novel opportunity in this context. Unlike task-specific AI systems, language models are trained to translate open-ended human instructions into executable text. When combined with programming libraries and hardware interfaces, this capacity can be repurposed for instrument control.
A researcher can describe what they want to do in plain language, and the model can return code that performs the task. This framework effectively removes a major bottleneck in experimental design: the need to write bespoke software for each new setup or workflow. It reframes code generation not as a technical task, but as a collaborative process driven by iterative feedback between the user and the model.
A recent study operationalizes this concept (Small Structures, “Toward Full Autonomous Laboratory Instrumentation Control with Large Language Models”). It investigates how a language model can serve as both a real-time code assistant and an autonomous agent in laboratory settings, capable of managing instrumentation workflows from setup to data acquisition.
Workflow of the LLM (ChatGPT)-based instrumentation control. After identifying the computer–instrument interfaces, the instruments are controlled using scripts generated in response to human prompts through a large language model (e.g., ChatGPT). Reprinted from DOI:10.1002/sstr.202500173, CC BY)
Focusing on an optoelectronic measurement system that can be configured as a single-pixel camera or a scanning photocurrent microscope, the authors demonstrate how large language models can not only generate code for controlling devices, but also adjust it interactively or execute it autonomously in a feedback loop. In doing so, the research points to a broader reconfiguration of how laboratories might integrate AI tools—not as static code generators, but as flexible, adaptive interfaces between researchers and machines.
The team began by constructing a minimal experimental setup using readily available commercial components. These included a Keithley 2450 source-measure unit (used to apply voltage and measure current), a Standa XY stage (to move a sample with high precision), a cadmium sulfide photodetector, and a fiber-coupled LED for illumination. The setup was capable of operating in two distinct modes: one as a single-pixel optical camera that measures reflected light intensity across a surface, and another as a scanning photocurrent microscope that maps variations in electrical response when light strikes the material.
Each device communicated using distinct hardware protocols. The Keithley instrument used a standardized VISA interface over USB, while the XY stage operated over a more specialized serial protocol. Instead of manually writing the software needed to control this hardware, the researchers employed ChatGPT to iteratively generate it. Their prompts were structured as short, natural language requests—e.g., asking for MATLAB code to initialize the XY stage, or Python code to perform current measurements. At each step, they tested the generated code, reviewed the outcome, and either accepted the result or adjusted the prompt to refine it. This process—called STEP (segment, test, evaluate, proceed)—reduced the complexity of system integration into manageable, incremental steps.
In the single-pixel camera mode, the XY stage moved the sample in a raster pattern, pausing at each location to allow the source-measure unit to record a photocurrent value from the detector. These values were correlated with the amount of light reflected at each position and were assembled into a two-dimensional reflectance image.
The workflow, including data acquisition and visualization, was entirely built using code segments generated by ChatGPT. A variation of the setup—employing a collimated light source and tighter focusing—was then used to perform scanning photocurrent microscopy, which measured spatial variation in the electrical response of the photodetector surface.
In both cases, the key advantage of using the language model was not speed but accessibility. Researchers with minimal programming knowledge were able to build and run custom experimental systems by iteratively querying a language model, reviewing the results, and refining the code. Tasks that would ordinarily require familiarity with low-level device commands or manufacturer-specific drivers were completed through natural language dialogue.
Typical prompts used in LLM-based instrumentation illustrate the STEP approach (segment, test, evaluate, proceed). a) The flow chart of the process to combine the movement of stage with the Keithley 2450 source measurement unit. b) The typical prompt used for the corresponding interaction with each block in (a). The key point is breaking the coding process into small steps so the user can quickly review and adjust the code through interaction with ChatGPT. (Reprinted from DOI:10.1002/sstr.202500173, CC BY)
To extend this approach beyond manual prompting, the authors developed an autonomous software agent powered by ChatGPT’s API. The agent operated in a closed feedback loop: it sent a prompt to the API, received Python code in return, executed that code, and used the resulting output—or any error message—to generate the next prompt. Its task was to perform a full current-voltage sweep on a photoresistor, a standard test in electronics where the current is measured at different applied voltages. The agent proceeded step by step, correcting errors, refining the code, and saving the results. By the end of the loop, it had generated and executed a complete measurement script without further human input.
The underlying architecture involved structured system messages to define the agent’s role and a series of user messages that broke down the experimental goals into subtasks. The model was instructed to maintain progress toward a defined endpoint—measuring and plotting an I–V curve—while automatically handling errors and confirming successful execution after each step. This framework allowed the model to function as a task-aware agent capable of executing physical measurements, adjusting procedures, and saving outputs in an organized form.
Despite the success of the agent in this controlled task, the authors clearly acknowledge the current limitations of language models in laboratory automation. These systems are not designed for real-time control and cannot yet respond to events on sub-second timescales.
Tasks requiring rapid feedback, continuous monitoring, or precise timing remain outside the scope of general-purpose LLMs. Moreover, automatically generated code can pose safety and operational risks, especially if used to control high-voltage equipment or fragile materials. Data privacy is also a concern when instruments are operated through cloud-based models.
The study suggests several strategies for mitigating these risks. Generated code should be tested in safe, simulated environments before live execution. All AI-generated control software should be supervised by human operators, especially during deployment. For laboratories working with sensitive systems or private data, local deployment of the language model can provide better control over data flow and system behavior. In the future, combining LLMs with rule-based control layers, real-time feedback systems, and hardware-level safety checks may offer a more robust framework for autonomous experimentation.
This work demonstrates how large language models can act as a functional interface between researchers and their equipment, dramatically reducing the technical threshold for building and modifying experimental systems. The approach is not just about writing code more quickly—it reconfigures how scientists interact with instruments by making code generation interactive, modular, and accessible. Rather than relying on specialized engineers to customize control software, researchers can now work directly with their tools using conversational inputs, guided by an iterative, model-assisted workflow.
As these systems improve and safety mechanisms mature, the use of language models in laboratory settings could shift from experimental to routine. The ability to describe an experiment in plain language and have the model generate, test, and refine the necessary software introduces a new form of experimental flexibility—one where control systems are no longer fixed assets, but dynamic, reconfigurable components of the scientific process.
Get our Nanotechnology Spotlight updates to your inbox!
Thank you!
You have successfully joined our subscriber list.
Become a Spotlight guest author! Join our large and growing group of guest contributors. Have you just published a scientific paper or have other exciting developments to share with the nanotechnology community? Here is how to publish on nanowerk.com.