Thursday, June 3, 2021

A Smart Cat Deterrent

Recently our geriatric Siamese cat has started peeing on the floor.  We are going to take her into our vet to determine if she has a UTI,  but it's quite possible that she is just going senile.  She's exhibiting other behavior that suggests this is the case.  We're not to the point of putting her down for that yet,  because we have no carpet on our floors.  Slate and hardwood.  But we DO have some wool area rugs at risk.

So I started thinking about a way to restrict her access to places she visits when she transgresses.  There are some commercial and DIY solutions that combine a motion sensor with some sort of deterrent -- making a loud noise and some sort of electronically-activated spray system are out there.  But they also are activated by a human entering that space.  Some kind of sophisticated image recognition system would likely work to differentiate between people and their pets but would be relatively expensive.  In contrast, a relatively simple logic scheme using two PIR motion sensors looks like it could work.  They would be at two different heights -- one close to the ground and the other about 2-3 feet high.  If both are activated, something tall (like a human) just entered the space.  If only the bottom one is activated, it must be something smaller like a cat.  In that case, the logic circuit will activate a piezo tweeter that emits sound obnoxious to a cat.  This will teach the cat -- hopefully -- to stay away from that area.  If the frequency is above about 15KHz we won't hear it (not much anyway), but the cat definitely will.

PIR motion detectors usually have a fairly wide field of view.  So it may be necessary to place a tube around the top one to restrict its field of view so it won't trigger when a cat enters the area.

To test the idea out I ordered several PIR sensors, a couple of piezo tweeters and a 5V/12V wall-wart power supply from ebay.  The 12V supply will be used for the piezo driver circuit.  I have several Arduinos lying around so I will use one of them to perform the logic and output a high frequency signal to the piezo driver.  So far I have far less than the $$ charged for a commercial device, and it should work better.  Such a deal.  And if need be, I will have enough sensors and tweeters to protect another area.

Sunday, April 25, 2021

XRF update

 It's been some time since I posted -- for some reason, although Covid meant we spend much more time at home, I have remained busy.  But it's time for a quick update on my home-made XRF setup.

I started by finding some relatively inexpensive scintillator crystals that looked suitable for XRF, but got hung up on the detector side.  Photomultiplier tubes are fairly inexpensive but require well regulated high voltage, on the order of 1,000V.  They also are fairly bulky, a disadvantage if you want to perform XRF in the field.  A number of semiconductor manufacturers make something called silicon photomultipliers, commonly referred to as SiPM's.  They typically require something on the order of 30V to operate, much friendlier -- and they are much smaller than PMT's.  A 6x6mm SiPM on an evaluation board costs about $100.

However, I came across a thing called a pocket geiger radiation detector, sold by Sparkfun.  It uses a 10x10mm detector that by itself costs about $100 -- but they're selling it on a circuit board for only $69.95.  In its as-delivered condition it can't be used as the detector for XRF because the design uses comparators, which remove the pulse-height information needed.  However, the circuit board has some pads (possibly used for test purposes) that DO make the analog signal available.  So I bought a pocket geiger and started experimenting.  I used the 60Kev gamma rays from Americium (found in ionization type smoke detectors) as the radiation source, to excite XRF in a thin brass sheet.  I was hoping to see pulses of various heights coming out of the amplifier (from the mixture of copper and zinc that make up brass), and sure enough, I did.

While this result is encouraging, it's not quite enough.  To analyze ferrous metals the copper shield has to be removed, so the ~10Kev x-rays aren't absorbed.  But removing the shield results in a large 60Hz signal coming in from all the power lines.  The detector circuit has very high gain so this is an unavoidable problem with an unshielded detector.  So currently I'm making an aluminum box that will house the detector, and also serve as a shield to block 60Hz and those pesky 60Kev x-rays.  The box will have a partition with a hole in it to admit the x-rays emitted by the sample, and a removable end that, when installed, will fully shield the detector from all that power line noise.  The Americium disks will be placed around the hole so the detector will be shielded from them, but can "see" the fluorescence x-rays.  I have some 1/8" thick lead sheet that will line the interior of the box, just to make absolutely sure that I have no exposure to x-rays.


Then there is the software needed to process the pulses and assign their peak height to individual channels.  That information, in turn, will be used to determine what element(s) are present in the sample.  First things first though -- I need a robust test platform I can depend on before spending the effort on S/W. 

Sunday, June 28, 2020

XRF, a geek's homebrew dream

I recently learned about a really cool way to perform your own elemental analysis on a (relative) shoestring.  Traditional approaches to elemental analysis have taken a number of different paths, starting with chemistry.  Typically, analysis would involve dissolving the unknown(s) in an acid and then using various chemical reagents to determine the components.  Some compounds are insoluble in water, so adding a solution with something that will react and cause some to become insoluble could be the first step in figuring out what you've got.  Since there's a huge number of potential reactions (and possible confounding results), this approach requires a well-stocked chem lab and knowledge of many different reactions.  Not for the hobbyist.

Another approach is spectroscopy.  Based on the light emitted by excited elements, it's very powerful and sensitive.  But there is the problem of heating the sample to a high enough temperature to get it to emit -- and then having the ability to separate the light into its individual components.  This is more approachable because it's relatively easy to make or buy a visible-light spectrometer based on a diffraction grating (or blank DVD), plus a webcam to image the spectrum.  The difficulties are the necessity to make something to ionize your sample long enough to acquire a spectrum; and the need to break your sample down in to some form to feed into your home-brew ionization device. 

On the industrial side, you can buy analysis tools that look at the x-rays emitted by your sample.  One approach that I'm pretty familiar with is to hit your sample with high-energy electrons (accelerated to 30KV or thereabouts), and look at the x-rays it emits.  This requires an electron gun capable of accelerating your electrons.  The x-rays are characteristic of the element(s), so an x-ray spectrometer has to be used in order to distinguish them.  Two detection methods are used, EDX or WDX.  EDX is "energy dispersive x-ray" and WDX is "wavelength dispersive x-ray" analysis.  WDX is more straightforward, and uses a crystal lattice as a diffraction grating to produce a spectrum of the x-rays emitted.  The crystal is rotated to direct the diffracted x-rays into a detector, so it is fairly slow because it must rotated in order to scan through the x-ray spectrum.  In my experience, it also is less sensitive so scan times must be very slow in order to get decent signal to noise ratios.  The detectors used for these analysis tools use relatively exotic gasses like argon + methane in a flowing tube.

On the other hand, EDX is much more sensitive and faster, because it uses a special kind of photo-detector.  The detector outputs a pulse whose height is proportional to the energy of the incoming photon -- the shorter the x-ray wavelength, the more energy it has.  So it is a kind of single-photon detector, but the energy of each photon is categorized and then entered into a "channel" of a multi-channel analyzer.  So all detected photons are detected and characterized, which greatly increases the detection rate.  The downside is that the detector has some losses -- x-rays can enter the detector (a type of semiconductor diode) but they may not deposit ALL their energy -- so they don't produce a signal that is exactly related to their original energy (determined by their wavelength and Planck's constant).  These detectors also need to be operated at cryogenic temperatures, 77K (the temperature of liquid nitrogen) so they have to be inside a Dewar whenever they're are in use.  Attempting to operate them at room temperature will destroy them, a VERY expensive proposition.

All this stuff is way out of the range for hobbyists, unless they buy something used and have the ability to get it to work.  That could require a wide range of abilities, since these tools typically are attached to scanning electron microscopes.  Not impossible, but a pretty high bar for most.


Another approach is XRF.  It is a type of fluorescence, hence it's acronym -- "X Ray Fluorescence".  You probably are familiar with ultraviolet fluorescence, from "black light" bulbs or tubes.  When it occurs, the light emitted is characteristic of the materials involved.  XRF is similar, but uses higher-energy X-ray photons to excite fluorescence at somewhat longer energy x-ray wavelengths.  X=rays are emitted from inner-shell electrons so they are pretty much independent of the oxidation state of the elements -- so they are good for looking at individual elements.  This sounds pretty exotic, but it actually has some advantages -- particularly from a hobbyist's point of view.

What are some of these XRF advantages?  Well, for starters a lot of work for you as a DIY'er has already been done.  Just Google "Theremino XRF" and you will see what I mean.  It's not too expensive to buy scintillator crystals and photomultiplier tubes (and power supplies) from ebay to come up with something that can tell you (for instance) if the paint flakes you've got have lead in them or not.  And it can be done with an x-ray source made from a few dead smoke detectors!  Since this approach is all open-source based, you can take it as far as you want.  Caveat:  yep, you do need to have some experience with roll-your-own electronics, but it's not that high a lift.

Just to add to the attraction, the same setup can be used to look at materials to see if they're radioactive and provide some guidance on what the radionuclides might be.  Not important, you say?  well, Strontium-90 is a common contaminant from Nuke-reactor failures (think Fukushima, and apologies if I got the spelling wrong); and our bodies can't tell the difference between strontium and calcium.  Living on the west coast, we've wondered just how much SR-90 we got from that, but authorities here have not been very helpful to resolve that concern, possibly due to economic issues.  Yes, radioactive cesium also can be detected too.

Sunday, December 29, 2019

Slow Cooker Sous Vide Modification, Learnings

I haven't used our modified slow cooker because I wanted to make sure it had a fail-safe over-temp cutoff system first.  I found some cheap thermal cutoff switches for microwave ovens and bought one that was rated for 120C (from ebay).  I inserted it in series with the heater connection and bolted it to the bottom of the heating unit, which is an aluminum basin that holds the crock pot.  I fired everything up and it went well -- until the thermal switch opened up.  And it stayed open.  Apparently this style of over-temp protection is like a fuse -- once it opens up, it's done.

Rather than buy something with a slightly higher cutoff temperature (and possibly have the same problem), I decided to actually do it more scientifically (about time, eh?).  I have a thermocouple-based thermometer I bought from Harbor Freight awhile back, tested with ice water and boiling water so I know those two points are fairly accurate.  I left the thermal cutoff switch in place, just loosening one of the attachment screws enough to slip the thermocouple underneath it, retightened, and rewired the heater so it was operating in its "dangerous" mode.

I filled the crock with hot (50C) water and set the temperature controller set point to 78C, which should produce 160F in the crock (based on previous characterization work I did on the system).  Before the water got even close to 78C the thermocouple was indicating over 150C!  No wonder the thermal cutoff opened up.

Some investigation revealed some clues as to why the crock and over-temp sensor location were so different, temp-wise.  I loosely crumpled up some aluminum foil into a ball and put it in the bottom of the heater, then dropped the crock in there.  Pulling it back out, I saw the foil ball had been compressed into a "puck" that was almost 1 inch thick!  That means there is a _really_ poor thermal connection between the heater and crock.  This result is not inconsistent with what I initially observed, and which prompted me to move the temp controller's temp sensor into the crock itself, rather than controlling the temperature of the surrounding aluminum bowl.

Just for fun, I replaced that aluminum-foil "puck" in the heater bowl directly above the thermocouple location, put the crock back in, re-filled it with hot water, and re-did the heating experiment.  This time the heater didn't quite make it to 120C by the time the crock got to 78C.  Success!  And, I also noted that this temperature difference was worst-case -- as the setup continued to operate, the temperature difference between the crock pot and heater became much smaller.

I might declare victory here, but the downside is that it takes quite awhile for the crock pot to heat up to the set temperature.  Improving that is problematic, unless I'm willing to do a much-more intensive modification of the slow cooker.  I'm thinking about putting something like plaster of paris or the like, in the heater and dropping the (greased) crock in there.  After the plaster cures, the crock can be pulled out for cleaning/washing, but it will have a much better thermal connection between the heater and crock.  Plaster of paris isn't the most robust thing in the world though, and it will make the whole thing heavier.  I'll have to try the new setup (with a new resettable thermal cutout switch I found) to see if it's usable or not.  A mix of Portland cement with fine-grain sand would be a lot stronger.  Not going there yet!!!

One way to reduce the time to get to operating temperature would be to fill the crock with water that is close to the operating temperature.  This is an easy way to address a number of these issues.

Monday, December 2, 2019

DIY Spectrometer and CBD/THC analysis: Results

In an earlier, lengthy post I described my spectrometer build and showed the spectrum from a CFL lamp.  Since then, I have continued with experiments to see if the dye (Fast Blue B) could be used to produce more quantitative data on CBD and THC content.

My executive summary:  the color shift between CBD and THC is too subtle to use as an analytical tool.

Below, I show two spectrograms -- taken with extracts from two different marijuana clones.  One contains less than 1% THC and one contains no CBD, as determined by my wet chemical analysis (a 5% sodium hydroxide solution in ethyl alcohol turns blue if CBD is present).  The differences are very subtle, making it very difficult to distinguish between the two.

So in conclusion, I made a fairly nice spectrometer I can use for other things, but my primary goal -- being able to determine the relative amounts of CBD and THC in plant material -- was not achieved using this approach.



Wednesday, November 6, 2019

Kitchenaid Slow Cooker Sous Vide Modification

******************************************************************************
NOTE:  If anyone reading this post is inspired to try something similar, you MUST be aware of potential hazards associated with DIY modifications that use 110VAC (household AC) and temperature controllers that could cause a fire hazard.  This hazard could be the result of your system or temp controller being improperly configured, improperly wired or used in an inappropriate manner.  What I describe below is for educational purposes only, and anyone building something based on this post is fully responsible for ensuring that it meets local electrical codes, and being aware of its potential for electrocution or fire.  Also, see the last paragraph in this post for more details on potential failure modes.

*********************************************************************************

So we had this highly-rated slow cooker that we were using for making CBD-infused coconut oil for salves.  Besides CBD, cannabis plants contain a number of other beneficial compounds called Terpenes.  They are somewhat volatile so it is important to keep the processing temperature as low as possible.  Some terpenes you might recognize are turpentine (not so pleasant for topical use), lemon oil, orange oil and a number of similar terpenes that find use in cooking or medical applications

Unfortunately, the slow cooker's temperature controller went crazy and would heat the contents of the slow cooker to the boiling point regardless of the temperature setting.  This particular cooker had 4 settings -- Keep Warm, Low, Medium and High.  It became no good on any of them.  So what to do?  Well, I so happened to have an STC-1000 temperature controller on hand.  I originally got it to make a temperature controlled cabinet for making my own cured sausages and meats.  It turns out that our basement is the right temperature anyway so the controller wasn't needed.

I took the slow cooker apart and found the heater connections, then cobbled something together to see how the controller would work to maintain the right temperature.  At first, I went with a fancy spring-loaded temperature sensor that pressed against the bottom of the slow cooker crock, but the thermal path from the heater to the sensor was too good, so the contents of the crock didn't get anywhere close to the set point.  I found it was necessary to immerse the sensor in the crock itself.  For making CBD extract (or sous vide) this isn't a problem, because in both cases the "product" is in a jar or bag so the water in the crock doesn't come in contact with the stuff we're cooking up.

The in-the-crock temperature sensor worked just fine so I proceeded to make a more robust setup.  I bought a plastic enclosure and a pair of male/female DB9 connectors, then machined holes in the enclosure to accommodate the controller and connector.  I also had to do some creative machining (and carving) for the power cord's strain relief.  Unfortunately, the strain relief wasn't quite the right size for the power cord so it wasn't properly captured by the strain relief.  To address this, I did two things:  I squirted a good dollop of silicon caulk into the strain relief to glue the cord in place, and I also put a tie-wrap around the cord on the inside of the enclosure, right next to the strain relief.

Today I had an opportunity to check the whole thing out.  As in situations where 110VAC is present, there's a chance that sparks and smoke (or flames!) could come out of the box, but all went well.  Here's a photo of the setup working to maintain about 160F in the crock:


One thing I didn't realize about the STC-1000 is that it ONLY supports degrees Centigrade, not Fahrenheit so now it is a METRIC slow cooker  :)

CAVEATS

The STC-1000 will go into an error state and shut down if it loses connection to its temp sensor so that is one failsafe.  However, if the sensor isn't put into the crock, or if it inadvertently comes out of the crock, the controller won't know that and will keep on heating until the water boils.  This isn't too bad (yet): but once the water boils away it will continue to heat up and could become a fire hazard.  Therefore, as it's currently configured it is NOT ready for unattended use.  The controller itself could also fail so that's a potential issue as well.  To address the over-temp problem I will buy a thermal-cutout switch that will be wired in series with the heater (and installed into the slow cooker) so it will interrupt the power if the temperature rises too much. This kind of secondary fault protection based on a mechanical thermostat (instead of electronic) is commonly found in laboratory ovens, and I thoroughly approve of this kind of protection.  Don't make or use one of these modified slow cookers unless you include a thermal cutout switch!!!

Thursday, July 11, 2019

Troubleshooting wireless sensors

Over the years we have acquired a number of wireless sensors -- remote temperature sensors and motion detectors.  All of the ones that have failed spent time outside, something they (according to the manufacturers) should be able to handle.  While most seem to have failed due to moisture related problems, one of the motion sensors was colonized by ants.  It started sending out signals almost continuously because the ants were crawling across the surface of the sensor.  After cleaning out the ants and their nesting crud, the sensor stopped working -- sort of.

All these sensors SHOULD have been working, because the red or blue LED "transmit" lights would flash -- but their receivers weren't picking anything up.  One of the sensors appeared to have a greatly-reduced transmit range.  So what was going on?

Awhile back I bought a cheap SDR -- a software defined radio -- to play with.  It is an RTL-SDR, basically a USB dongle with an antenna and can receive RF from 500KHz to 1.7GHz.  I got it to use as an ultra-cheap spectrum analyzer, but it's very slow when used for that purpose.  This is mainly due to the design's relatively narrow RX bandwith (about 1MHz).  However, there's a simple application for it that can be used to troubleshoot wireless sensors.  It's called "rtl_433", and was written to listen to and decode wireless sensors.   Another handy utility is "gqrx", which has a RF spectrum display and a waterfall display.  A waterfall display shows the intensity of received signals over time -- the horizontal axis is frequency, and the vertical axis is the intensity over time (about 30 seconds are shown).  This is handy for pinpointing periodically-sent signals, like the type generated by wireless sensors.


The above shows the output of gqrx.  The small vertical red stripe in the waterfall portion is a burst of RF data sent by a wireless sensor.  In this case it's an Acurite temperature sensor.

The waterfall display shows this wireless sensor is transmitting close to the specification, which is 433.920MHz.  But the bad wireless sensors were all transmitting at significantly different frequencies:


-In this case, about 432.58MHz.

This is where the other utility, "rtl_433" comes in handy.  You can specify the frequency it listens to by calling it this way:  "rtl_433 -f 432580000" (the frequency parameter is passed in Hz).  I was able to get data from some sensors, but not all of them, by doing this.  BTW, rtl_433 should be called from the command line so it is NOT a graphically-oriented application.  I'm using Linux at home so I'm accustomed to using command line programs in a terminal window.

The sensors that were sending data (just at the wrong frequency) mostly likely had a frequency shift due to "crud" buildup under or around the transmitter components.  To test this, I soaked one in very hot water after opening the case up (and removing the batteries).  To help the circuit board dry faster I rinsed the board with isopropyl alcohol, then left the board to dry in the sun for a few hours.  I reassembled everything and checked the transmit frequency -- right back to where it should be.  After resetting the receiver unit, it started picking up the sensor.  Success!

Now I need to figure out why the other units aren't sending data, despite having a functioning transmitter.  That may be a more serious problem, but one clue is that the amplitude of the transmitted signal is quite a bit lower compared to a good unit.  I suspect the RF is not being modulated, perhaps due to more-robust "crud" on the circuit board.  Time to look at the board more carefully.....