Do you ever get lazy feeding your pets? Sure, we love our pets, but just sometimes we wish we could make it automatic. Today we’ll make a smart automatic pet feeder using Arduino Uno! The key components of the project include an RTC module to track time and manage feeding schedule, distance sensor to monitor food level, light sensor to distinguish day/night, and RFID to identify our pet. Let’s get started!
We’ll be using SparkFun Ambient Light Sensor TEMT6000 to detect if it’s Day or Night. It’s important to distinguish the two in order to determine when and how often we release the food. TEMT6000 light sensor has 3 pins: SIG; GND; VCC. Wiring this sensor to the Arduino Board is quite simple: the VCC to the 5V pin; GND to board’s GND pin and the SIG needs to be connected to an Analog Input. I’ve chosen the A0 pin. The output pin SIG works as a transistor, so the greater the light applied near the sensor, the higher the voltage is on the output of the pin.
The graph below shows a relationship between the current and illuminance perceived by the TEMT6000. Illuminance is a measure of total luminous flux (i.e. visible light emitted by a source, measured in lm) divided by an area in m². Generally, 1 illuminance (Ix) = 1 Im/m². The TEMT6000 recognizes typical human visible spectrum with light wavelengths in the range of 390–700 nm.
Figure 2: Wire diagram of TEMT6000 light sensor and Arduino Uno
Figure 3: Connection between TEMT6000 and Arduino Uno
Because this sensor is connected on an analog pin, the maximum value is 1023 due to the 10 bit resolution of the analog-to-digital converter. So for example, when the sensor is subjected on the highest light from my phone flash the value read from the sensor was around 1023.
Figure 4: Arduino serial monitor showing the maximum values of the sensor
To measure the distance I’ve chosen an analog sensor (Sharp GP2Y0A21YK) because it has the best results when compared to other distance sensors. The working principle of reflection is as follows: a signal is emitted and when it finds an obstacle in the way, it sends back also a signal (a voltage value that varies depending on how near/far is the obstacle); this voltage needs to be converted into distance.
The position of GP2Y0A21YK will be above the food container, measuring the emptiness of the bottle (i.e. food level) before initiating the automatic feeder function. With this distance sensor, the system will detect if in the food container (or bottle) is full or empty. The ways this program will work:
For a small distance: the automatic system will add only a small portion of food;
For a medium distance: your pet will receive a half of portion of food;
For a large distance: the automatic system will release full portion of food.
Here the distance implies the value from the place you mounted the distance sensor to the bottom of the food container. Because the range of the sensor is 10-80 cm, the sensor needs to be above the top of the food container with 10cm in order to read the correct value of the distance.
How to determine the best-fit line for the sensor:
The relationship between the sensor’s output voltage and the inverse of the measured distance is approximately linear over the sensor’s usable range. You can use this plot to convert the sensor output voltage to an approximate distance by constructing a best-fit line that relates the inverse of the output voltage (V) to distance (cm). In its simplest form, the linearizing equation can be that the distance to the reflective object is approximately equal to a constant scale factor (~27 V*cm) divided by the sensor’s output voltage. Adding a constant distance offset and modifying the scale factor can improve the fit of this line.
The time will be determined using the RTC DS1307 model. A real time clock is a system whose function is to determine real time. This circuit works on the base of a crystal oscillator with a frequency of 32.768 kHz. The principle is similar to the watches. An electronic oscillator function based on mechanical resonance of crystal vibration creates a precise frequency. This frequency is used for tracking date and time from the computer.
It’s a practical module because it has a battery that provides continuity even when the system is shut down.
Figure 8: Wire diagram for RTC module
Figure 9: Connection between the RTC, Sharp distance sensor, TEMT6000, and Uno
For an optimal usage, it is necessary to add 2 libraries for the module to work.
Wire (this library is already included in the Arduino IDE and can be easily added)
We will run a test code in to check the module. When we upload the program to Arduino board, the serial monitor will show the current date and hour. These 2 libraries have an example code for finding date and hour, called “SetTime”.
Click on Arduino IDE → File → Examples → DS1307RTC → SetTime
Figure 10: Finding SetTime on Arduino IDE
In Figure 11, you will see that the module works correctly as the current date and time are displayed.
Figure 11: Current date and time displayed correctly
For our application, we will only measure hour. To do this we need to extract from RTC module the exact hour. This will be done with the simple function of the RTC called “setSyncProvider(RTC.get)”. After implementing this function, you will be able to see the hour in serial monitor along with values from distance sensor and light sensor.
Tiberia is currently in her final year of electrical engineering at Politehnica University of Bucharest. She is very passionate about designing and developing Smart Home devices that make our everyday lives easier.