Introduction: DIY Automatic Trash Can

About: GreenPAK™ is a broad family of cost-effective NVM programmable devices that enable innovators to integrate many system functions into a single custom circuit.

Almost every appliance in domestic life is experiencing innovation in automation and intelligence. In keeping with this trend, this app note will explain how to build a smart trash can that opens automatically when someone approaches, and closes automatically when the user moves away from it. Consequently, there is no need for the basket to be touched by user, which is beneficial when both user’s hands are dirty or incapacitated, such as when handling raw meat discards. The system is also equipped with special buttons to calibrate the distance: the user may select the distance the basket senses to be 20 cm, 40 cm or 60 cm. The project is implemented using a SLG46140V CMIC, a servo motor, and an ultrasonic sensor. We chose the SLG46140 for this project because it includes the appropriate elements to efficiently carry out all the system's functions. The IC receives the signal coming from the ultrasonic sensor in the form of pulses, where the latency time between the trigger and the received signal denotes the time needed for the sound signal to move and rebound from a facing object. The IC then correlates the time delay to distance; this distance is then measured in relation to the chosen distance threshold. If the threshold is met, a suitable PWM signal is generated and sent to the servo motor to rotate 90º and open the basket's lid. When the user moves away from the basket, the IC receives new values from the ultrasonic sensor, which generate a new PWM signal to make the motor rotate 90º in the opposite direction, thereby closing the lid.

The SLG46140 GreenPAK is a small IC that contains many distinct, configurable components. It can
be configured in minutes for this application and will perform all of the system's functions without the use of a microcontroller or similar processing device. Additionally, the low power consumption of the GreenPAK can save battery life, which makes the automatic garbage can sensor more appealing to a customer. We used a small servo motor (SG90) to build the project prototype, which is convenient for smallsized trash cans. The servo motor should be chosen by examining its torque and ensuring it can properly open the desired garbage lid. This project has been tested and implemented with a real-life prototype, please view the video attached to the project's files to see the prototype while operating.

Below we described steps needed understand how the GreenPAK chip has been programmed to create the Automatic Trash Can. However, if you just want to get to the result of programming, download GreenPAK software to view the already completed GreenPAK Design File. Plug the GreenPAK Development Kit to your computer and hit program to create the custom IC to control your Automatic Trash Can.

Step 1: Ultrasonic Sensor Control Design

GreenPAK Design

The design consists of two basic parts: the first is intended to receive the signal from the ultrasonic sensor and correlate it to distance. The second part is responsible for generating a PWM signal to rotate the servo motor.

Ultrasonic Sensor Control Design
The sensor which we used in this project is HC-SR04 Ultrasonic sensor module. This sensor has four pins. The GND and VCC pins provide the sensor with power and the TRIG and ECHO pins control the filtered ultrasonic signals. If we apply a high signal on the TRIG pin for no less than 10 us, the sensor will send an 8-cycle ultrasonic transmission burst at a frequency of 40 kHz. If there is an object facing the sensor the waves will rebound and will be received by the sensor. The sensor then will output a high signal on the ECHO pin with a period equal to the latency between the pulse’s transmission and reception. According to the sensor's datasheet, distance may be calculated by the following formula:

Time = Width of echo pulse (µs)

Distance in cm = Time / 58

Or you can utilize the speed of sound (340 m/s) and use the equation:

Distance = speed x time

Note that the time which we receive from the sensor is the time required for the sound signal to both receive and rebound. The distance value is therefore doubled, and we need to divide the time by two to get the correct distance. Pin3 in the GreenPAK has been configured to operate as an output, which is wired to the HC-SRO4’s TRIG pin. CNT2 and CNT3 generate a 10us pulse every 20ms, which is sent to Pin3. CNT2 has been configured to operate as “Delay”, with the counter data equal to 270. The delay triggers on the falling edge coming from P DLY. CNT3 is responsible for generating a pulse every 10ms and its counter data is 249. CNT3 output is connected to DFF0 having been used with P DLY as a frequency divider to trigger a CNT2 every 20ms. Pin4 has been configured to operate as an input which is connected to the ultrasonic sensor's ECHO pin. The input signal from Pin4 passes to 2-bit LUT0 and CNT0; both are used to calculate the pulse width to be compared with the chosen threshold. CNT0 has been configured to operate as a rising edge delay with counter data equal to 26. This delay time equals 1.14ms and consequently corresponds to a distance of 20cm. Therefore, CNT0 will output a pulse for each 20cm distance increment, which is calculated depending upon the ECHO pulse duration from the sensor. The Pipe Delay block is used to count whether one, two or three pulses come from CNT0. ‘1 Pipe Out’ correlates to a 20cm distance mark, ‘Out1’ correlates to a 40cm distance mark, and ‘Out0’ correlates to a 60cm distance mark. The signals from the Pipe Delay block pass to 4-bit LUT0 and 3-bit LUT0 to be compared with the DFF1, DFF2, and DFF5 outputs. If the active output for the Pipe Delay matches the value selected by the user a high signal permeates and is stored in DFF3. Pin5 is connected to a button which cycles the distance sensitivity of the device by clocking the 3-bit shift register composed by DFF1, DFF2, and DFF5. The DFFs outputs are connected to Pin9, Pin10, and Pin11, all of which have been configured to operate as outputs. These DFFs are responsible for saving the option selected by user, and the outputs can be sent to LEDs to indicate the current setting. Pin6 will toggle the inverting DFF4, which is responsible for activating or deactivating the system. DFF4’s output passes to 2-L2 and 2-L3. Both Pin5 and Pin6 are debounced with an external filter, since our design uses all of the CNT/DLY blocks in the SLG46140. 3-L1 has been configured to operate as an inverter that inverts the signal coming from Pin4. The inverter’s output is connected to the DFF3’s CK input. This connection enables DFF3 to hold the value located at the ‘D’ input when the sensor starts a new cycle of operation.

Step 2: Servo Motor Control Design

In this section a suitable PWM signal will be generated to rotate the servo motor arm and consequently open and close the basket according to the distance calculation. The servo motor’s angle of rotation is dictated by a pwm signal. In this project we will use the Tower Pro SG90, which is capable of rotating to almost 180° (90° each side). The rotation angle is extended through the PWM signal that is presented to the motor’s control input. The motor is positioned in the middle (angle 0°) if each PWM pulse is 1.5ms, positioned at 90° angle if the pulse width equals 2ms, and positioned at -90° if the pulse width equals 1ms. In our project, the motor should be positioned at 0° when the sensor does not detect an object within the specified range; the motor will rotate to about 90° angle when an object approaches the basket. When the system detects an object near to the basket, the DFF3 output switches from Low to High; the signal named “Object detected” passes to CNT1’s ‘DLY IN’ input. CNT1 has been configured to Both Edge Delay, which is used to prevent the noise or any swift movement in front of the sensor from opening the basket. In this case the basket will not be opened unless an object stands before it for more than half a second. CNT1’s counter data is 193, which equals 500ms. CNT1’s output is connected to the PWM0’s ‘MTRX sel#1’ and ‘MTRX sel#0’ inputs. PWM0 is responsible for generating the servo motor’s final PWM signal; the width of the generated pulse will correspond to the values that are previously stored in this block’s internal registers since we selected ‘Register selected through the matrix’ from the ‘IN+’ list. We stored value 24 in Register 1 and value 52 in Register 2.

A smart trash can that opens automatically when someone approaches it and closes automatically when they move away was built in this project. All of the system’s control functions, which include receiving signals from an ultrasonic sensor and generating a suitable signal for the servo motor, have been achieved using a single, small GreenPAK CMIC that performed effectively in this project.