Project tutorial
Magnetic Field Meter range +- 200mT (milliTesla)

Magnetic Field Meter range +- 200mT (milliTesla) © GPL3+

A stable instrument with display, LED and buzzer to feel the Magnetic Field live.

  • 300 views
  • 0 comments
  • 1 respect

Components and supplies

About this project

Description:

How to measure the magnetic fieldstrenght of a magnet, a coil, an inductor, a magnetized screwdriver, a piece of iron or whatever?

An interesting sensor with similar shape as a TO-92 BC337 transistor with 3 pins, helped me to realize this project.

To make it more interesting I included an Oled 128x32 display where you can read the value in mT (milliTesla), the magnetic field strenght of the object under testing. Together with the display there is a led and a buzzer as accompanying with light and sound proportionally to the value.

The value is "filtered" by the way of a simply average calculation of the last 500m/sec of samples, around 2000-4000 sensor readings, then shown every half a second; at the same time are discarded peak values to have a beautiful stable value in output.

Power up the circuit by the way of the mini-USB connector. To use my 3D model plastic box you should use also my double faced PCB to fit all components in so small room. Yes, you can do even smaller circuit using a smaller microcontroller and SMD components...

Place face up the sensor, the branded and most sensitive side, inside the window at the top of the probe; look at the picture below.

The Sensor:

The 3503 sensor gives out 0.1mT (1 Gauss) every 1.3mV. Note that the magnetic field can be + or - (north and south poles of a magnet), so the sensor generate the "zero" starting point at 2.5V below it are the minus values, over it are the plus values.

The "zero" point can slightly fluctuates depending of power supply voltage and temperature conditions, so I provided a button you will push to force the "zero" (or nearly it) before starting to measure of a magnetic field. This instrument will provide exactly +- 192.3 mT (+- 1923 Gauss) full scale. About the precision of the measurements I planned to compare it at an external laboratory with a serious other instrument, but looking at the sensor datasheet I guess this should be quite "serious" too, so not just a toy.

Components list:

  • Arduino Nano 5V MCU
  • Display OLED 128x32
  • Active buzzer
  • Blue LED 2.5mm
  • Push button (normally open)
  • 3 x 10k ohm resistors
  • 470 ohm resistor
  • UGN3503UA linear magnetic field sensor
  • Optional: a 3D shaped plastic box (please read NOTES below)

NOTES and improvements:

Happy measurements!

Code

Arduino IDE CodeArduino
/*
 This sketch acts as a Magnetic Field Meter, by Marco Zonca, 3/2021
 Arduino Nano as 5V MPU, UGN3503UA magnetic sensor, i2c Oled 128x32 display, a LED,
 one button, an active buzzer and a few resistors;

 Magnetic Field Meter, output in milliTesla (mT)
  
 from sensor +- 1.3 mV = +- 1 Gauss = +- 0.1 mT
 from sensor 2.5V = 0 (0-2.5V = -2500 to 0 mV, 2.5-5V = 0 to 2500mV)  
*/

#include <Wire.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display = Adafruit_SSD1306 (128, 32, &Wire, -1);

float aVal=0;
float aZero=0;
float aRead=0;
float VL=0;
float Gauss=0;
float mTesla=0;
float fTot=0;
float fNr=0;
float fMax=0;
float fMin=0;
float fAvr=0;

unsigned long fprevMillis=0;

const unsigned long fMillis=500;  // update display and average calc every 0.5 seconds
const int aValPin=14;
const int aLedPin=10;
const int aBuzPin=9;
const int aButton=15;

String mT = "  -0.0 mT";

void setup() {
  //Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Display Address 0x3C for 128x32 pixels
  mT.reserve(20);
}  //setup()

void loop() {
  aRead=analogRead(aValPin);
  if (aZero==0) aZero=aRead;  // initial auto zero
  if (digitalRead(aButton)==LOW) aZero=aRead;  // forced zero with button
  aVal=(map(aRead,0,1023,0,5000)-map(aZero,0,1023,0,5000)) / 1.3;  // to milliVolt, to Gauss
  if (aVal != 0) {
    fTot=fTot+aVal;
    fNr=fNr+1;
  }
  if (aVal>fMax) fMax=aVal;  // mem max
  if (aVal<fMin) fMin=aVal;  // mem min
  if (millis() > (fMillis+fprevMillis)) showVal(); 
}  //loop()

void showVal() {
  if (fMax != 0) {
    fTot=fTot-fMax;  // average without max
    fNr=fNr-1;    
  }
  if (fMin != 0) {
    fTot=fTot-fMin;  // average without min
    fNr=fNr-1;    
  }
  if (fNr > 0) {
    aVal=fTot/fNr;  // average value
  } else {
    aVal=0;
  }
  if (aVal != aZero) {
    Gauss=aVal;
    mTesla=Gauss/10;  // to milliTesla
    VL=abs((aVal) / 10);
    if (VL>255) VL=255;
    analogWrite(aLedPin,VL);  // lights led
    analogWrite(aBuzPin,VL);  // beeps buz
    //Serial.print(roundOneDec(mTesla));
    //Serial.println("mT");
  } else {
    Gauss=0;
    mTesla=0;
    analogWrite(aLedPin,0);  // off led
    analogWrite(aBuzPin,0);  // off buz
  }
  display.clearDisplay();  // output to display
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(1,1);
  display.print("Magnetic Field Meter");
  display.setTextSize(2);
  display.setCursor(8,16);
  mT="      "+String(roundOneDec(mTesla),1)+" mT";
  display.print(mT.substring(mT.length()-9));  // right alignment
  display.display();  
  
  fprevMillis=millis();
  fTot=0;
  fNr=0;
  fMin=0;
  fMax=0;
}  //showVal()

float roundOneDec(float f) {
  float y, d;
  y = f*10;
  d = y - (int)y;
  y = (float)(int)(f*10)/10;
  if (d >= 0.5) {
    y += 0.1;
   } else {
    if (d < -0.5) {
    y -= 0.1;
  }
  }
  return y;
}  //roundOneDec()

Schematics

PCB Overview
Magfield pcb overview arlncz4h9i
PCB Top face
Pcb magnetic field meter 2021 04 01 top e7sfum2ejw
PCB Bottom face
Pcb magnetic field meter 2021 04 01 bottom upbyw5qfyg
PCB Top components face
Pcb magnetic field meter 2021 04 01 top components owynbsr8au
PCB Bottom components face
Pcb magnetic field meter 2021 04 01 bottom components dar04ldnta
Fritzing Schematic Diagram
magfieldmeter_be8naBwhH3.fzz

Comments

Similar projects you might like

Magnetic Field Strength Meter

Project tutorial by Mirko Pavleski

  • 2,798 views
  • 1 comment
  • 11 respects

UltraV: A Portable UV-Index Meter

Project tutorial by fmarzocca

  • 10,561 views
  • 8 comments
  • 22 respects

Mobile Fine Dust (PM10 & PM2.5) and NO2 Meter

Project showcase by Telina

  • 19,949 views
  • 29 comments
  • 84 respects

Arduino pH Meter

Project tutorial by Atlas Scientific

  • 19,874 views
  • 5 comments
  • 40 respects

Wireless Water-Tank Level Meter with Alarm

Project showcase by Manusha_Ramanayake

  • 14,307 views
  • 16 comments
  • 34 respects

Preemptive Multitasking Scheduler for AVR

Project tutorial by Akash Kollipara

  • 4,417 views
  • 0 comments
  • 4 respects
Add projectSign up / Login