Magnetometer

From ShawnReevesWiki
Revision as of 09:12, 23 April 2019 by Shawn (talk | contribs) (→‎Version with smaller MCU, i2C LCD display)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Specifications

  • Use a ratiometric Hall effect sensor for repeatable measurements.
  • Include at least two-digits display, using floating point if two.
  • Use a breadboard so it can be modified.
  • Provide a steady reference voltage to the sensor so that output is accurate.
  • Indicate direction of magnetic field and a number proportional to the voltage of the ratiometric sensor.

Possible improvements

  • Allow a momentary-on button to allow the user to zero the readout.
  • Calibrate linearly, with a menu to allow setting high and low points.
  • Calibrate with a lookup table.

Circuit

Circuit diagram for a PICAXE-based magnetometer, using a PICAXE 20M2 with an SS49E Hall effect sensor and an EA DOGM081 LCD 8-character display. Pin numbers on DOGM081 begin on at 21 on upper right and go to 40 on upper left when facing module.

Components

Honeywell SS49E analog position sensor
This is a ratiometric Hall effect sensor, whose output voltage swings almost linearly from 1V to 3V when powered by 5V, as the magnetic field through the face goes from -1000 Gauss to 1000 Gauss. The sensor comes in a very small, three-pin package with leads, or a four-contact surface-mount device. I use the package with through-hole leads to put in our breadboard for testing.
Solderless breadboard

Version with larger MCU, LED display

This version will not run more than 10 hours on a battery, so use rechargeable batteries or a plug-in power supply.

PICAXE 20M2
This is an inexpensive micro-controller with a 10-bit ADC with the ability to set voltage reference to the power supply, 1.024V, 2.048, or 4.096V. It is easy to program with free software from Revolution Education, and requires fewer external parts than most micro-controllers. We will use the many output pins to control our display. Please see PICAXE serial for issues.
The PICAXE also requires two pulldown resistors on its serial programming pin.
2-digit, 7-segment LED display with decimal point
Optionally, shared pins for each analogous pair of segments reduce the amount of wires.

Version with larger MCU, SPI LCD display

Thanks to the low power consumption of this display, the whole circuit uses merely 6mA.

PICAXE 20M2
This micro-controller has enough pins to read ADC and output 4 SPI pins. We could also use the PIXAXE 14M2.
Electronic Assembly DOGM081W-A
An LCD display with 8 digits and an ST7036 controller capable of SPI communications over four wires.

Version with smaller MCU, i2C LCD display

PICAXE 08M2
This micro-controller has only eight pins and is very inexpensive.
Newhaven i2c LCD display
The PICAXE 08M2 only has three available output pins after we use one for the ADC, so we cannot use SPI-based LCD displays. However, since the Hall sensor works at a minimum of 4V but the Newhaven display works at a maximum of 3.3V, we need to power and communicate with the Newhaven display through a level shifter.

Power supply

A typical 5V regulated circuit, with protective diode and output capacitor. The input voltage must be greater than the dropout voltage of the regulator plus the voltage of the diode plus the output voltage (see a data-sheet).

We can use three AAA or AA cells which would provide 3.6V to 5.1V, or one lithium 3.7V cell. Or, we can use a 9V battery with a voltage regulator. Or a 3V to 5V wall adapter would work, although reduce portability in measuring fields in multiple locations. A regulated 5V supply will reduce the need for frequent calibration. The microcontroller will use a few mA, the LCD and sensor less than a quarter mA each, so you should get roughly a hundred hours of use from a set of 4 AAA batteries or 5-6 AAA batteries with a regulator, or at least 10 hours of use from a 9V battery with a regulator.

Program

See Magnetometer PICAXE 20M2 program for a working example.

Reading the output voltage of the sensor

Digitize the voltage output from the Hall sensor with an ADC converter. Many micro-controllers include an ADC with enough resolution for pedagogical purposes, usually 10-12 bits. If the output of the Hall sensor output the full range of the ADC, then we'd have at least 1 in 1000 precision (2^10 is 1024). But usually the output will be only about half of that range, so for 10 bits we'd have a precision of 1 in 500.


Displaying the digits on a shared-pin LED display

To display a value between 1 and 999 as just two digits, if the value is below 100 we display the ones and tens with a decimal point between them, else we divide the value by 10 and display the resulting tens and ones with a decimal point on the right; i.e., the decimal point always is between the tens and ones, and we declare that we're displaying decaGauss, not Gauss.

To convert a two-digit decimal value to individual characters, we set the variable TENS to the value divided by ten (all maths are in integers), and the variable ONES to the value modulo ten.

Since the two digits share the same cathode-pins, we can only show one at a time. We flip back and forth so quickly, about five thousand times a second, that it's imperceivable. The value of each digit is stored in a byte of memory, actually not the value [0-9] but the combination of bits to make the right LEDs on the display light up. For example, '8' requires all seven bits, while '7' requires just the first three.

Displaying the digits on a serial LCD

Every time we take a reading we clear the LCD. Then we send a negative sign if needed. We add an offset to each variable (HUNDREDS, TENS, ONES) equal to the value of 0 in the character map of the LCD, then send that offset HUNDREDS, TENS, and ONES to the LCD.

Sending the value to the serial port

Optionally, we can also send the raw ADC values and/or the calculated results to a computer or other device via another serial pin. Pin 19 of the PICAXE 20M2 operates at 4800 baud 8N1.

Datasheets

Electronic Assembly ED DOGM081-A
8-character LCD dot matrix display, with SPI serial control. http://www.lcd-module.com/eng/pdf/doma/dog-me.pdf
Read various forums for discussions on using SPI between the micro-controller and this display. For example, one on how CSB must be used: http://forums.parallax.com/showthread.php/134847-EA-DOGM-162-Display
Everlight ELD-515 two-digit, seven-segment LED display
http://www.everlight.com/datasheets/D515SURWA-S530-A3_datasheet.pdf
Honeywell SS49/SS19 Series Analog Position Sensors (Hall effect sensors)
http://www.mouser.com/ds/2/187/SS49-185687.pdf
While the datasheet states no damage will be caused by fields greater than 1000 Gauss, it does not indicate how such fields affect the output.
Sitronix ST7036 LCD Controller
The controller for the EA DOGM LCD displays. http://www.lcd-module.de/eng/pdf/zubehoer/st7036.pdf
ST Microelectronics L7805CV 5V regulator
http://www.st.com/web/en/resource/technical/document/datasheet/CD00000444.pdf
PICAXE micro-controller system for education
http://picaxe.com

See also

Hall Effect Sensing and Application by Honeywell.

Electronic circuits gives general tips on breadboards and their use.

Circuits for teaching physics discusses a rationale for having students build circuits like this magnetometer in physics classes.