Hardware Components
| Component | Quantity | Description |
|---|---|---|
| Arduino UNO | 1 | Main microcontroller board |
| Analog Hall Effect Sensor | 1 | AH49E or equivalent analog sensor |
| SSD1306 OLED Display (I2C) | 1 | 128×64 pixels OLED module |
| Breadboard | 1 | For easy prototyping |
| Jumper Wires | ~10 | Male-to-male wires |
| USB Cable | 1 | For uploading code and powering Arduino |
| Small Magnet | 1 | To test the sensor |
Schematic

Wiring / Connections
| Hall Effect | OLED SSD1306 | Arduino UNO |
|---|---|---|
| Ground (-) | GND | GND |
| VCC (+) | VCC | 3V3 |
| Signal (S) | A0 | |
| SDA | A5 | |
| SCL | A4 |
Arduino Code
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define HALL_SENSOR_PIN A0 // Hall sensor analog output connected to A0
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int baseline = 0;
void setup() {
Serial.begin(9600);
// Initialize I2C and OLED display
Wire.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 initialization failed!");
while (true);
}
pinMode(HALL_SENSOR_PIN, INPUT);
// Calibrate sensor baseline
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.setTextSize(1);
display.println("Calibrating...");
display.display();
long total = 0;
for (int i = 0; i < 100; i++) {
total += analogRead(HALL_SENSOR_PIN);
delay(10);
}
baseline = total / 100;
display.clearDisplay();
display.setCursor(0, 10);
display.println("Baseline set:");
display.print("Base: ");
display.println(baseline);
display.display();
delay(2000);
}
void loop() {
int reading = analogRead(HALL_SENSOR_PIN);
int delta = reading - baseline;
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
// Bar display layout
int barY = 20;
int barHeight = 20;
int barWidth = 124;
int centerX = SCREEN_WIDTH / 2;
// Draw bar outline
display.drawRect(centerX - barWidth / 2, barY, barWidth, barHeight, SSD1306_WHITE);
// Calculate and constrain fill width
int fillAmount = map(abs(delta), 0, 500, 0, barWidth / 2);
fillAmount = constrain(fillAmount, 0, barWidth / 2);
// Fill bar left or right based on polarity
if (delta > 0) {
display.fillRect(centerX, barY + 1, fillAmount, barHeight - 2, SSD1306_WHITE); // North
} else if (delta < 0) {
display.fillRect(centerX - fillAmount, barY + 1, fillAmount, barHeight - 2, SSD1306_WHITE); // South
}
// Display text labels
display.setTextSize(1);
display.setCursor(centerX - barWidth / 2, barY + barHeight + 5);
display.print("S (-)");
display.setCursor(centerX + barWidth / 2 - 30, barY + barHeight + 5);
display.print("N (+)");
display.setCursor(centerX - 10, barY - 10);
display.print("NEUTRAL");
// Show numeric strength
display.setCursor(0, 0);
display.print("Field:");
display.setCursor(40, 0);
display.print(abs(delta));
display.display();
delay(100);
}
Conclusion
This project is a fun and educational way to visualize magnetic fields using a Hall effect sensor and OLED display. It’s beginner-friendly and gives you insight into how analog sensors work with microcontrollers. It can be extended further into a digital compass, proximity magnetic switch, or rotational sensing system for motors.
Whether you’re a student, hobbyist, or maker, this is a great addition to your collection of Arduino-based sensor projects.
If you liked this project, follow more on circuit-diy.com for tutorials, projects, and practical circuits for makers like you!