A method of determining, by a system including an ingestible device and one or more processing devices, location of the ingestible medical device within a gastrointestinal tract of a body, wherein the device has a housing shaped as a pill or capsule, and wherein the method includes steps of: transmitting, by the ingestible device, a first illumination at a first wavelength and a second illumination at a second wavelength towards an environment external to the housing of the ingestible device and detecting a first reflectance from the environment resulting from the first illumination and a second reflectance from the environment resulting from the second illumination, wherein the first reflectance has a value indicative of an amount of light in the first reflectance, and the second reflectance has a value indicative of an amount of light in the second reflectance; storing, by the one or more processing devices, a ratio of the first reflectance value and the second reflectance value in a data set, the data set including a plurality of values, each of the plurality of values corresponding to a respective ratio of a respective first reflectance and a respective second reflectance detected at a respective time; obtaining, by the one or more processing devices, from the data set, a first subset of values, the first subset of values corresponding to a first predetermined number of stored ratios of recent first reflectances and second reflectances, the recent first reflectances and second reflectances detected during a recent time range; obtaining, by the one or more processing devices, from the data set, a second subset of values, the second subset of values corresponding to a second predetermined number of stored ratios of past first reflectances and second reflectances, the past first reflectances and second reflectances detected during a past time range, wherein the recent time range is separated from the past time range by a predetermined period of time; and identifying by the one or more processing devices, a change in the location of the ingestible device within the gastrointestinal tract of the body based on a difference or a ratio between a first mean value and a second mean value exceeding a threshold level; wherein the first mean value is the mean of the first subset of values and the second mean value is the mean of the second subset of values. transmitting, by the ingestible device, a first illumination at a first wavelength and a second illumination at a second wavelength towards an environment external to the housing of the ingestible device and detecting a first reflectance from the environment resulting from the first illumination and a second reflectance from the environment resulting from the second illumination, wherein the first reflectance has a value indicative of an amount of light in the first reflectance, and the second reflectance has a value indicative of an amount of light in the second reflectance; storing, by the one or more processing devices, a ratio of the first reflectance value and the second reflectance value in a data set, the data set including a plurality of values, each of the plurality of values corresponding to a respective ratio of a respective first reflectance and a respective second reflectance detected at a respective time; obtaining, by the one or more processing devices, from the data set, a first subset of values, the first subset of values corresponding to a first predetermined number of stored ratios of recent first reflectances and second reflectances, the recent first reflectances and second reflectances detected during a recent time range; obtaining, by the one or more processing devices, from the data set, a second subset of values, the second subset of values corresponding to a second predetermined number of stored ratios of past first reflectances and second reflectances, the past first reflectances and second reflectances detected during a past time range, wherein the recent time range is separated from the past time range by a predetermined period of time; and identifying by the one or more processing devices, a change in the location of the ingestible device within the gastrointestinal tract of the body based on a difference or a ratio between a first mean value and a second mean value exceeding a threshold level; wherein the first mean value is the mean of the first subset of values and the second mean value is the mean of the second subset of values.