|
Not too long ago my brother came to me with an idea for a project. He plays bass guitar in a band, and uses a fan for visual effect and to stay cool while performing. His idea was to use a guitar wah pedal to control the speed of the fan. I looked at the inside of the guitar pedal to see what the mechanism was for controlling the audio signal. It was pretty simple. There was a gear rack which moved along with the pedal. This drove a gear which was attached to the shaft of a potentiometer which was fixed inside the pedal. I had the idea that I could route the power from the fan to the guitar pedal, but instead of going through the potentiometer, I could go through a rotary wall dimmer. Thus the pedal could control the setting of the dimmer, and hence the power delivered to the fan. The fan being used was a Lasko U12100 blower fan. I opened it up to see how it worked. The wiring was pretty simple. There was a four wire switch, one of which was connected to 120V wall power, the other three of which ran directly into the fan motor. The switch allowed choosing between one of three fan speeds and OFF. The voltage delivered to each of the three wires running into the fan motor was identical, so the control for the motor speed was done inside the motor, probably by shifting the phase of power delivery, similar to how a wall dimmer works. I wanted to leave the function of the fan intact, in case my brother ever didn't want to use the guitar pedal to control fan speed, so I next did two things:
Contents: Initial Attempt Revised Plan Components Microcontroller Relay Potentiometer Connections Schematic Circuit Operation Code On the guitar pedal side, I then connected the hot lead of the wall dimmer to one lead of a male wall plug, and the neutral lead to the other plug lead. In this way, I could run an extension cord from the fan to the dimmer and control the speed of the fan. Things seemed to be working great. I was able to control the speed of the fan with very good precision through the wall dimmer. In addition, I could toggle to operate the fan without running to the dimmer at all. It was at this point, however, that things began to become problematic. First of all, the dimmer was larger than the potentiometer that was originally in the guitar pedal, so that the bottom cover of the pedal wouldn't quite fit on top of it. This seemed like a minor problem, since I could simply add some spacers to create some space between the pedal and the bottom cover, allowing room for the dimmer. Secondly, and more problematic, was that the position of the shaft of the dimmer was significantly different than the position of the shaft of the original potentiometer. Thus the mechanism of driving the dimmer from the gear rack would need to be altered. This was something which I was not comfortable in tackling, so I solicited the assistance of my father, who is very adept at mechanical things. He was able to mount the dimmer, and adjust the mechanism of driving it from the gear rack, and things worked pretty well.
However, at this point, another couple problems presented themselves. First, the dimmer would only deliver 100% power when it was rotated completely in one direction. Anything less than resting completely against one of its stops would result in noticeably less than full fan speed. And in fact, I am not sure that the fan was completely at full speed even when the dimmer shaft was completely turned in one direction. This problem became magnified when coupled with the fact that when driving the shaft from the gear rack, it was very difficult to allow the dimmer shaft to completely turn in this direction without putting significant strain on it when the guitar pedal was depressed. The second problem was that when the dimmer shaft was rotated in the other direction, below a certain setting the fan would stop turning. This result was predictable, and not necessarily undesirable, as I had wished for the fan to be able to turn completely off using the guitar pedal. However, before the dimmer clicked completely off, there was a range in which the fan wouldn't be turning, but there was an audible hum coming from its motor. I feared over time this may damage the motor.
I decided to scrap the idea of using the wall dimmer and start over. I knew that the pedal would work fine to control a potentiometer, as this was its initial configuration, so I decided to use this potentiometer, coupled with a solid state relay and a microcontroller to control the fan speed. I could use a simple voltage divider along with the potentiometer to measure the position of the guitar pedal. Depending on the position of the pedal, I could use pulse width modulation through the relay to control the fan speed. This would solve all of the problems I was having earlier. First, no spacers would be needed to allow room for the wall dimmer, as the potentiometer which was originally used fit comfortably. Second, the shaft of the potentiometer wouldn't need to be rotated completely in one direction. I could just choose a position which was close to completely rotated, and call that 100%. Third, and similar to second, I could choose a position at which the fan was at a very low speed, and cut power to it below this position. These second two things would be possible because I was now using a microcontroller rather than a mechanical dimmer to control fan speed. For the microcontroller I chose to use an ATMEGA328P with optiboot from SparkFun Electronics because I had an Arduino R3 Uno from a previous project which uses the same microcontroller. Thus I could program this chip by simply swapping it out in the Arduino and uploading code from my computer. For anyone interested, I originally used tried the ATMEGA328 without optiboot, figuring I could load the bootloader onto it. I fought with this for a very long time with no luck. When the new chip came with optiboot, it worked like a charm. I highly recommend the chip with the bootloader preinstalled. I used a 16MHz external crystal as an external clock. For the solid state relay I chose the 8A version, also from SparkFun, as the current drawn by the fan measured at less than an Amp during operation, with a peak of about 1.5A at start up. For anyone choosing to control one of these relays from a microcontroller, be advised that it is necessary to place a current limiting resistor between the microcontroller and the control pin of the relay. When the microcontroller is part of a board like the Arduino, I don't think this resistor is necessary because the Arduino will limit the current going into the relay. However, when the microcontroller stands alone on a breadboard or printed circuit board, there is nothing to limit the current. The unlimited current flowing into the relay can be plenty to fry its internal LED.
For the potentiometer I used the original one that came with the guitar pedal. It is a 470kΩ logarithmic potentiometer. I measured resistances ranging from about 30kΩ to 490kΩ. I wanted the fan speed to vary linearly with pedal position, rather than logarithmically, so I connected the potentiometer on the lower half of a voltage divider (i.e. between Vout and ground). For the top half of the voltage divider I used 122kΩ resistance by connecting a 100kΩ resistor in series with a 22kΩ resistor. I chose 122kΩ as the value for this as it would represent near the geometric mean of the extreme resistances of the potentiometer, and give a near linear output as the potentiometer resistance varied logarithmically.
It then occurred to me that in my current configuration, I would need two cords to run to the guitar pedal. One would run from the fan, the other would run from a 120V power source to supply the 9V power transformer. However, I already had 120V input coming from the fan. If I ran a 3 prong extension cord from the fan, I could carry a neutral line, along with the 120V source and the return. This would eliminate the need for two cords to be plugged into the pedal. I tapped into the neutral line from the fan and ran it to what would have been the hot lead in the plug. I attached the hot wire from the fan to what would have been the ground lead in the plug, and attached the return wire from the fan to what would have been neutral in the plug. On the pedal side, I split the hot lead to run to both the relay and to the hot connector on the transformer. I ran the neutral lead to the neutral connector on the transformer, and the return lead to the other terminal on the relay. I chose this configuration because I wanted to ensure that if the pedal were accidentally plugged directly into a wall socket, both inputs to the relay would be grounded, thus avoiding a short and potentially blowing up the relay. Power to the entire system comes from wall power which runs into the fan. The positive lead runs into a toggle switch. In one position, power is supplied through a 3-way switch and into the fan motor. This is the normal operation of the fan. In the other position, the toggle switch sends power to a female plug which was mounted on the fan. A line for neutral and for return from the guitar pedal are also run into the female plug. This plug can then connect to an extension cord to a male plug which is mounted on the guitar pedal. From the male plug on the guitar pedal, the neutral lead is connected to one input to the 9V DC power supply. The hot lead is split two ways. One lead runs to the other input of the power supply, while the other lead runs into one of the AC terminals of the solid state relay. The power supply then powers a fixed 5V voltage regulator, which powers the rest of the system. The 5V power supplied by the regulator then runs through a simple voltage divider. First it runs through a 100kΩ and a 22kΩ resistor, then through the potentiometer which is controlled by the guitar pedal. The resistance of the potentiometer varies logarithmically from about 30kΩ to 490kΩ. This supplies from about 1V to 4V to Analog Input pin A0 on the microcontroller, which varies approximately linearly with the pedal position. Power is connected to the microcontroller via pins 7 and 21. In addition, pin 20 is connected to 5V as a reference to measure the analog input which is supplied to pin A0. Also, the Reset pin (pin 1) is connected to 5V through a 10kΩ resistor. This prevents the board from accidentally resetting during normal operation. Pins 8 and 22 are connected to ground. A 16MHz crystal is connected between pins 9 and 10 on the microcontroller. This supplies an external clock. Each of these pins is connected through a 22pF capacitor to ground to minimize noise.
Pin 14 of the microcontroller (Digital 7) runs through a 220Ω current limiting resistor to control the solid state relay. When turned on, the relay allows current to flow back to the fan, which can then run through the 3-way switch inside the fan and supply power to the fan motor. The microcontroller uses pulse-width modulation to control the speed of the fan. I somewhat arbitrarily chose 10 cycles to be the switching frequency, which at 60Hz corresponds to 1/6 of a second. Because the fan carries momentum when the power to it is cut, this is plenty often to maintain a constant speed. The code to control the relay and hence power delivered to the fan is extremely simple. First, voltage is read from analog input to the microcontroller. This corresponds to the pedal position. Voltages range from about 1.2V to 3.9V. The microcontroller reads values from 0 to 1023, so 1.2V to 3.9V corresponds to input values from about 246 to 798. I chose to have these represent 105% and 25% duty cycle respectively. Six times per second, values are measured. For anything over 100%, the relay is turned on, resulting in 100% power being delivered to the fan. For anything under 30%, the relay is turned off, resulting in the fan turning off. For anything in between, the fan is turned on for the corresponding fraction of 1/6 of a second, and turned off for the remainder. Here is a copy of the code:
#include <Arduino.h> |