Silicon ChipBuild A Digital Spirit Level - August 2011 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Big challenges lie ahead for Australia
  4. Review: Asus EeePad “Transformer” Tablet PC by Ross Tester
  5. Project: An Electronic Stethoscope by John Clarke
  6. Feature: Safely Removing Solder Fumes & Other Pollutants by Ross Tester
  7. Project: Build A Digital Spirit Level by Andrew Levido
  8. Book Store
  9. Project: Ultra-LD Mk.3 200W Amplifier Module, Pt.2 by Nicholas Vinen
  10. Project: Rudder Position Indicator For Power Boats, Pt.2 by Nicholas Vinen
  11. Review: UP! Portable 3D Printer by Nicholas Vinen
  12. Vintage Radio: Hotpoint Bandmaster J35DE console radio, Pt.2 by Maurie Findlay
  13. Advertising Index
  14. Outer Back Cover

This is only a preview of the August 2011 issue of Silicon Chip.

You can view 33 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "An Electronic Stethoscope":
  • Electronic Stethoscope PCB [01108111] (AUD $10.00)
  • Electronic Stethoscope PCB pattern (PDF download) [01108111] (Free)
  • Electronic Stethoscope front panel artwork (PDF download) (Free)
Items relevant to "Build A Digital Spirit Level":
  • Digital Spirit Level/Inclinometer or G-Force Meter PCB [04108111] (AUD $10.00)
  • PIC18LF14K22-I/P programmed for the Digital Spirit Level [0410811B.HEX] (Programmed Microcontroller, AUD $15.00)
  • Firmware (HEX file) and C source code for the Inclinometer/Digital Spirit Level [0410811B] (Software, Free)
  • Digital Spirit Level/Inclinometer/G-Force Meter PCB pattern (PDF download) [04108111] (Free)
Items relevant to "Ultra-LD Mk.3 200W Amplifier Module, Pt.2":
  • Ultra-LD Mk3 200W Amplifier Module PCB [01107111] (AUD $15.00)
  • Ultra-LD Mk3/Mk4 Amplifier Power Supply PCB [01109111] (AUD $15.00)
  • Ultra-LD Mk.3 Power Supply PCB pattern (PDF download) [01109111] (Free)
Articles in this series:
  • Ultra-LD Mk.3 200W Amplifier Module (July 2011)
  • Ultra-LD Mk.3 200W Amplifier Module (July 2011)
  • Ultra-LD Mk.3 200W Amplifier Module, Pt.2 (August 2011)
  • Ultra-LD Mk.3 200W Amplifier Module, Pt.2 (August 2011)
  • Ultra-LD Mk.3 200W Amplifier Module, Pt.3 (September 2011)
  • Ultra-LD Mk.3 200W Amplifier Module, Pt.3 (September 2011)
Items relevant to "Rudder Position Indicator For Power Boats, Pt.2":
  • Rudder Position Indicator PCB Set [20107111/2/3/4] (AUD $80.00)
  • ATtiny861 programmed for the Rudder Position Indicator Sensor/Transmitter [2010711A.HEX] (Programmed Microcontroller, AUD $15.00)
  • ATtiny861 programmed for the Rudder Position Indicator Receiver/Display [2010711B.HEX] (Programmed Microcontroller, AUD $15.00)
  • Firmware (HEX) files and C source code for the Rudder Position Indicator [2010711A/B] (Software, Free)
  • Rudder Position Indictor PCB patterns (PDF download) [20107111/2/3/4] (Free)
Articles in this series:
  • Rudder Position Indicator For Power Boats (July 2011)
  • Rudder Position Indicator For Power Boats (July 2011)
  • Rudder Position Indicator For Power Boats, Pt.2 (August 2011)
  • Rudder Position Indicator For Power Boats, Pt.2 (August 2011)

Purchase a printed copy of this issue for $10.00.

Digital l e v e L Spirit By ANDREW LEVIDO This project is really on the . . . errr . . . level. It’s an inclinometer, an electronic version of the old spirit level except that this one gives a digital readout of the angle of any flat surface in 0.1° increments from 0-360°. A MEMS accelerometer chip, as found in tablets and smart phones, is at the heart of the project. M OST OF US HAVE a spirit level somewhere in our shed or garage. These handy devices have been around since the mid 1600s, although the modern form of the device dates from the 1920s. A simple air bubble in a slightly curved tube of coloured alcohol can indicate horizontal or plumb (vertical) with surprising accuracy. Often a quick check for plumb or level is all that is needed but if you want to measure the actual angle you need an inclinometer. You can buy a digital one for up to a couple of hundred dollars or build one yourself for less than $40, thanks to the plummet34  Silicon Chip ing costs of MEMS accelerometers. MEMS (Micro Electromechanical Systems) technology is finding its way into all sorts of consumer electronics these days. Your tablet or smart phone has a MEMS accelerometer so it knows whether you are holding it in portrait or landscape orientation. Handheld game controllers use both accelerometers and gyroscopes to detect how they are waved, shaken, pointed or flicked. Even my universal remote controller uses one to turn on its LCD when I pick it up. The inclinometer described in this article uses a typical MEMS chip; the Freescale Semiconductor MMA8451Q. This tiny 16-pin surface-mount device includes a 14-bit 3-axis accelerometer together with a sophisticated DSP (Digital Signal Processor) and an I2C interface, all for less than $10. Add a low-cost PIC microcontroller, four 7-segment LED displays and a handful of common components and you have all that is necessary for a pretty useful little instrument. Form factor Our inclinometer has a form factor that’s similar to a small spirit level and can measure angle of tilt with an siliconchip.com.au accuracy of 0.1° over the full 360° of rotation. Operation could not be simpler. Just pick up the device and give it a shake to bring it to life, then place it on the surface you want to measure. It will stay awake while ever it senses movement and it will automatically turn off after 30 seconds of inactivity. Y AXIS X AXIS G x SIN θ How it works The inclinometer measures its orientation with reference to the acceleration due to gravity which, conveniently for us all, always points straight down. We nominate the side-to-side horizontal axis of the accelerometer as “x”, the top-to-bottom axis as “y” and the front-to-back axis as “z”. If the accelerometer is level, gravity will be perfectly aligned with the y axis. However, when tilted as shown in Fig.1, there will be components of gravitational acceleration (ie, G x sinθ and G x cosθ) along both the “x” and “y” axes, depending on the tilt angle. Using trigonometry, we could calculate the angle of tilt from the measured acceleration along the x or y axis, as long as we knew the gravitational acceleration. Unfortunately, this varies from the nominal 9.8ms2 depending on location, since the Earth is neither perfectly spherical nor uniformly dense. Fortunately, we can use the trigonometric identity tanθ = sinθ/cosθ, to solve our problem. If we take the inverse tangent (arctangent) of the ratio of accelerations along the x and y axes, the gravity terms cancel out and we arrive at the angle of inclination using only the acceleration values. So the angle can then be determined by using the formula θ = atan(x/y) where x and y are the measured accelerations along the two axes. There is another complication however. If the inclinometer tilts around the x-axis (ie, the x-y plane is no longer vertical), a component of the acceleration due to gravity appears on the z-axis, and the components along the x and y-axes reduce. Ultimately, with the inclinometer lying flat on its back, the x and y components reduce to zero, as all of the acceleration now acts in the z-direction. The falling amplitude of the x and y accelerations as the x-y plane tilts about the x-axis progressively reduces the accuracy of the measurement. The digital inclinometer described here can maintain 0.1° accuracy, up siliconchip.com.au G x COS θ ANGLE = θ GRAVITY (G) Fig.1: the accelerometer measures the component of the acceleration due to gravity acting on each of the three axes. These components are trigonomet­ rically related to the angle of inclination (see text). Note that the z-axis has been omitted from this diagram for clarity. to the point where the tilt about the xaxis reaches ±45°. The microcontroller therefore keeps track of all three angles, and displays four dashes in place of the measured angle if this level of accuracy cannot be guaranteed. Wake & sleep modes As described above, the main ICs in the inclinometer are in a low-power deep sleep mode when it is not being used and “wakes up” when its senses movement. It remains awake until it senses that it has not moved for about 30 seconds. The MMA8451Q’s built-in DSP looks after the detection of movement and the consequent transition between wake and sleep modes. This is just one of the many features of the chip; see the panel titled “Inside the MMA8451Q” for further information on this device. The DSP algorithm considers motion to be an acceleration that exceeds a programmable threshold for a programmable period of time. Optionally, the acceleration signals can be highpass filtered first, to eliminate static effects (such as gravity). In addition, motion detection can be enabled on each axis independently. We set the motion sensitivity threshold fairly low while the unit is awake so that relatively small movements suffice to keep it that way. Conversely, in the sleep mode, the sensitivity is reduced so that a solid “air swing” is required to wake the inclinometer up. This prevents the device from being woken up by every small knock or vibration, as might be experienced in a moving vehicle for example. Circuit description The circuit diagram in Fig.2 shows that the Digital Inclinometer uses just two chips – the MEMS accelerometer (IC1) and a PIC18LF14K22 microcontroller (IC2). The latter drives the anodes of the four 7-segment LED displays directly and the common cathodes indirectly via four Mosfets (Q1-Q4). The whole circuit is powered directly from two AA batteries, with 10µF and 100nF capacitors providing bulk filtering and high-frequency bypassing respectively. The supply for the accelerometer (IC1) is further filtered by a 10Ω resistor and 10µF and 100nF capacitors, preventing any ripple generated by driving the display from affecting accelerometer measurements. The PIC micro communicates with the accelerometer using an I2C bus (pins 6 [SDA] & 4 [SCL] of IC1) and two interrupt lines (pins 9 & 11 of IC1). Two 4.7kΩ resistors are used as the usual “pull-ups” for the I2C bus. The accelerometer is configured to generate a negative-going interrupt pulse on pin 11 (INT1) each time a new acceleration sample is available. Similarly, a negative-going interrupt pulse appears on pin 9 (INT2) of the August 2011  35 +3V DISP1–4: FND500 OR EQUIVALENT 10 F 100nF 10 4.7k 10 F 1 Vdd 10k 4.7k 4 MCLR 100nF Vpp 2x AA CELLS 1 VddIO 2 100nF 7 BYP PGC 14 Vdd 6 SDA 13 4 11 SCL IC1 MMA8451Q 11 SA0 INT1 INT2 GND GND GND 5 10 12 1k 18 17 9 10 CAL S1 +3V 16 RC0 15 RC1 14 RC2 7 RC3 6 RC4 5 RC5 8 RC6 9 RC7 8x 4.7 DISP1 10 g 9 f 7 a 5 dp f 1 e 6 e SCK/RB5 INT1/RA1 INT2/RA2 RB5 RA0 RA5 RA4 RB7 Vss 20 DISP3 a b f DISP4 a b g e c d f a b g e c d f b g e c c d d K IC2 PIC18LF14K22 SDA/RB4 a g b 2 d 4 c DISP2 8 8 8 8 D Q1 TN0604 G 12 S 19 G PGD D Q2 TN0604 S D Q3 TN0604 G 2 S 3 Vpp +3V D Q4 TN0604 G S PGC GND 1 (ICSP SKT) 5 TN0604(N3) SC 2011 INCLINOMETER (ELECTRONIC 'SPIRIT LEVEL') D G S Fig.2: the circuit for the Inclinometer. The accelerometer (IC1) interfaces with the microcontroller (IC2) over just four lines – two for interrupt signals (pins 9 & 11) and two for the I2C bus (pins 4 & 6). The ICSP connector is not necessary if your microcontroller is supplied pre-programmed. accelerometer whenever it detects movement, or changes between sleep its wake states. Pin 18 (RA1) on the PIC microcontroller serves double-duty, functioning both as an interrupt input and as the clock input for in-circuit programming. The 1kΩ resistor is required to ensure that the in-circuit serial programmer (ICSP) interface can drive pin 18 without interference from the accelerometer, for programming the micro. The ICSP data input is shared with pin 19, one of the digit driver outputs. No similar resistor is required here because the Mosfet gate is high impedance and won’t affect programming. The display is a classic multiplexed common-cathode 7-segment arrangement. The eight 4.7Ω resistors on pins RC0-RC7 provide current limiting for the segment LEDs, although in reality the microcontroller outputs themselves limit the drive current to about 20mA per segment. Mosfets Q1-Q4 are used to drive the digits’ common cathodes, rather than the usual bipolar transistors, because they can provide a very low “on” resistance even when driven at a low voltage. With only 36  Silicon Chip 3V to play with (less if the battery is discharged), we can’t afford the few hundred millivolt drop that bipolar transistors would exhibit. The firmware The firmware is fairly straightforward. The main program sets up the microcontroller peripherals, configures the accelerometer and then enters an endless loop. From there on, everything occurs in one of four interrupt service routines. One interrupt, triggered by an internal timer, multiplexes the display. The interrupt occurs every 5ms which defines the on-time for each digit. It therefore takes 20ms to display all four digits, for a 50Hz refresh rate. The second interrupt service routine is triggered by a falling edge on pin 18 of the micro, indicating that new accelerometer data is available. When the accelerometer is awake, this occurs every 640ms. The firmware reads the new data via the I2C bus, calculates the angle, subtracts the offset value stored in EEPROM and updates the display (more on the offset value later). The third interrupt service routine is triggered by a falling edge on pin 17. This indicates either that the accelerometer has switched between its wake and sleep states or that movement has occurred. We are only interested in the wake-to-sleep transition, so when the interrupt occurs the micro interrogates the accelerometer to find the source of the interrupt. If the accelerometer has gone to sleep, the firmware turns off the display and puts the microcontroller to sleep too, configuring it to wake up only when a new interrupt occurs on pin 17. This happens only when there is further movement which reawakens the accelerometer. The final interrupt service routine is invoked when the user presses and releases the calibration button (S1). This routine zeroes the display and stores the current angle as the offset value in the micro’s internal EEPROM memory. This allows you to compensate for any imperfection in the alignment of the mechanical axes of the accelerometer relative to the case. It’s unlikely that the accelerometer IC is perfectly aligned with the metal case (due to both misalignment between the IC and PCB, and the PCB and the case) but this can be compensated for siliconchip.com.au 8888 TN0604 N3 TN0604 N3 TN0604 N3 TN0604 N3 FND500 FND500 FND500 (COMMON CATHODE) BATTERY 3V + – SC FND500 CALIBRATE S1 4.7 1 ICSP 1k 10k 100nF 4.7 4.7 4.7 4.7 4.7 4.7 4.7 10 04108111 Q4 100nF IC1 10F PIN 1 IC1 (UNDER) 10F 4.7k Q3 4.7k Q2 IC2 PIC18LF13K22 Q1 100nF Digital Inclinometer 11180140 (UNDERSIDE OF BOARD) Fig.3: install the parts on the PCB as shown on this layout diagram. Note that the two 10uF capacitors must be mounted on their sides. Fig.4: the MMA8451Q is mounted on the copper side of the PCB as shown here. Left: a close-up view of the MMA8451Q in position. Be sure to orientate it correctly. This prototype differs slightly from the final version shown in Fig.3 (eg, Q1 is orientated differently and hole for the battery leads has been moved. to give a zero reading on a perfectly level surface. Power consumption In sleep mode, the micro draws less than 100nA and the accelerometer only 14µA – amazing considering it is still measuring acceleration and checking for movement. In use, the inclinometer draws around 50mA, most of which is consumed by the display. With moderate usage therefore, the two 1.5V AA batteries should last many months. The inclinometer monitors the battery voltage and when it falls to around 2.85V, lights one decimal point on the display to indicate that the battery is low. Since every pin on the micro is used, we had to resort to a clever trick to monitor the battery. The microcontroller’s ADC is con- figured to measure a fixed internal 1.024V band-gap voltage using the supply voltage as the reference. This is the opposite of the way we would normally do things and means that as the battery voltage falls, this measurement actually increases. It’s not a linear relationship but it is more than adequate for detecting a low battery level. Construction The Digital Inclinometer is built on a small, single-sided PCB. All components are through-hole types with the exception of the accelerometer (IC1) which is in a tiny 16-pin QFN (surface-mount) package. This is the first thing you should fit. It takes some patience and a steady hand but it can be soldered in manually. First, carefully tin the pads. You want a thin, even layer of solder, so use solder wick to clean up any bumps or shorts between pads. Check carefully for solder shorts between pads at this point and fix them now. Once the chip is down, you will not be able to see the joints. Now carefully place the accelerometer on the pads, lining up the tiny dot on its body with the corresponding dot on the PCB layout. In addition, make sure that the chip is properly lined up with the pads on all four sides. The small marks on the sides of the chip indicate the pin positions and these must be perfectly lined up with their corresponding pads. Once it’s fully lined up, you need to melt the solder under each pad, without moving anything. If you have a hot-air rework station, you can use this to gently heat the chip until the solder reflows. If you don’t, you need to use a soldering iron to apply heat to each pad in turn, all the while holding the chip in place. The idea is to melt that thin layer of solder you applied to the pads and to heat the corresponding contact on the chip so that the two Table 1: Resistor Colour Codes o o o o o o siliconchip.com.au No.   1   2   1   1   8 Value 10kΩ 4.7kΩ 1kΩ 10Ω 4.7Ω 4-Band Code (1%) brown black orange brown yellow violet red brown brown black red brown brown black black brown yellow violet gold brown 5-Band Code (1%) brown black black red brown yellow violet black brown brown brown black black brown brown brown black black gold brown yellow violet black silver brown August 2011  37 Fig.5: the base is made from a 200mm length of 50 x 25 x 3mm aluminium channel, while the two end pieces (right) are made from 44mm lengths of 20 x 12 x 1.4mm aluminium angle extrusion. Fig.6: the front panel is made from 3mm red Perspex. Drill and countersink carefully as the material fractures easily. The back of the panel is sprayed matte black, except for the display window shown dotted. Left: this is the view inside the case before the PCB and battery are installed. The end pieces are secured using M3 x 6mm countersinkhead screws and M3 x 16mm tapped metal spacers. The Perspex front panel (below) is spraypainted matte black on the inside, with the display window masked out. 38  Silicon Chip siliconchip.com.au The PCB is mounted inside the case on four M3 x 6mm spacers and secured using machine screws (pan head on top, countersink head through the case). bond. Take your time, but try not to overheat the accelerometer. Now use a multimeter to check for any unintentional shorts between adjacent pads. If there is a solder short between two adjacent pins, you will be able to remove it using solder wick. Once the accelerometer (IC1) is in position, the remaining parts can be installed in order of height, ie, from lowest to highest. Note that the Mosfets (Q1-Q4) have to be pushed down so that they do not stand proud of the 7-segment displays. Likewise, the two electrolytic capacitors are mounted on their sides (ie, with their leads bent down at right angles), so that they are lower than the display faces. The 7-segment displays are soldered directly to the PCB. Make sure that they sit flush with the board surface and that they are orientated correctly (ie, each decimal point at lower right). Having completed the board assembly, attach the battery holder and insert a pair of fresh AA cells. If everything is working correctly, the display will show four dashes while the PCB is face up. Now slowly tilt the board up to vertical with its long edge on the bench and check that it displays an angle within a few degrees of horizontal (ie, just above 0.0 or just below 360.0). If that checks out, hold it perfectly still for about 30 seconds. At the end of this period, the display should go blank as the device falls asleep. When it does, give it a firm shake to wake it up again. Finally, check the calibration button by positioning the board at an angle of a few degrees and briefly pressing the calibration button. When the button is released, the display should read zero. Troubleshooting If there is no display, check that the component values and orientations are correct. That done, visually inspect the solder side for bad joints or solder shorts. If that looks OK, use a multimeter to check for 3V on the micro’s supply pins (ie, between pins 2 & 20) and check that the MCLR pin is pulled high. If you have access to a scope or frequency counter, check for 5ms pulses repeated every 20ms at the gates of the Mosfets. If these are present, you can be confident the micro is operating. If the micro is working but no angle measurement takes place, the problem probably lies with the soldering of the accelerometer. In that case, remove the batteries and inspect your work with the aid of a magnifying glass. Since you checked for shorts earlier, the most likely problem is an open-circuit pin so carefully resolder each one using a fine-tipped iron and applying very small amounts of solder. Basically, you want the solder to melt and wick up under the chip. If you inadvertently apply too much solder, use solder braid to remove the excess. Housing We made the housing from a length of 50 x 25 x 3mm aluminium channel (a standard extrusion that should be available from your local aluminium centre). The end pieces are also aluminium extrusions, this time 20 x 12 x 1.4mm angle extrusion. You will have to cut and drill the aluminium as shown in Fig.5, taking care to de-burr all the holes. If you want a form factor more akin to a spirit level, you can cut the 50mm channel longer than shown, so that it extends out either side of the end-pieces. The front panel is a piece of trans- Fig.7: this cross-section diagram shows how the Inclinometer is assembled into its case. The battery holder is held in place with foam-core double-sided tape. siliconchip.com.au August 2011  39 X-AXIS TRANSDUCER Y-AXIS TRANSDUCER CAPACITANCE TO VOLTAGE CONVERTER 14-BIT ADC 32-WORD FIFO BUFFER FREEFALL & MOTION DETECTION EMBEDDED DSP TRANSIENT DETECTION ORIENTATION DETECTION SINGLE & DOUBLE TAP DETECTION AUTO WAKE & SLEEP Z-AXIS TRANSDUCER What’s inside the MMA8451Q accelerometer chip The Freescale Semiconductor MMA8451Q is a 14-bit 3-axis accelerometer with a built-in DSP (Digital Signal Processor) and a plethora of embedded functions. The acceleration transducers are MEMS (Micro Electromechanical Systems) technology which combines on-chip nano-scale mechanical parts with electronic components. In this case, each transducer is a microscopic sprung mass which forms the moving plate of a capacitor. As the mass moves against the spring, under the influence of acceleration, the capacitance changes. The capacitance is converted to a voltage and then digitised by the 14-bit ADC for processing by the on-board DSP. The gain can be configured for full-scale readings of ±2g, ±4g or ±8g and the transducers are sampled at a programmable rate of up to 800 times per second. Naturally, faster sampling increases power consumption. Although the ADC has 14-bit resolution, the effective resolution of the device is limited by mechanical and electronic noise. The signal-to-noise ratio (SNR) can be improved by oversampling, where multiple samples are averaged into each reading. Many combinations of sampling rate and oversampling are available, allowing the user to trade off accuracy, update lucent red Perspex, cut and drilled according to Fig.6. Keep the protective film in place as long as possible to avoid scratches. The inside of the Perspex is spray-painted matte black after masking off the rectangular section that will be directly in front of the 40  Silicon Chip INTERRUPT CONTROLLER I2 C INTERFACE SDA SCL rate and power consumption. The sampled data is available for direct readout via the I2C bus but some of the real power of this device comes with the embedded DSP functions. The chip is extremely flexible, if a little difficult to master, with a 50page datasheet and more than 40 configuration registers. For example, the output data may be directed to a FIFO (first in, first out) buffer capable of storing up to 32 samples. This means that at high sample rates, the microcontroller can wait until several samples have accumulated before reading them all in one go. The FIFO can even be read out while simultaneously capturing data. A freefall/motion detector can detect when the device is falling. This is often used in portable devices to park the hard disk drive read heads safely before impact. Alternatively, this functional block can be configured to detect motion. The user can configure both the level and duration of movement required to qualify as valid motion, configure a high-pass filter and nominate which axes are to be monitored. Orientation function An orientation function detects whether the accelerometer is oriented in “portrait” or “landscape” mode, LED displays (see above photo). The best way to make this mask is to first peel off the protective film on the inside surface and then cover the central section (ie, where the display window goes) with masking tape. Make sure you slightly overlap each INT 1 INT 2 whether it is face up or face down and whether it’s upright or upside-down. The transition points and the hysteresis between them are configurable. The transient function detects fleeting events such as flicks and shakes. This makes use of a configurable highpass filter and configurable level and duration thresholds. Another block can detect single and double-tap events and can determine on which axis and in which direction the tap originates. Once again the amplitudes, durations and delays are all programmable via the I2C interface. Most of these functions can be selected as inputs to the auto sleep/ wake function, which either puts the device into a sleep mode or wakes it up. The device is still active in sleep mode; it just falls back to a (programmable) lower sampling mode and rate. Current consumption can be as low as 6μA in this state, even though the chip is fully functional. There is also a standby mode. The MMA8451Q also contains an interrupt controller. The interrupt sources include all the functional blocks, the availability of new data and the sleep/ wake logic. Any source can be directed to either of the two outputs and the outputs can be configured for polarity. You can even select whether the outputs are push-pull or open drain! strip so that there are no gaps. That done carefully measure and draw the rectangular window onto the tape. You can now use a sharp hobby knife and a metal straight-edge to cut through the tape around the window. Don’t press too hard – you want to siliconchip.com.au The completed Inclinometer is shown here, together with a conventional spirit level at the rear. The unit measures in 0.1° steps from 0-360° (the resting surface here is not quite level). cut through the tape but not score the Perspex too deeply. Finally, you can peel off the excess tape, leaving just a neat rectangle in the middle, ready for spraying. Fig.7 shows how the whole thing goes together. The end pieces are each held in place by two M3 x 16mm spacers which are secured using M3 x 6mm countersunk machine screws. These spacers also support the front panel. The PCB is supported on four M3 x 8mm spacers and these are also secured to the case using M3 x 6mm countersunk machine screws. It’s best to test-fit the whole assembly, then use some Loctite to secure the eight countersunk screws holding the spacers into the housing. You can now paint the case to your liking, ensuring you don’t get paint in the threads of the spacers. Once that’s done, add some foam-core doublesided tape inside the case to hold the battery in place (see photo) and secure the PCB using four M3 x 6mm pan head screws. Calibration To calibrate the unit, place it on a known level surface (a 2-metre spirit level will typically be accurate to 0.05°) and press the calibrate switch. Alternatively, you could level a piece of timber or metal using a water level made from clear plastic tubing. Pressing switch S1 now automatically calibrates the unit. You can confirm that it is correct by checking siliconchip.com.au Parts List 1 PCB, code 04108111, 100 x 44mm 1 tactile pushbutton momentary switch (S1) (Jaycar SP0601, Altronics S1120) 1 5-way pin header (ICSP) (2.54mm pitch) 1 2 x AA battery holder (Jaycar PH9202) 1 200mm-length of 50 x 25 x 3mm aluminium extrusion 2 44mm lengths of 20 x 12 x 1.4mm aluminium angle extrusion 1 red Perspex sheet, 197 x 44 x 3mm 4 M3 x 16mm tapped spacers 4 M3 x 8mm tapped spacers 12 M3 x 6mm countersunk machine screws 4 M3 x 6mm pan head machine screws 1 330 x 20 x 3mm length of closed-cell foam 1 180mm length of regular double-sided tape 1 60mm length of foam-core double-sided tape masking tape black & yellow paint that the unit indicates 0° when it is orientated in either direction. The unit can then be completed by fitting the Perspex front panel and securing it using four M3 x 6mm Semiconductors 1 MMA8451Q 3-axis accelerometer (IC1) (Mouser*, Digikey, Ele­ ment14 Order Code 1842359) 1 PIC18LF14K22-I/P microcontroller programmed with 0410811A.hex (IC2) (Mouser*, Digikey, Element14 Order Code 1770702) 4 TN0604N3 Mosfets (Q1-Q4) (Mouser* 689-TN0604N3-G) 4 FND500 7-segment LED displays or equivalent (Jaycar ZD1855, Altronics Z0190) * Mouser components are available either direct from Mouser or via Active Components in Australia & NZ. Capacitors 2 10µF 16V electrolytic 3 100nF MKT or monolithic ceramic Resistors (0.25W, 1%) 1 10kΩ 1 10Ω 2 4.7kΩ 8 4.7Ω 1 1kΩ countersunk machine screws. That’s it! Your new Inclinometer is now ready for use. It’s a simple project that nicely demonstrates the power and versatility of MEMS devices. SC August 2011  41