Ultrasonic rodent/animal scarer - Page 1
Forum section: electronics / general

author: HwAoRrDk
author_rank: Super Contributor
timestamp: January 12, 2017, 11:21:17 pm
content: Today I had cause to tear down one of those ultrasonic animal scaring gadgets. My mother uses it in the garden to ward off the neighbours cats and stop them digging holes or pooping in the flowerbeds.Seemed quite effective, until today, when she complained it had stopped working and was just sitting there triggering over and over and making a nasty buzzing noise when it did so. So, out with the screwdriver and "take it apaaart"!These things appear to work like any regular PIR sensor, but with a speaker output that produces an ultrasonic burst of noise - high frequency enough to be inaudible by humans, but annoyingly (painfully?) audible by most small mammals. (Funny aside: the instructions claim it outputs sound at a frequency of "23Mhz". Yeah... sure.I think they meant 23KHz - and in fact, I measured it at 26.2KHz.)When looking at the circuitry of this device, I thought something was quite weird about it, that made me think "why on earth did they design it like that?".So, as expected, when the PIR circuitry (an all-in-one LP0001 chip) triggers, it activates the ultrasonic noise. Now, you might think they'd put in a 555 or something simple like that to generate a signal with the nominal 23KHz frequency. But no! Instead, what we have is as follows:- PIR trigger output switches NPN transistor Q2, which in turn pulls the base of PNP transistor Q1 to ground, switching it on.- Q1 switches power to a status LED and to a 3V regulator U3.- The regulator powers the MCU U4 (at least, I think it's an MCU - it's one of those anonymous 8-pin SOIC with no markings the Chinese love to use).- MCU outputs a 26KHz square wave on pin 4 which switches NPN transistor Q3 to gate power through the speaker/transducer at the given frequency.So: a) they're using a small microcontroller as literally nothing more than a signal generator, and; b) switching the whole damn thing, 3V regulator included, on or off during the PIR trigger period!Another weird thing is that the MCU is the only SMD part on the board. It's all through-hole otherwise. Plus, because it's a single-sided board, the MCU had to be mounted on the back, and looks to have been hand-soldered there (tell-tale flux residue remains on the pins).By the way, when I was reverse-engineering it, I wasn't sure what to make of that inductor used to drive the speaker. I think I have it wrong on the schematic above. It's actually a 3-leaded radial part, with two of the leads appearing to be shorted together. One lead has the same +9V power as going to one side of the speaker, the second goes to the collector of the transistor, and the third goes to the other side of the speaker.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: January 12, 2017, 11:30:27 pm
content: Oh, I forgot to mention: turns out it wasn't actually faulty in the end.The 9V batteries had simply got so low it had got the unit stuck in some kind of loop. Because everything on the board except the speaker and LED actually runs at 3V, the detection circuitry was still triggering fine, but as soon as the speaker sounded, the higher current draw pulled the voltage too low, resetting everything and making it start over again. The buzzing came from the fact that the MCU seems to be programmed to first emit an intentionally audible 'tick' from the speaker before it emits the ultrasonic frequency, and when it's resetting many times a second, that tick turns into a buzz.

author: zl2wrw
author_rank: Regular Contributor
timestamp: January 13, 2017, 12:36:14 am
content: Quote from: HwAoRrDk on January 12, 2017, 11:21:17 pmIs the speaker a peizo electric speaker/tweeter?If so, electrically, it looks like a lossy capacitor - the inductor across it will probably be to make it resonate at ~ 26 kHz.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: January 13, 2017, 12:01:24 pm
content: I'm not sure actually. The speaker has a plastic cone-shaped back cover that is heat-staked to the housing, so I can't look at it without breaking it apart. Although I suspect it is a piezo because of the lack of flyback protection diode for the drive transistor.

author: james_s
author_rank: Super Contributor
timestamp: February 02, 2017, 02:03:12 am
content: Almost looks like someone had a pile of leftover parts and told someone to design something around them. Or maybe it was designed by an intern or some guy in his garage who managed to convince a company to mass produce his invention.

author: nctnico
author_rank: Super Contributor
timestamp: February 02, 2017, 03:01:04 pm
content: The inductor is probably a transformer to increase the output voltage. If the speaker is a piezo transducer chances are the whole thing is rigged to resonate.

author: helius
author_rank: Super Contributor
timestamp: February 02, 2017, 03:34:10 pm
content: Would the X-Men villain, Magneto, keep an "ultrasonic rodent" as a pet?

author: metrologist
author_rank: Super Contributor
timestamp: February 02, 2017, 04:43:28 pm
content: Do these things even work? I have a raccoon family in a backyard palm tree that I would like to encourage to leave. A home built solution would carry the required oomph needed.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: February 02, 2017, 06:13:57 pm
content: Well, all I can say is that it appears to work on cats. My mother reports that since setting up the device, there hasn't been a single instance of one of the neighbour's cats messing up her garden. But... then again, could be coincidence, as it is now winter and maybe the cats aren't interested in being outside much.Can't say whether these things work on raccoons. Although some sources I was able to find say their hearing range is up to 40KHz, which just a little less than cats.I do know that versions of these ultrasonic devices that claim to repel insects, fleas, dust mites, etc. are complete bollocks, though.

author: Rick Law
author_rank: Super Contributor
timestamp: February 05, 2017, 03:52:16 am
content: Quote from: james_s on February 02, 2017, 02:03:12 amMay be it is the "brother in law rule" in action...(Brother of wife of owner of the company. Whatever he does, it is always good work - or - at least that is what the owner has to make his wife think he thinks...)

author: Seekonk
author_rank: Super Contributor
timestamp: February 05, 2017, 11:57:15 am
content: I had heard elsewhere that the MCU is used to drive a multiple of frequencies in random patterns. A frequency counter likely only measures the average count.

author: Housedad
author_rank: Frequent Contributor
timestamp: February 17, 2017, 04:12:32 am
content: Does that mean he has a reason to buy a $1000 frequency analyzer? What the heck, any reason is a good reason!!

author: HwAoRrDk
author_rank: Super Contributor
timestamp: May 09, 2017, 09:42:46 pm
content: Well, the device I mentioned at the beginning of this thread chewed its way through another pair of 9V batteries in just a few months, so rather than keep buying batteries I suggested we try one of the solar-powered ones that are common on eBay. We got one of these:A quick mini-review:Pros:- Very sensitive to movement through quite a wide arc of view.- Sturdy spike that locates it securely in the ground.Cons:- Sensor's arc of view is needless wide in the vertical axis for something monitoring near ground-level (so triggered by birds in nearby trees, etc.).- Ni-MH batteries are not user-accessible, nor externally rechargeable.- Not properly weatherproof, moisture easily gets inside.- Makes a short, loud beeping noise every time it triggers (which wasn't mentioned inanyof the information on the eBay seller's page).Now, about that last point: it's been installed in my mother's garden for a couple of weeks now, and because it's so sensitive and is triggered so frequently, she's just about fed up with the noise and wanted me to see if I could do anything to silence it. So I took it apart to see what could be done to modify it's behaviour.This one is a lot more sensibly-designed (at least from an electronics point of view) than the previous one. It uses an integrated PIR sensor with a digital output, and the whole thing is controlled by a microcontroller (appears to be a PIC 12F510 clone - pin-out matches, and is marked '510') rather than some off-the-shelf dedicated function PIR controller chip. It was quite easy to reverse-engineer the circuit; schematic attached below.An interesting point is that the circuit includes functionality to flash an external LED (or perhaps multiple LEDs) while it is triggered, but the manufacturer did not equip this particular device with that option. So perhaps this board is generic to more than one model. However, given the propensity for cost-cutting on cheapo electronic consumer devices like this, it's strange they still populated the board with the transistor and resistors for this feature.Anyway, back to my mission: silence the damn thing!I initially thought - given the external design of two 'speakers' on the front - that perhaps there was a separate buzzer being used for the audible beep, and a second for the ultrasonic, and I could simply disconnect the audible buzzer. But, teardown revealed that the second 'speaker' on the front is fake. So, the same transducer is obviously being used for the audible and ultrasonic output.Analysing the output drive circuitry with a 'scope revealed the following signals: upon triggering it outputs a 5.1 kHz square wave for 2 secs, then 2 secs each of 26, 35, 45, 54, and 63 kHz square waves. The latter ultrasonic sequence repeats for as long as the device remains triggered.So, given that the 5.1 kHz beep is integral to the device's output, how can I go about eliminating this without affecting the rest of the output?The only thing I can think of is a high-pass filter, but I'm not sure that something simple like a passive RC filter would work effectively. If I had, for example, a 20 kHz high-pass RC filter, I'm not convinced the shallow roll-off would attenuate the voltage level enough at 5.1 kHz to eliminate that part of the output. Also, I'm not certain to what level I need to attenuate the signal to nullify the drive transistor's switching. Would it just need to be below the typical base-emitter voltage of 0.6V?Are there any better, simple solutions? I suspect there are more sophisticated high-pass filter setups (i.e. multiple-order and/or active) that would work great, but I don't want to start adding a dozen passives or op-amps, etc.A crazy thought I had was to replace the existing microcontroller with something pin-compatible and write my own code for it - seems pretty simple, just an interrupt for the PIR trigger and a timer. Don't think I'm quite prepared to go to those lengths, though...

author: james_s
author_rank: Super Contributor
timestamp: May 09, 2017, 10:52:33 pm
content: It might be easier to re-write the firmware. You know now exactly how it works, so it should be fairly trivial to write some code that will do the same thing, minus the part you don't want.

author: stj
author_rank: Super Contributor
timestamp: May 09, 2017, 11:14:11 pm
content: i hate these things, i can hear them!they usually have a sweeping burst going downwards in frequency - probably caused by a cap discharging.

author: Ian.M
author_rank: Super Contributor
timestamp: May 10, 2017, 12:14:49 am
content: Drop in a PIC12F1571 or some other PIC12 that can be erased and programmed at 3.3V, has on-chip debug support and that's got a PWM module on GP2 so you don't have to bitbang the ultrasound output and write your own firmware. As there are 1K resistors isolating GP0 and GP1 from their loads and /MCLR is floating, you can easily patch in an ICSP header and as the LEDs are non-critical, debug in circuit via the same ICSP header.Take the old PIC and hook it up to a logic analyser or a DSO with data capture + some means of triggering it in a repeatable fashion and analyse the toneburst to see if they are doing anything clever like chirping the frequency.If you want to get really fancy, add a low power RF transmitter module on the spare I/O pin GP4 so it can signal when its triggered. If it is repeatedly triggered you can use that signal to activate a remote solenoid valve to turn on a sprinkler system for one minute, which should see any persistent cats dogs or varmits leave the area in haste.Reassemble with sealant on the case seams apart from a drain hole at the bottom, which needs to be protected against insect intrusion by a fine mesh screen - cut up a tea-strainer for something suitable and gunk it in place.As some people will want to deter possums and squirrels, I'm not surprised it has a wide vertical viewing angle, so I'd add a shade overhanging the sensor to blind it to birds in trees etc.

author: Alex Nikitin
author_rank: Super Contributor
timestamp: May 10, 2017, 10:39:38 am
content: 74HC74 as a monostable to mute the output for 2 sec required .CheersAlex

author: David Hess
author_rank: Super Contributor
timestamp: May 10, 2017, 03:03:08 pm
content: The microcontroller might be the cheapest way to implement a swept and amplitude modulated output. For maximum output though the transducer needs to be driven at its resonate frequency so I would use a driver which does that and amplitude modulate it. That is pretty easy to do with a simple discrete design.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: May 15, 2017, 05:31:37 pm
content: I thought I would take a shot at designing my own board to replace the existing one wholesale. That's what a boring Sunday afternoon does for you.I largely followed the circuitry of the original (from my reverse-engineered schematic I posted above), but made a few changes:- Removed the circuitry for flashing auxiliary LEDs, as this unit doesn't have them.- Uses an ATtiny13A. Slightly overkill for this application, but it's the lowest spec ATtiny in a DIP package. Will use the timer's OC0A output to generate the transducer waveform, and PCINT to handle the trigger input. When not active, the MCU will go into sleep mode, so standby power draw should be tiny compared to the 9mA I observed the device currently consuming in standby.- Run everything at 3V rather than 3.3V. Should allow a little more life from the battery. Plus, 3V is the nominal supply voltage for the PIR sensor anyway (3.3V is actually the maximum recommended voltage).- Uses an LP2950 regulator, which has greatly less overhead than the existing AMS1117, so should also contribute to increased battery life. Drop-out voltage is millivolts versus >1V, and quiescent current is microamps versus 5-10mA.- Added a proper connector for the solar panel, rather than the dodgy directly-soldered wires at present.- BC337 instead of S8050 transistor to switch the transducer.However, there's currently a few things unresolved, and I could do with some feedback.1. I'm not sure what the exact value of the inductor across the transducer is. The existing one is a small radial-leaded inductor, and is labelled '101'. I assumed that must be 100uH, but I'm not convinced that's correct, or perhaps not in microhenries, because I can't find any inductors of that size (5mm diameter, 7mm height) with a value of 100uH. So what value is it likely to be? 1uH? Something else?2. I don't quite understand what the purpose of the capacitor on the PIR sensor's 'ONTIME' pin is. As I understand it, the 1M and 75K resistors form a divider giving a nominal 230mV (I measured around 200mV), and this sets the time period that the PIR will hold its 'REL' (i.e. trigger) pin high when active. But, I managed to find the datasheet for the exact sensor (attached below), and the info regarding the on-time setting is most confusing. It talks about setting it in two ways: 'analog' and 'digital', with some example graphs of time versus resistance for various cap values for the former, and a table fractions of VCC for the latter (and I don't know what differs the second 'center voltage' column versus the first). Can anyone make any sense of this?3. Can't decide what clock speed to run the ATtiny13A at: 4.8 or 9.6MHz. Will the lower speed yield lower current usage?

author: james_s
author_rank: Super Contributor
timestamp: May 15, 2017, 06:42:07 pm
content: That seems like a lot more work than just swapping out the existing microcontroller.Yes, lower clock speed results in lower current draw.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: May 15, 2017, 07:42:07 pm
content: Indeed. However:a) I don't have any equipment with which to program PICs, nor any real experience with them.b) I don't have any means of getting the old chip off the board without destroying it.c) There's an opportunity to make the device perform better.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: June 13, 2017, 09:21:35 pm
content: I actually went ahead and had some boards made of my new circuit design. Largely the same as I posted previously, but with two changes: I added a jumper to make an audible beep optional (in case for some insane reason I actually want that behaviour again), and made the inductor's footprint a dual one for two different pitches of lead (was having trouble finding a small enough inductor).Because they had a special offer on, I went with Elecrow for the boards. Fairly pleased with how they came out, with only a couple of minor issues.One was that a square pad on one pin of the PIR sensor's footprint somehow got rotated 45 degrees, but its cut-out in the surrounding ground plane wasn't. However, there is still clearance between it and the ground plane, so no problem with shorting, which is good. I don't know how this occurred, as my Gerbers seem to be fine and have the pad in the correct orientation.The second issue was that their edge routing was a bit sloppy and left a spike on one corner of every board, but again, no big deal. I was quite amazed with how fast they arrived. I only paid for the standard, basic shipping, with the expectation that it'd take 2-3 weeks to arrive from China, but it actually only took 7 days!Total time from ordering to arrival was 10 days. Not bad for only $8.Here it is assembled:I robbed the PIR sensor, inductor and the red LED's plastic spacer from the old board. I wasn't planning to re-use the inductor, but I couldn't find any 100uH as small as the existing one, and I'm not 100% sure it's actually 100uH, as I have nothing to measure with, so I thought best to stick with the old part. The old board (sans borrowed components) for comparison:One issue I had when I went to re-assemble the unit was that my capacitors were slightly too tall and were interfering with the plastic PIR lens. Luckily, this was easily solved by simply trimming a little off the edge of the lens:I also soldered new wires on to the solar panel, so that they had a proper connector, rather than the wires soldered direct to the board as on the old one.As mentioned before, I used an Atmel ATtiny13A. The logic of the code was fairly simple, but I made a substantial number of improvements over how the old board performs. A few notable things:Eliminated the audible trigger beep, but made it so a jumper link can be installed to re-enable it if so desired. I'm never going to, as the driving force behind this whole endeavour was to get rid of the beep, but I had an IO pin going spare, so what the hell.The sequence of ultrasonic tones (25, 35, 45, 55, 65 kHz) is randomised every time the unit triggers. To seed the code's random number generator at power-on, I take two 8-bit ADC readings from a floating pin - which should have some fluctuation - and concatenate them into the 16-bit value required bysrand().The MCU goes into power down sleep mode when in standby and awaiting trigger, with all peripherals (including the brown-out detector) turned off. Current draw is so low my cheapo meter can't even measure it!To play the ultrasonic tones (each for 2 secs), I use another trick to minimise power consumption. Instead of just a simple delay loop, I sleep in idle mode and use the watchdog timer to wake up after the required time has elapsed. Idle mode still allows any timers to run, and thus continue to generate the tone while the CPU sleeps. Because of this, the MCU draws only 190uA while playing.Because of these extra code features, I nearly ran out of room on the flash memory: 1,018 bytes out of 1,024 used!And that's compiled with-Os...Overall I'd say I'm quite pleased with how this project turned out. I've eliminated an extremely annoying feature (the beep), added one (randomised sequence of ultrasonic tones) and significantly improved battery life. If you recall, the previous board drew 9mA when in standby, whereas now it's essentially nothing.There are a couple of things that didn't end up as I would have liked though.First is that for some reason, while triggered and emitting the ultrasonic tones, the unit's power draw as a whole has gone up. It's around 100-140mA now, whereas the old version was about 80-90mA. Not sure what has caused this, but I think it may be because it's now louder - the beep, when enabled, seemed to have more volume, at least. Perhaps my choice of transistor is passing more current than the old one? My choice of BC337 (what I had laying around) should have a similar hFEas the old transistor, but of course I can't be certain what the true spec of that was.The second is that the output frequencies are a little off from their nominal figure. The ultrasonics are all down by about 2-3 kHz (e.g. 25 => 23), and the 5.1 kHz beep comes out at 4.8 kHz. Not entirely sure why that is. Perhaps I didn't set the timer up in my code entirely correctly, although I merely adapted some code I previously used elsewhere with good accuracy. Perhaps, with only an 8-bit timer, it's because there's some rounding to the calculate OCR values at a clock speed of 1.2 MHz (default for ATtiny13A - 9.6 MHz with CKDIV8 fuse set) and >20 kHz output frequencies. But that doesn't explain the lower-frequency beep being off too.

author: bwack
author_rank: Contributor
timestamp: June 18, 2017, 12:47:54 pm
content: Regarding the current pull. There is a lot of resistors there you can measaure and calculate currents from. what is next ? Converting to solar power ?

author: aries
author_rank: Newbie
timestamp: July 11, 2017, 02:11:24 am
content: Hi, when checking the schematic with the image of the original PCB, it seems to me that the PIR connections are not correct, having to be changed 1 by 2, 2 by 3, 3 by 4 and 4 by 1, besides the resistor R8 does not connect to the pin 5 of U2, should be connected to Q1 base.Can you please tell me if what I indicate is correct?. Do you have the code for the PIC?

author: stj
author_rank: Super Contributor
timestamp: July 11, 2017, 02:07:21 pm
content: Quote from: bwack on June 18, 2017, 12:47:54 pmi was just thinking about that, we have those solar garden-spike led lights here in a 2-pack for £1 !!!!

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 11, 2017, 05:40:57 pm
content: Quote from: aries on July 11, 2017, 02:11:24 amAre you referring to the pinout in the datasheet PDF for the PIR sensor I posted earlier? If so, I can see how you might think that - but, no, for two reasons. Firstly, the pinout in the datasheet - despite not being labelled so - is bottom view. So when viewed from the top, it's mirrored, with ONTIME on the left and REL on the right. In addition to that, when laying out my PCB I was lazy and used an existing pattern/footprint for a TO-39-4, which had pin 1 marked at the 9-o'clock position, not the 12-o'clock position, and assigned the pins correctly according to the locating tab, not the numbers.So, what I have is correct (it works) but doesn't match the datasheet by numbers.I see I did get the order of R8 and R7 mixed up. The R8 pull-down does indeed come after the R7 series resistor. No matter, it's functionally the same either way.Quote from: aries on July 11, 2017, 02:11:24 amNo. I wasn't concerned with getting the code off the existing chip. And it was only an educated guess that it's a PIC. I don't really know for sure.

author: Ian.M
author_rank: Super Contributor
timestamp: July 11, 2017, 07:24:44 pm
content: Why not post your AVR code?

author: ivan747
author_rank: Super Contributor
timestamp: July 12, 2017, 04:19:49 pm
content: Quote from: Housedad on February 17, 2017, 04:12:32 amYou bet it!

author: aries
author_rank: Newbie
timestamp: July 13, 2017, 07:03:20 pm
content: Excuse me by insist, but R8 should go since base to emitter of Q1, and R7 should go since pin 5 of U2 to the base of Q1.

author: aries
author_rank: Newbie
timestamp: September 28, 2018, 05:46:02 pm
content: HelloPlease, you could share your AVR code?Thanks.