Lightning Sensor

Over the last year or so I’ve been working on a lightning sensor system for my weather station. I originally found a circuit published by Charles Wenzel that I thought looked interesting, and I decided to give it a try. The circuit worked quite well. So well, in fact, that it picked up lights turning on and off around the house. It also goes wild when the stove-top in the kitchen is used. I guess the stove has a noisy PWM circuit or something. I made a PCB for the circuit, and integrated it into my weather station and have let it run for a few months now.

Weather Station Data
10 Days of Weather Data

As the summer draws near a flaw in this design has presented itself. The flaw is severe temperature instability. Hotter temperatures increase the sensitivity of the system, and on hot days the thermal noise of the circuit causes a significant amounts of false triggers. This will be addressed in an upcoming design change in an attempt to reduce the number of false triggers.

The event on May 4th was an actual lightning storm and strikes were observed by persons in the area. Note the large drop in barometric pressure preceding the rise in lightning strike counts.

Ultrasonic Anemometer Part 5 – Initial Bench Testing

I received my first printed circuit board for the ultrasonic anemometer. After soldering all the parts together I began some testing to see how the design worked. There were some very successful parts, and some things that will need to be adjusted.

Ultrasonic Anemometer
First prototype powered up

The amplifier stage seems to work pretty well. However, because I forgot to order one of the capacitor values in the band-pass stage, the center frequency wasn’t right on. That, however, was not a problem with the design, but rather the designer. Oops!

The main issue with the design was not something I expected to be a problem, but in hindsight is something I should have considered more carefully. The problem lies in the 3.3V supply rail. When the micro-controller drives one of the transducers there is quite a bit of noise on the 3.3V supply rail.

Noise on the 3.3V rail
Noise on the 3.3V rail

Because everything (including the amplifier circuits) are connected to that supply the noise appears on the received signal as well. I think the best solution here is to isolate the sensitive analog stages from the digital supply. This will take a separate power supply. This is a downside because it will add components and cost, but I think the expense is warranted and will result in better performance. I also added a capacitor in the mid-supply generation circuit to help keep the bias point closer to the midway point between the two rails for the analog circuitry.

I also decided to increase the gain of both stages of the amplifier. I must have underestimated the gain requirement of the system because the output is too low at present.

While I wait for the modified circuit boards to arrive I’ll spend some time using what I have now to begin working on coding the firmware. Although the current design has some problems, there is nothing that would prevent me from getting 90% of the code finished before the new boards arrive. I’ll start to cover the C code in the next part of this series.

 

Ultrasonic Anemometer Part 4 – Envelope Detector

The envelope detector circuit will be used to detect the amplitude of the signal coming from the amplifier. The output will be fed into an analog input on the micro-controller. Here is the initial schematic that I’ll be using for this portion of the design:

Envelope Detector Circuit
Envelope Detector Circuit

The first two elements (C15 and R14) form a high-pass filter (Fc = 339 Hz) and also bias the op-amp to ground. U3D drives D6 and C16 which form a simple peak detector. The output of this peak detector is low-pass filtered by R18 and C17 to smooth the output. U3C provides adjustable amplification if needed, and buffers the output. R21 and C18 will provide a final low-pass filter to reduce any noise in the signal before it enters the microcontroller.

Now would be a good time to tell you about a little trick I’m holding up my sleeve. Often overlooked, the built-in analog comparator in many micro-controllers will be very useful in this design. I plan on using it to perform the entire function of the zero-cross detector, by way of feeding the output from the amplifier directly into a analog input to the micro-controller. I also plan on using this built-in comparator to perform the threshold detection of the envelope input which will be fed into a separate analog input. The microcontroller has a built-in multiplexer that can select the appropriate signal quickly, and perform the comparison. This comparison can also trigger an interrupt for precise time measurement. This will eliminate the need for external parts, thereby reducing cost and size, and should give the processor even more control and flexibility.

I’ve sent the PCBs off for manufacturing and next time we’ll look at results of these initial designs and see how they work.

Ultrasonic Anemometer Part 3 – Amplifier

Now that we’ve made some initial design choices about how the signals will be routed in the design, it’s time to start nailing down some of the finer details. But first, before getting into too much detail about the receiver design, let’s take a moment to survey the signals that we intend to receive using an oscilloscope:

Ultrasonic Anemometer Waveform 40kHz
Test waveform recorded using test setup

We can see both the transmitted and received signals using the simple test setup shown in the photograph below. In the final design the transducers will be much farther apart in order to minimize airflow disturbance.

40kHz ultrasonic transducers in a desktop vise.
Test Setup – Two transducers in bench vise

The received signal will be much weaker in the final design due to the increased spacing between transducers. Amplification will obviously be necessary. This leads us to the design of the first stage of the receiver.

The Amplifier

The incoming signal from the transducer will need to be amplified to account for the losses incurred during the waves journey through the air as well as the losses incurred in the transducers and multiplexer. Based on some rough oscilloscope measurements, we will need around 35dB of gain to amplify the 50mV signal that will reach the amplifier to get a 3V signal that we can then send on to the two processing stages. In order to make the circuit more immune to self-oscillation and to increase flexibility I will split the amplifier into two stages.

For the initial amplifier stage I have chosen to use a multi-feedback (MFB) band-pass topology. This topology will use an op-amp to both amplify and filter the incoming signal.  The gain of the first stage will be fixed at around 20dB. I’d like to have a Q of approximately 5. This is a trade-off between amplifier ringing and filtering ability. The transducers themselves have inherent filtering ability since they are tuned, thus, anything above 5 does not seem necessary at this point.

Amplifier Schematic
2-Stage Bandpass Amplifier Schematic

For the second stage I have chosen a basic inverting topology, whose gain could be easily adjustable by changing a resistor or using a potentiometer. I have drawn the second stage with about 20dB of gain. This will likely be adjusted later, but should be close enough for now. If the system ends up being too sensitive simply varying the output drive a few Hertz away from the resonant point will reduce the sensitivity without the need for any adjustments to the circuit. The output drive frequency is very easily modified in micro-controller firmware, and may end up as part of a calibration/initialization routine in the future.

Amplifier SPICE Simulation
Amplifier SPICE Simulation

It’s not yet clear to me weather or not separate bias circuits will be necessary, so I’ve included two at this point. The SPICE simulation doesn’t seems to show any adverse affects, but because there is a signal path to the bias circuit in the first stage, I’ve chosen to have another isolated bias circuit in the second stage just to be sure. I’ll find out later if this was over-kill (a colleague and I have a running joke that ‘over-kill’ is often ‘just-the-right-amount-of-kill’). The SPICE simulation shows results as expected, with just under 40dB of total system gain, and a nice peak at around 40kHz.

With a solid design in place for the amplifier I will move on to the envelope detector design process.

 

Ultrasonic Anemometer Part 2 – Signal Path

Since we’ve established the methodology behind how we will approach making these wind speed measurements, it’s time to begin the design. The design of this system was inspired by several other individuals who have also designed and built their own ultrasonic anemometers. Here you will find their own reports documenting their efforts:

The Signal Path

The first thing I chose to tackle was designing the overall flow of signals. Because the design has four transducers I needed either four transmitters and receivers, or, a way to select the appropriate signals and route them to one transmitter and receiver. In order to minimize cost and size I chose to build one receiver and transmitter and use a multiplexer to route the signals to the correct destination.

Ultrasonic Anemometer
Signal path for ultrasonic anemometer

The transmitter in this case is simple. I determined that the impedance of the transducers was approximately 680 Ohms at 40kHz. This allows me to drive them directly from a pin of the micro-controller at either 3.3 or 5 volts without cause for concern since most micro-controllers can source and sink around 20mA, or more. Additionally, the multiplexer will have some resistance, which should also protect the micro-controller. Because the transducers are tuned circuit driving them with a square wave directly from the micro-controller seems like it should be acceptable at this point. The transducer will filter out most of the harmonics in the square wave. I will re-evaluate this later in the design process.

Side note: In order to determine the impedance of the ultrasonic transducer I connected a variable resistor in series with the transducer. I then applied a voltage with a signal generator set to 40kHz. Next, I adjusted the variable resistor until the voltage amplitude was equal across the resistor and the transducer. At that point the impedance of the resistor and transducer were equal. Using a simple multi-meter I measured the DC resistance of the variable resistor which yielded a result of 680 Ohms. While this doesn’t provide the whole story regarding the impedance of the transducer, it does give enough information to move forward with the initial design. Plus, it’s very quick and easy to do with only basic equipment.

Designing the receiver in this system was the most difficult part of the hardware design process. I will start to cover that process in the next entry in this series.