Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Interface SparkFun 9DoF sensor stick with Arduino Uno

By Usman ali Butt February 19, 2021

A decade ago, 2D and 3D accelerometers were commonly used in devices to provide the direction, speed, and GPS localization of an object. An accelerometer is an electronic sensor that measures the acceleration forces acting on an object, typically to determine its position in space and monitor the object’s movement.

Since then, the 3D field has advanced considerably. For example, it’s now possible for such a device to not only assess the acceleration forces acting on an object but also of any objects near it (think of autonomous cars, which must take traffic lights, nearby buildings, other vehicles, and pedestrians into account).

What’s referred to as “nine degrees of freedom,” or 9DoF, now combines 3D acceleration with a 3D gyroscope and magnetometer readings — providing accurate readings of an object’s precise position in 3D space.

In this tutorial, we’ll learn how to interface a SparkFun 9DoF sensor stick with Arduino Uno. A SparkFun 9DoF stick can measure G-force accelerations from 2 to 16, between 245 to 2,000 degrees per second of angular rotation around the axis, and magnetism between 4 to 16 gauss. All the readings are provided along three axes.

Note: The sensor “communicates” with the external modules using an I2C interface. The default I2C address of the magnetometer is 0x1E. For the accelerometer and gyroscope, it’s 0x6B. The sensor board operates on 3.3 volts, which is powered by the Arduino NANO.

Specifically, the sensor is powered with 3.3V of the Arduino NANO’s power regulator output. Arduino NANO’s I2C pins are connected to the sensor’s I2C pins.

Here’s a circuit diagram of the sensor…

The code
For this project, the wire and sensor (SparkFun) libraries are included in the code. A new instance of the sensor library is, therefore, created that acts as the “functions” of the sensor library.

It’s only necessary to declare a few global variables that are shared between the different functions. The variable declination is the angle between the magnetic north and the true north. Its value is fixed. Three functions are also declared. Their purpose is to obtain data from the board for each of the sensor modules.

Arduino NANO’s setup function serial port is activated at 9,600 bits per seconds. Then, the I2C interface starts and the I2C addresses (of each individual sensor) are passed to the board.

The control will remain in the sensor loop until the sensors are started without any fault.

In the loop function, the imu.xxxAvailable() instructions are continuously polling the sensors for updated data. When data is updated in a sensor’s internal memory, the imu.readxxxX() instructions then update the particular xX, xy, and xz variables. To extract the coordinate variables of each sensor, its particular function is called from the main loop.

To extract the coordinates for a sensor, its particular function is called. However, it’s important to understand what happens for each function.  

Each sensor acquires its physical parameters as analog and then converts them to a digital reading. But, this digital value does not correspond to the SI unit of the parameter. So, to properly convert the digital value in an SI unit for a particular physical parameter, the imu.calcGyro(imu.gx) instructions must be called. You can also print the raw values. Simply uncomment the PRINT_RAW global variable and comment the PRINT_CALCULATED.    

Upon opening the serial monitor at 9600bps, you should receive the results displayed below.

The roll, pitch, and yaw are angular movements in the x, y and z directions. With these parameters, it’s easy to locate an object’s position in space.

Where to purchase parts?

  • The Arduino NANO: Mouser
  • The 9DoF sensor — SparkFun: Mouser

Filed Under: Arduino Projects, Microcontroller Projects
Tagged With: Arduino
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Industrial Relay Board Design for Motorcycle Use
  • Finding past posts on edaboard?
  • I think i have devised a new type of "super_transformer" for the Electricity grid?
  • What is the purpose of this relay?
  • mosfet driver problem in regeneration mode

RSS Electro-Tech-Online.com Discussions

  • Sump pit water alarm - Kicad 9
  • Pic18f25q10 osccon1 settings swordfish basic
  • Anyone jumped from Easyeda std to Easyeda pro?
  • turbo jet fan - feedback appreciated.
  • More fun with ws2812 this time XC8 and CLC

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe