An algorithm to detect the timing of each breath from an electromyogram (EMG) signal was developed. The algorithm has low computation cost and would be suitable for applications of implantable diaphragm pacing devices or as a trigger for each breath generated by a mechanical ventilator. The algorithm was implemented both in a LabView program on a desktop computer and in a C program on a microcontroller chip, and was tested on the EMG signal from the left diaphragm muscle of an anesthetized rat via implanted electrodes. The breath detection by the algorithm was over 99% accurate when the anesthetized rat was lying still, but for periods when the rat was gently wiggled to introduce noise and irregular breathing patterns, 19% of the breaths were missed and false positives occurred 6% of the time.