In the 1966 science fiction classic “Fantastic Voyage,” a submarine crew is miniaturized so it can squeeze inside a human body and travel to a hot spot where medical assistance is needed.

A team from the Massachusetts Institute of Technology has adapted this idea for real life, replacing the shrunken squad with specially engineered E. coli bacteria and pairing them with a suite of electronics that fit neatly inside an ingestible pill.

They call their creation an IMBED — short for ingestible micro-bioelectronic device — and used it to detect excess blood in the stomachs of pigs. After finding blood, the capsule sent a wireless signal from within the pig’s body that was read by a smartphone and a laptop computer.

Other IMBEDs outfitted with different bacteria were able to detect one molecule that signals inflammation inside the gut and another that’s a biomarker for gastrointestinal infections.

The invention is described in Friday’s edition of the journal Science.

Although IMBEDs are still years away from being used in patients, gastroenterologists say they are already eager to get their hands on them.

“This has the potential to unlock a wealth of information about the body’s structure and function, its relationship with the environment, and the impact of disease and therapeutic interventions,” Dr. Peter Gibson and Dr. Rebecca Burgell of Australia’s Monash University wrote in a commentary that accompanies the study.

Inside the capsule are four wells that contain genetically engineered Escherichia coli bacteria.

These biosensors have been modified to recognize a particular molecule of interest, such as the blood component heme. A semi-permeable membrane traps the biosensors inside the capsules, but allows molecules from the environment to enter and be detected.

Once the target is identified, the bacteria metabolize it in a process that generates light through bioluminescence.

Beneath each well is a tiny electronic photodetector that can register light from the bacteria. A luminometer chip converts it into a digital signal, and a wireless transmitter sends that signal outside the body.

The MIT researchers, led by microbiology graduate student Mark Mimee and electrical engineering researcher Phillip Nadeau, put the IMBEDs through their paces in the stomachs of six pigs.

After the pigs were sedated, the scientists used an endoscope to deliver about one cup of solution into the pigs’ stomachs. Three of the pigs also got a tiny amount of pig blood.

Next, the team placed two IMBEDs in each pig’s stomach and used the endoscope to confirm that they were fully submerged. It took 52 minutes for the biosensors to recognize the blood, generate light and transmit the signal to the scientists. The signals grew stronger until the IMBEDs were removed two hours after the experiment began.

The IMBEDs correctly identified which three pigs had blood in their stomachs and which three did not, according to the study.

Other experiments outside of animals showed that the IMBEDs could recognize — and respond to — molecules that signal problems in the human gut.

The IMBEDs used in the Science study were 30 millimeters (a little more than one inch) long and 10 mm across.

Timothy Lu, a senior author of the study and Mimee’s adviser, acknowledged that the devices were “on the larger side,” but added: “I think for someone who’s motivated, they could definitely swallow it.”

Nadeau said he was optimistic that future IMBEDs could be at least one-third smaller than they are today by combining the luminescence detector, the microprocessor and the wireless transmitter onto a single chip. That would make it more palatable for patients.

“The idea would be you would swallow it and it would pass through the GI tract and eventually you would excrete it,” he said.

Lu said IMBEDs might eliminate the need for colonoscopies. Not only are colonoscopies uncomfortable, but the bowel prep required in advance of the exam alters the physiology inside the intestines, potentially masking signs of disease.

Gibson and Burgell described a future in which smaller IMBEDs could be placed into blood vessels to assess conditions in the circulatory system. Other versions could be implanted in solid organs — just like the five heroes of “Fantastic Voyage” who ventured inside a brain to remove a life-threatening blood clot.

“It is exciting to watch where this technology ultimately takes us,” Gibson and Burgell wrote.