|
Arduino Nano R3 |
x 1 | |
|
HMC5883L Compass module |
x 1 | |
|
0.96 |
x 1 | |
|
NeoPixel Ring: WS2812 5050 RGB LED |
x 1 |
|
arduino IDEArduino
|
|
|
Soldering iron |
|
|
Soldering Iron Wire Welding Lead Roll |
Arduino Analog + Digital Compass with HMC5883L sensor
Compass is device used for navigation and orientation, and consists of a magnetic needle that is mounted on a pivot and is free to rotate horizontally. The needle aligns itself with the Earth's magnetic field, and scale under her typically has four cardinal directions marked on it: North, East, South, and West.
In addition to these four main directions, many compasses also have additional markings indicating the degrees or fractions of a circle.
The device presented in the video represents an electronic version of the Compass, where the position of the needle is indicated by group of a three light-emitting diodes.
There is also an Oled display in the middle of the device, which shows the angle relative to the North Pole. In this case the resolution is greater than one degree, while in the case of LEDs the resolution is 6 degrees when moving one diode. When the red diode coincides with the top of the arrow and the value of the angle on the Oled display is about 0 and 360 degrees, then this side is North, opposite to it is South, and East and West are located at an angle of 90 degrees.
The device is relatively simple to build and consists of several components:
- Arduino Nano microcontroller
- HMC5883L compass module
- Led ring with 60 adressable RGB Leds type WS2812B
If you want to make a PCB for this project, or for any other electronic project, PCBway is a great choice for you. PCBway is one of the most experienced PCB manufacturing company in China in field of PCB prototype and fabrication. They provide completed PCB assembly service with worldwide free shipping , and ISO9001 quality control system. Also, on their site there is an online gerber viewer where you can upload your gerber and drill files to render your board.
The Arduino code is simple as it uses libraries for the Led ring as well as the Compass module. The only modification is conditioned by the fact that we need to enter the declination angle for the specific area for a more accurate result, which we can find it at:
http://magnetic-declination.com/
We also have to calibrate the sensor using the calibration code provided in the library, and input the resulting values into the code in line:
compass.setOffset(27, 200);// Set calibration offset. See HMC5883L_calibration.ino
At the beginning, let me emphasize that the instrument is very sensitive to local magnetic fields and massive metal objects in its surroundings, so the results of this video may deviate to a certain extent. First we need to place the compass in a horizontal position and then turn it on. After the initial logo, a group of 3 LEDs appears on the screen, the two surrounding ones are Green, and the middle one, which represents the direction, is Red.
By equating the arrow with the Red Led we get the direction of the North pole. By rotating the compass around its own axis the OLED display shows the angle between north and the tip of the arrow at the given moment. So the Red LED always points North.
In my case I use a box with a oled display from one of my previous projects, and Led ring is mounted in a situable case made of 3D Printer, and below is the .STL file for 3D printing.
/* Start of Code */ #include <SPI.h> #include <Wire.h> #include "FastLED.h" #include <HMC5883L.h> #include <Adafruit_GFX.h> #include <Adafruit_SH1106.h> #define OLED_RESET 4 #define SCREEN_ADDRESS 0x3C Adafruit_SH1106 display(OLED_RESET); #define NUM_LEDS 60 // Number of LEDs on Ring #define DATA_PIN_RING 3 // Pin 3 connected to RGB Ring CRGB leds_RING[NUM_LEDS]; HMC5883L compass; int fixedHeadingDegrees; // Used to store Heading value void setup() { Serial.begin(9600); Wire.begin(); FastLED.addLeds<NEOPIXEL,DATA_PIN_RING>(leds_RING, NUM_LEDS); display.begin(SH1106_SWITCHCAPVCC, SCREEN_ADDRESS); display.clearDisplay(); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(22,10); display.println("mircemk");// Print text display.setCursor(22,40); display.println("COMPASS"); display.display(); delay(2000); // Set measurement range compass.setRange(HMC5883L_RANGE_1_3GA); // Set measurement mode compass.setMeasurementMode(HMC5883L_CONTINOUS); // Set data rate compass.setDataRate(HMC5883L_DATARATE_30HZ); // Set number of samples averaged compass.setSamples(HMC5883L_SAMPLES_8); // Set calibration offset. See HMC5883L_calibration.ino compass.setOffset(27, 200); } void loop() { Vector norm = compass.readNormalize(); // Calculate heading float heading = atan2(norm.YAxis, norm.XAxis); // Set declination angle on your location and fix heading // You can find your declination on: http://magnetic-declination.com/ // (+) Positive or (-) for negative // For Montreal,QC declination angle is -14'35W (negative) // Formula: (deg + (min / 60.0)) / (180 / M_PI); float declinationAngle = (5.0 + (3.0 / 60.0)) / (180 / M_PI); //for Ohrid heading -= declinationAngle; // Correct for heading < 0deg and heading > 360deg if (heading < 0) { heading += 2 * PI; } if (heading > 2 * PI) { heading -= 2 * PI; } // Convert to degrees float headingDegrees = heading * 180/M_PI; // To Fix rotation speed of HMC5883L Compass module if (headingDegrees >= 1 && headingDegrees < 240) { fixedHeadingDegrees = map (headingDegrees * 100, 0, 239 * 100, 0, 179 * 100) /100.00; } else { if (headingDegrees >= 240) { fixedHeadingDegrees = map (headingDegrees * 100, 240 * 100, 360 * 100, 180 * 100, 360 * 100) /100.00; } } int headvalue = fixedHeadingDegrees/4.88; int ledtoheading = map(headvalue, 0, 59, 59, 0); Serial.print("Angle:"); Serial.print(headingDegrees); Serial.println(); display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setCursor(20,10); display.println("Angle"); display.setCursor(10,40); display.println(headingDegrees); display.display(); FastLED.clear(); if (ledtoheading == 0){ leds_RING[59] = CRGB::Red; leds_RING[0] = CRGB::Green; leds_RING[58] = CRGB::Green; } else { if (ledtoheading == 59){ leds_RING[0] = CRGB::Red; leds_RING[59] = CRGB::Green; leds_RING[1] = CRGB::Green; } else { leds_RING[ledtoheading] = CRGB::Red; leds_RING[ledtoheading+1] = CRGB::Green; leds_RING[ledtoheading-1] = CRGB::Green; } } FastLED.setBrightness(50); FastLED.show(); delay(100); } /* End of Code */
Arduino Analog + Digital Compass with HMC5883L sensor
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
- Comments(0)
- Likes(0)
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Mirko Pavleski
- Arduino Rotary encoder combination lock (Arduino door lock system with Rotary Encoder) Rotary dial safes typically use a mechanical combination lock. They are valued for their simplicity...
- DIY DRSSTC Music Tesla coil with Interrupter using cheap Driver Module DRSSTC (Dual resonant solid state tesla coil) is a type of Tesla coil that uses solid-state compone...
- Arduino HPDL1414 Retro Clock with Set and Alarm Functions The HPDL-1414 is a 16-segment LED display with four printable fields that is over twenty years old....
- How to turn a 7 inch Elecrow pi terminal into a standalone SDR Radio Today I received the Pi Terminal-7” IPS HMI CM4 Panel All-In-One Module Raspberry Pi Computer from E...
- DIY Simple Functional Lakhovsky MWO (Multiwave Oscillator) Therapy Device The Lakhovsky Multiwave Oscillator (LMO) is a device that was developed by Georges Lakhovsky in the...
- DIY simple Advanced Weather station (5day forecast) and Internet Radio ELECROW crow panel 2.8 inch esp32 display module is ideal for making simple but also relatively com...
- Arduino 3D Printed self Balancing Cube Self-balancing devices are electronic devices that use sensors and motors to keep themselves balanc...
- Tug of War Arduino Game on WS2812 Led strip A Tug of War is a classic team-based game where two opposing teams compete to pull a rope in opposi...
- DIY ESP32 Bioresonance Rife Machine with ZAPPER function Rife machine therapy is an alternative treatment developed by Dr. Royal Raymond Rife in the 1930s. H...
- Arduino VFO Project with a Large LCD Display A Variable Frequency Oscillator (VFO) is an electronic oscillator whose output frequency can be adj...
- Exploring the Tesla Coil Driver Board, Full Review & Test Results Some time ago I presented you a video in which I analyzed a super cheap Tesla Coil driver that cost...
- Arduino Eatrthquake alarm and protection system with D7S seismic Sensor Earthquakes are extremely common events around the world. On average, there are fifty earthquakes a...
- Review and Comparison of Three Inexpensive Metal Detector Kits A metal detector is a device used to detect the presence of metal objects in the ground or other ma...
- How to make simple Arduino RGB Led strip VU Meter VU meter or volume unit meter is a device intended for visual presentation of the audio signal. It ...
- DIY Simple Antistress and Relaxation PEMF Device based on Schumannn resonance frequency 7.83 Hz Schumann resonances are global electromagnetic resonances, generated by lightning discharges in the...
- DIY Si4825 A10 multiband Radio (MW,SW,FM) Thanks to the production of specialized radio chips, nowadays it is possible to make a quality mult...
- DIY simple HUNTER Led Game with Arduino Some time ago I presented you a simple to make, but interesting game, a 1D version simulation of "P...
- XHDATA D-109WB Radio Short Review with complete disassembly Recently I received a shipment of a radio from the brand XHDATA model: D-109WB, so I immediately de...
- Arduino Rotary encoder combination lock (Arduino door lock system with Rotary Encoder) Rotary dial safes typically use a mechanical combination lock. They are valued for their simplicity...
- DIY DRSSTC Music Tesla coil with Interrupter using cheap Driver Module DRSSTC (Dual resonant solid state tesla coil) is a type of Tesla coil that uses solid-state compone...
- Arduino HPDL1414 Retro Clock with Set and Alarm Functions The HPDL-1414 is a 16-segment LED display with four printable fields that is over twenty years old....
- How to turn a 7 inch Elecrow pi terminal into a standalone SDR Radio Today I received the Pi Terminal-7” IPS HMI CM4 Panel All-In-One Module Raspberry Pi Computer from E...
- DIY Simple Functional Lakhovsky MWO (Multiwave Oscillator) Therapy Device The Lakhovsky Multiwave Oscillator (LMO) is a device that was developed by Georges Lakhovsky in the...
- DIY simple Advanced Weather station (5day forecast) and Internet Radio ELECROW crow panel 2.8 inch esp32 display module is ideal for making simple but also relatively com...
- Arduino 3D Printed self Balancing Cube Self-balancing devices are electronic devices that use sensors and motors to keep themselves balanc...
- Tug of War Arduino Game on WS2812 Led strip A Tug of War is a classic team-based game where two opposing teams compete to pull a rope in opposi...
- DIY ESP32 Bioresonance Rife Machine with ZAPPER function Rife machine therapy is an alternative treatment developed by Dr. Royal Raymond Rife in the 1930s. H...
- Arduino VFO Project with a Large LCD Display A Variable Frequency Oscillator (VFO) is an electronic oscillator whose output frequency can be adj...
- Exploring the Tesla Coil Driver Board, Full Review & Test Results Some time ago I presented you a video in which I analyzed a super cheap Tesla Coil driver that cost...
- Arduino Eatrthquake alarm and protection system with D7S seismic Sensor Earthquakes are extremely common events around the world. On average, there are fifty earthquakes a...
-
RGB LED Matrix input module for the Framework Laptop 16
169 0 2 -
-
📦 StackBox: Modular MDF Storage Solution 📦
54 0 2 -
-
-