This is a method of using the square pulse output of a Memsic dual-axis accelerometer to control a servo. However, unlike other methods that use a microcontroller device, I'll show you how to directly tap into the control pin of a 555 timer chip to adjust its pulse length and turn the servo horn.
I bought a Mx2125 from RadioShack as it was closing many of its stores (https://www.parallax.com/product/28017). I didn't know what to do with it becuase I usually avoid any sensors that require a digital interface. However, after reading through the datasheet, I noticed it offered a method of converting its digital signal to an analog voltage through the simple use of an R-C low pass filter.
So follow along as I take you through the steps to convert the square pulse accelerometer output to a variable DC voltage, build a 555 servo controller circuit, and bias a transistor to source current from the 555 chip.
Step 1: Gather Your Components
Attached is a schematic and prototyping board layout of the circuit.
You will need these components:
-Stable 5V source like a USB battery
-x1 220k Ohm
-x1 22k Ohm
-x1 820k Ohm
-x2 1k Ohm
-x1 47k Ohm
-x1 100k Ohm
-x1 10k Ohm
-x2 npn transistors like 2N3904
-x1 555 Timer IC
Start by building the 555 servo controller and connecting a 10k potentiometer's wiper to the control pin (pin 5), and the other two ends to +5V and Ground. This creates a voltage divider at pin 5 and will demonstrate how the signal output of the 555 changes with varying voltage.
Step 2: Convert the Accelerometer Output to DC
The datasheet includes these instructions for converting the PWM output to an analog DC voltage.
The PWM output can be easily converted into an analog
output by integration. A simple RC filter can do the conversion. Note that that the impedance of the circuit following the integrator must be much higher than the impedance of the RC filter.
After testing this circuit, I noticed the square wave was made into a triangle wave with 1.6V of change. This was not suitable for my needs, so I increased the capacitance to 47 uF. The drawback of this method is that the response time is slower as the capacitor must charge and discharge. You should experiment with capacitor values here to meet your own needs. The oscilloscope snapshots show you the raw square wave output, the 1uF triangular conversion, and the final DC flatline output I wanted.
Step 3: Bias a Transistor and Connect to 555
Most npn transistors have a pn junction between base and emitter with a voltage drop of 700 mV. The 2N3904 I was using had a voltage drop of 740 mV. We need the voltage output of our accelerometer when perpendicular to gravity to be right at the cusp of saturating our transistor's base. The datasheet also recommends using a high impedance input so using a 100k resistor, then dividing the voltage to ~740 mV by using another 47k to ground at the base worked for me. Use your multimeter to measure the forward voltage drop of the transistor you plan to use and adjust your voltage divider to match. Try using a 200k Ohm trimpot between the 47uF cap and ground with the transistor base connected to the potentiometers wiper so you can accurately dial in your saturation point.
It is important to also note that pin 5 of the 555 chip is a direct connection to the three 5k Ohm resistors inside the IC. When applying voltage (or in this case, pulling it away) remember to keep in mind that there is a voltage divider inside the chip. So, I connected the collector of the npn transistor to pin 5, then the emitter to 500 Ohms and ground. I used two 1k Ohm resistors in parallel to do this. This way, the voltage drops considerably, but never goes to zero.
This step took me the longest, and requires some experimentation. I also added the 1 uF capacitor to pin 5 and ground to help reduce jitter and noise in the signal. Take your time, ask questions, measure voltages, and have fun here.
Step 4: Refine the Circuit and Add Another 555
At this point, you are technically done, but of course, there is another axis to think about! For the second axis, just duplicate what we already built. If you start with a 556 dual timer chip, you can create two servo controllers and access both control pins for each servo.
Trimpots in strategic places (like the 22k resistor, or the 100k-47k divider) will allow you to tune your servo to function more elegantly.
Thank you for reading along and watching the video!