📜 ⬆️ ⬇️

Touch the cover for a garbage can with their own hands

image

In the article I will tell you how to turn an ordinary bucket with a lid into an automatic one.
I went to the bucket - the lid opened, put what I needed into it, walked away - the lid closed.

The metal bucket is used, the lid is opened with a pedal, such buckets can be found in many stores.
To finish the bucket used IR LED, IR receiver, servo, microcontroller.
The control and monitoring of the servo overload is carried out using the Atmel ATtiny44A microcontroller.
')
The control program is written in C in Atmel Studio 6.1.

Electronic filling


Work algorithm


IR Sensor


The principle of operation is based on the property of reflection of infrared rays from an obstacle.
The IR diode sends a modulated code message to the space, and the IR receiver receives it.
To adjust the transmit power used trimmer RV1.
The carrier frequency of the signal is 38 kHz.
Biphasic (Manchester) coding is used. It does not require quartz frequency stabilization.

Here are the waveform coding waveforms:




Here is the packet waveform:



The IR receiver (I used Vishay TSOP4838) receives the signal, decodes and outputs the packet in an inverted form.

The package is repeated after a certain time:



The IR receiver is a smart device and tries to filter the signal, suppressing interference, various pulses that do not fit its understanding of the appropriate packet format.
Therefore, between the packets there should be a pause not less than the minimum.
For example, when using TSOP4838, if you make a pause of 15 bits with a packet length of 8 bits, the receiver will often pass packets.
With a pause of 30 bits - packets are not skipped.

Servo

image

To open the cover, use the standard Futaba S3001 serv.
She issued a force at 4.8 V about 2.4 kg-cm, and at 6 V - 3 kg-cm.
The cover is metal and relatively heavy, but this servo is enough for it.

Power is supplied to the servo only during its positioning. To do this, use the Logic level MOSFET transistor.
To control the current consumed by the servo drive, a 0.5 Ω resistor is used.
The microcontroller measures the voltage drop across it and, if it is exceeded, turns off the power to the servo.
The peak value of the current consumed during the opening of the cover is 500 mA, during closing - 150 mA, with “jamming” - 550 mA.

The servo drive is controlled by pulses with duration from 1.1 to 1.8 ms, which follow every 0.02 seconds.
After the end of the control pulse, the servo, if necessary, begins to be positioned.

Oscillograms:
Yellow - control pulses, blue - servo consumption (voltage drop on the shunt).

Here is the oscillogram of the start of normal servo positioning:



Normal positioning, somewhere in the middle of a move:



Here are oscillograms of serf jamming:



At the start we hold with our hands:



As you can see, at the very beginning there is a fairly large consumption almost regardless of whether the servo can move or not.
It is also seen that the instantaneous consumption of the servo cannot be greater than a certain value, and in order to control the impossibility of moving the drive, it is necessary, in the ideal case, to calculate the area under the blue graph.
In the program, the voltage drop across the shunt is read using an ADC and a simple method is used to sum the instantaneous values ​​over a period. If the amount exceeds a certain threshold - the servo stops.
The threshold is chosen experimentally.
The value at which the protection was triggered is stored in the EEPROM.

Scheme:


Program

The program is written in C in Atmel Studio 6.1.
Used AVR ATtiny44A microcontroller with 14 pins in DIP package.
It works at a frequency of approximately 7904000 Hz in order to easily get 38000 Hz for an IR LED.
By default, the frequency is 8 MHz, and the frequency of 7.9 MHz is obtained by changing the register OSCCAL.
I got the value 0xA7 at a voltage of 5 V.
When the supply voltage or temperature changes, the frequency will slightly leave, but this does not affect the performance of the IR sensor.

For transmission - reception of the infrared signal, servo control, timing is a single 8-bit timer operating at a frequency of 988 kHz and tuned to the Fast PWM mode.
The signal frequency is set by the OCR0A register. It has a value at which the timer counter (TCNT0) will be reset.
In OCR0B recorded value that determines the pulse duty factor. In our case - 50%.
The timer is configured so that the change in the value at the output of the controller to which the IR diode is connected occurs 2 times per period (given by OCR0A) - at zero TCNT0 and when TCNT0 is equal to OCR0B.

In the interrupt for equality TCNT0 and OCR0B, all the work on the reception and transmission of the IR signal is performed.

ISR(TIM0_COMPB_vect) { static uint8_t IR_error = 0; if(++IR_pulsecnt == IR_BIT_LENGTH/2) { if(IR_pausecnt == 0) { if(((IRSENS_IN & IRSENS) == 0) != ((TCCR0A & (1<<COM0B1)) != 0)) IR_error = 1; TCCR0A ^= (1<<COM0B1); } } else if(IR_pulsecnt == IR_BIT_LENGTH) { IR_pulsecnt = 0; if(IR_pausecnt) { if(--IR_pausecnt == 0) { // after pause send again IR_send = IR_SENDDATA; goto IRStartSending; } } else { if(IR_send == 0) // Packet was sent { if(IR_error == 0) IRDetected = 1; else IR_error = 0; IR_pausecnt = IR_PAUSEBITS; TCCR0A &= ~(1<<COM0B1); // assumes that COM0B0 = 0 } else { IRStartSending: TCCR0A = (TCCR0A & ~((1<<COM0B1))) | ((1<<COM0B1) * (IR_send & 1)); // assumes that COM0B0 = 0, if 1 - generate (Clear OC0B on Compare Match, set OC0B at BOTTOM) IR_send>>=1; } } } } 


The feature of the sending function is as follows - a packet is considered to be sent when the bit buffer is 0. This means that there must always be one in the high order of the packet to be sent.
The generation of the IR signal starts when the COM0B1 bit is set in the TCCR0A register. The implication is that the COM0B0 bit is 0 and has never been set before.

Servo control, countdown, bounce suppression of the contact of the buttons are performed in the interrupt on overflow of the same timer.
In standard mode, opening the lid is performed in two stages - first, several cycles slowly, then quickly until full opening. Made to reduce servo load and thrust.

The first button is used to manually open or close the lid.
The second button to stop opening and to enable / disable quick opening mode.

Assembly

The servo is connected to a vertical thrust, the horizontal thrust and the pedal are ejected.
The IR diode and receiver are mounted in a protruding plastic leg. Places for them there just enough.




Video:



Source:
yadi.sk/d/OGTOvX73Agk8h

Source: https://habr.com/ru/post/197070/


All Articles