It would ensure patients receive only their prescribed amount of medication.
Government statistic show accidental overdoses have risen sharply over the past two decades.
The Brigham Young University students call their prototype design "Med Vault."
It plugs into a USB port so the pharmacist can access it and load the pills.
Patients cannot get a pill except at the time stated on the prescription.
"It's a pretty complicated system both on the electrical and the mechanical side," BYU electrical engineering student Madison Clark said.
"It's really challenging to make something that would allow pills of any shape and size to be dispensed while still maintaining the easy loading mechanism," BYU electrical engineering student Joel Marshall said.
A paramedic working with the students has applied for a patent on the device.