Business ideas are often hatched in unlikely places. But for Atsushi Nakanishi, an epiphany could not have hit him at a worse time.

On a fateful day in September 2013, Nakanishi, then a student at the University of California, Berkeley, was in the middle of moving house. He was hurriedly walking down the street, carrying carts full of luggage, when he felt the unexpected, unstoppable urge to, ahem, poo.

“It just happened,” he recalled recently at his office in Shibuya, Tokyo, noting that he had been trying to tame an uneasiness in his stomach that day after having spicy noodles for breakfast. “As I was walking, I was thinking I could wait to go to the toilet for 15 more minutes, because I couldn’t find one nearby, until I could get to the house I was moving into. But then my determination wavered when I saw a store. For a second, I thought the store might let me use its bathroom.”

The next minute, he had soiled his pants. Deeply embarrassed, he headed back to his apartment to change and wash his underwear.

Nakanishi, now 32, said the experience, the first time that had happened to him, was traumatic. But it also left him wondering how he could have avoided the disaster.

That eventually led to what he does today as CEO of startup Triple W, which he set up in May 2014. He is developing a wearable device that monitors the bowel movements of the wearers and predicts when exactly they will need to go to the toilet.

Named D Free, the device, which is smaller than a box of matches, has an ultrasonic sensor inside. It is designed to monitor changes in the size of the bladder and the rectum by picking up echoes and estimating the amount of urine and feces accumulated in the body. The data are then sent to smartphones or PCs, to be translated into easy-to-understand messages, such as “20 minutes left before the person is ready to have a bowel movement.”

Although Nakanishi had no background in engineering, he said he came up with the idea of using ultrasound himself.

“I thought that, if ultrasound can capture a fetus as small as a bean, it should be a no-brainer to keep track of poo.”

The Keio University graduate then turned to a network of friends and contacts both in Japan and the U.S. to develop and design the product, including a high school buddy who worked as an endoscope developer at a major electronics company in Japan.

The engineer used his own body to collect and analyze data, through which the device has been modified and improved to a point where the margin of error is down to about 15 minutes, Nakanishi said.

While it was a personal experience that sparked his venture, the entrepreneur now sees the biggest demand for D Free in nursing homes.

He is pairing the device with software that allows nursing home workers to manage real-time bowel movement data of all residents at once.

Nakanishi said that, with his service, he can help care facilities cut back on diaper costs, by allowing them to find diapers in the right size for each resident. Currently, facilities tend to use the largest — and thus costliest — pads for everyone because they want to avoid a worst-case scenario of urine overflowing from pads, he said. The service can also reduce the burden for workers, by giving them “forecasts” on when to take residents to the toilet.

Most importantly, it can improve the quality of life for the device-wearers by helping them become less reliant on diapers, he argued.

“The three biggest concerns for care workers are toilet care, diet and bathing,” he said. “Toilet care, in particular, is most time-consuming, because workers cannot plan ahead and, therefore, must keep watch around the clock.”

Last month, the firm tested the product to respond to urination needs at a facility in Tokyo. The responses from seven users were positive, and the firm plans to increase the number of users to 100 by July, and to 1,000 or 2,000 in the fall. Nakanishi also plans to market the service to retail consumers at the end of this year or early next year, and wants to add defecation monitoring to the product by the end of the year.

Nakanishi’s goal is to serve 100 million people worldwide by 2020, including up to 2 million domestic users.

That might sound like a far-fetched dream for a company with just seven employees, but Nakanishi is confident he can achieve this, and he has enough capital at hand.

Triple W has secured nearly ¥200 million in venture capital funding so far, including ¥77 million from Nissay Capital Co. and ¥70 million from the state-backed New Energy and Industrial Technology Development Organization.