Project Overview
This circuit allows users to control a light by clapping their hands. Three claps turn the light on and off and two claps toggle the color of the light between a cool, bright color and a warm, slightly dimmer color.
The design of the circuit allows for customizability. Certain components can be adjusted to tune the clap detector to different frequencies, and the circuit could be changed to control different kinds of lights.
As a general overview of function, this device takes an analog signal from a microphone, filters it for frequencies corresponding to claps, and compares the filtered signal with an unfiltered signal. When the filtered signal is large enough compared to the unfiltered signal, meaning a substantial proportion of the sound detected is of a certain frequency, a digital pulse is output. This digital signal is then used in a binary counter. A series of flip-flops and logic gates then control the light based on the number of digital pulses (claps) that are stored in the counter. A reset timer synchronizes the updating of the light and ensures claps are within about 1.6 seconds of each other to properly control the device.
Step-by-Step Instructions
The first step is to make a microphone that can detect sound in your environment. The diagram included here shows how. The capacitor removes the DC offset that exists in the microphone portion of the circuit. This AC signal is then fed into an inverting amplifier with a gain of about 5000. The output of the amplifier will then be split into an unfiltered signal and a filtered signal that can later be compared. This step (and the subsequent steps that divide the signal, filter it, and compare them) is heavily based on work done by Yuelin Kuang. You can view the project here: https://makerspace.cc/A_Sound_(Frequency)_Detection_Circuit_(Project_0038).
Now make a full-wave rectifier and averager. The two op-amps used in this diagram are LF411 op-amps with +/- 15V rail voltage supply. This full-wave rectifier essentially outputs the absolute value of our AC signal, an important first step in producing a digital output. It is important that the exact resistance and capacitance values listed here are used, it ensures that the correct amplitude of the signal is output. If you are curious to learn more about how this rectifier works, Yuelin Kuang’s project includes more detail: https://makerspace.cc/A_Sound_(Frequency)_Detection_Circuit_(Project_0038).
The last part of this block (two 10 kΩ resistors and one 1 μF capacitor) is an averager. It is important that this comes after the rectifier, as an unrectified signal will just average to zero. As the signal passes through this part of the circuit, the capacitor will charge and discharge as the signal oscillates, smoothing out the signal, especially in areas of dramatic change. The chosen values of the resistors and capacitors have a time constant of 1 ms. This smooths out our signal just enough to remove large fluctuations in background noise, but isn’t so large that it will average over the sound of a clap.
You will need to build two of these blocks. For one of them you can connect the input terminal directly to the output of our microphone amplifier. This will be our unfiltered signal. The other one won’t be connected to an input quite yet. So you can either build it now or wait until later.
Now we need to make an RC high pass filter. This will allow us to filter our signal for high frequencies. I use C_F = 2000 pF and R_F = 10 MΩ. The roll-off point for this filter is only about 8 Hz, which is extremely low. In theory, this would let essentially all sound frequencies through. Originally, I used filters designed to roll off around 2200 Hz. These, however, did not work. It is important to remember that stray capacitance in the circuit can dramatically impact how frequencies are transmitted, and the op-amps also have filtering effects. Be ready to change the capacitance and resistance values here until you find a value that responds well to your claps. I used resistance and capacitance switch boxes to easily explore different values as I tested the filter. This testing will be easier to do once the analog clap detector is complete and the indicator light is installed to show what is being detected. Use these values for now.
Alternatively, if you want to be extra precise you could make a bandpass filter: https://makerspace.cc/A_Sound_(Frequency)_Detection_Circuit_(Project_0038).
If you didn’t already, make an additional full-wave rectifier and averager as shown in step 2. Connect the output from the filter in step 3 to the input of this block.
Make a voltage divider as shown in the image. This voltage divider sets the minimum proportion of the unfiltered signal that the filtered signal has to reach in order for a clap to be registered. I use values of R_D1 = 100 kΩ and R_D2 = 30 kΩ. This sets my threshold at about 0.23. This is another instance where you may want to experiment with different resistance values. Depending on the efficacy of your filter, this is another area you can adjust values to tune your clap detector.
Connect the unfiltered signal (from the first full-wave rectifier) to the terminal of the left. The output of this voltage divider (on the right) will connect to our comparator and digital rectifier in the next step.
This next step is the most complicated. We need to make a comparator that can compare our filtered and unfiltered signals and output a clean digital pulse when a clap is detected. One difficulty with this step is that in a quiet environment, background noise has a wide range of frequencies, meaning that a clap can be falsely detected in a quiet environment when we connect our signals directly to a comparator. Instead, we route these signals into an op-amp first. Connect these components as shown in the diagram. Note that this op-amp needs to be on 0V and 5V rail voltages. At these voltages, the op-amp does not perform well for its typical functions. However, a result that I stumbled across is that this dramatically reduces instances of false detection in low volume environments. The op-amp holds a high output, and not only compares the intensity of signals to switch to outputting low, but also requires these signals to be loud enough, eliminating the background complications we’d otherwise see.
As a side effect, however, the op-amp outputs 4V high and 1.6V low. To get this to a digital signal, we then use an actual comparator. The minus input terminal is set to 2.5V with a simple voltage divider. This rectifies the signal from the op-amp to output 0V and 5V. Note that the "emitter pin” of the LM311 comparator must also be grounded, and the “collector pin” is used as the output.
The last step in this block is a 555 timer that helps smooth out our signal. This is a single shot 555 timer. It holds output low until the signal from the comparator drops when a clap is detected. This causes the timer to output a high signal for approximately 100 ms, before dropping down again. This helps to “debounce” a noisy signal. In this circuit, I observed claps to be a pulse with a width of about 100 ms. This prevents one clap from being counted multiple times and inverts our signal, giving us a clean output that swings high when a clap is detected. Also notice the LED connected to the output that lights up when a clap is detected. This serves as the clap detection indicator.
Datasheets for the IC's can be found online. The 555-timer is drawn using exact terminals of the LM555 IC, as it dramatically simplifies the diagram. The op-amp and comparator our drawn using typical symbols, not IC diagrams.
Now we move on to processing our digital signal that is output from the last step. In this step, we build a simple binary counter. This is done using two JK flip flops, which can be used on a single 74HCT107 JK Flip-Flop IC. Connect the digital output from the last step to the input terminal on the left side. Oftentimes when using flip flops, we automatically connect the CLR pins to high voltage because they are active low, and we don't want them to constantly reset. Don't do this. We want to control the reset of our binary counter. We will connect the reset terminal labeled in this diagram to the next step.
Build the reset timer exactly as shown. Connect the input on the left side to the digital output from the clap detector in step 6. When a clap is detected, the JK flip flop will set Q to high. Q is connected to the reset pin on the 555 timer. When it goes high, the 555 timer is activated. The time in the timer is set by the value of the resistors and capacitors in the diagram, so use these exact values. Wire the output of the timer to the clock on the second JK flip flop. When the timer expires and the output drops low, this flip flop serves as a synchronizer, simultaneously resetting all of the flipflops and stopping the timer from running another cycle.
The final output of this block is a signal that swings high when the first clap is detected, and drops low after 1.6 seconds. Now connect this output to the reset terminal shown in the last step. When the first clap is detected, the reset pins on the binary counter will now be held high, allowing them to count claps for 1.6 seconds before they are force-reset This requires that claps are in a tight sequence.
If you are looking for ways to simplify this project, you could try using a single shot 555 timer as used earlier. Whatever you do, you'll have to make sure that the signal drops from high to low at the end of the timer to make sure the binary counter is properly reset.
Now we use logic gates and flip flops to interpret signals from the binary counter to control the light. Build the circuit shown in the figure, connecting the Q_0 and Q_1 outputs from the binary counter to an AND gate on the 74HCT08 AND Gate IC. Use a 74HCT107 JK Flip-Flop IC to make two D flip flops by wiring all of the J and K inputs to high voltage.
The clock of one of these flip flops will be connected to the output of the AND gate and the other to only Q_1. When 3 claps are counted, the output of the and gate will be high. When the reset timer resets both bits to zero, the AND gate will drop to zero too, causing the top JK flip flop to toggle. When there are only two claps, only Q_1 will reset from high to low, toggling only the second flip flop.
This gives us toggle control over two different flip flops with either 2 or 3 claps. The top flip flop, controlled by 3 claps, controls on and off for the light. When it is high, no current can flow through the RGB LEDs, and the light is off. When it toggles low, current can flow, turning the light on. The second flip flop does something similar, but adjusts the base voltage on a transistor to be high or low. When high, the transistor shorts out the 10 kΩ resistor, producing a bright, cool color light. When off, the decreased current through the LEDs results in a slightly dimmer, warm color light.