Building Your First Project: A Smart Motion Tracker
Ready to put everything together?
Section titled “Ready to put everything together?”You’ve mastered the basics, flashed some LEDs, read IMU data, and hopefully enjoyed those gummy bears. Now it’s time to build your first complete IoT device that measures, records, and wirelessly transmits motion data.
By the end of this tutorial, you’ll have a working motion tracker that can log data locally on the SD Card, and stream it live to your computer for real-time visualization. With this, you can build all sorts of awesome movement-measuring projects (e.g fitness trackers, gesture-based controllers, or physics lab equipment).
Some students have used this exact demo to create:
- Fitness rep counters and form analyzers
- Musical gesture controllers
- Physics lab acceleration experiments
- Door entry monitoring systems
- Even a “FitBit for cows” (seriously!)
Part 1: The Code
Section titled “Part 1: The Code”Our motion tracker follows this software flow:
flowchart TD
START([Power On]) --> INIT([Initialize Sensors])
INIT --> SETUP([Setup WiFi & SD Card])
SETUP --> LOOP{ Loop }
LOOP --> READ[Read IMU Data]
READ --> PROCESS[Apply Filters]
PROCESS --> LOG[Log to SD Card]
LOG --> STREAM[Stream via WiFi]
STREAM --> LOOP
The Complete Motion Tracker Code
Section titled “The Complete Motion Tracker Code”Copy this code into your Arduino IDE:
Code Walkthrough
Section titled “Code Walkthrough”Setup Phase:
- Initialize IMU with optimal settings for motion tracking
- Prepare SD card with timestamped CSV file
- Connect to your WiFi network
Main Loop:
- Sample IMU data at 20Hz (every 50ms)
- Apply simple filtering for noise reduction
- Log structured data to SD card
- Stream JSON packets via UDP for real-time visualization
Part 2: Upload and Test
Section titled “Part 2: Upload and Test”1. Configure Your Network
Section titled “1. Configure Your Network”Before uploading, update these lines in the code:
const char* ssid = "YOUR_WIFI_NAME"; // Your WiFi network nameconst char* password = "YOUR_WIFI_PASSWORD"; // Your WiFi passwordconst char* host_ip = "192.168.1.100"; // Your computer's IP address💡 Tip: Finding Your Computer’s IPWindows: Open Command Prompt, type
ipconfigMac/Linux: Open Terminal, typeifconfigLook for your local IP address (usually starts with 192.168.x.x)
2. Insert SD Card and Upload
Section titled “2. Insert SD Card and Upload”- Insert the micro SD card from your kit into the tinyCore
- Connect via USB-C and select your board/port
- Upload the code and open the Serial Monitor
- Watch for startup messages - you should see:
3. Test Motion Detection
Section titled “3. Test Motion Detection”Start moving your tinyCore around! You should see packet count updates in the Serial Monitor every 5 seconds, confirming data is being collected and transmitted.
Part 3: Python Visualization App
Section titled “Part 3: Python Visualization App”Create this Python script to see your motion data in real-time:
import socketimport jsonimport matplotlib.pyplot as pltimport matplotlib.animation as animationfrom collections import dequeimport numpy as np
# Network settings (match your Arduino code)UDP_IP = "0.0.0.0" # Listen on all interfacesUDP_PORT = 12345
# Data storagemax_points = 500timestamps = deque(maxlen=max_points)accel_data = {'x': deque(maxlen=max_points), 'y': deque(maxlen=max_points), 'z': deque(maxlen=max_points)}gyro_data = {'x': deque(maxlen=max_points), 'y': deque(maxlen=max_points), 'z': deque(maxlen=max_points)}
# Setup UDP socketsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)sock.bind((UDP_IP, UDP_PORT))sock.settimeout(0.1) # Non-blocking
# Setup plotsfig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 8))fig.suptitle('tinyCore Motion Tracker - Live Data', fontsize=16)
def update_plot(frame): # Try to receive data try: data, addr = sock.recvfrom(1024) packet = json.loads(data.decode())
# Store data timestamps.append(packet['t'] / 1000.0) # Convert to seconds accel_data['x'].append(packet['ax']) accel_data['y'].append(packet['ay']) accel_data['z'].append(packet['az']) gyro_data['x'].append(packet['gx']) gyro_data['y'].append(packet['gy']) gyro_data['z'].append(packet['gz'])
except (socket.timeout, json.JSONDecodeError): pass # No data received, continue with existing data
if len(timestamps) < 2: return
# Clear and redraw plots ax1.clear() ax2.clear()
time_array = list(timestamps)
# Plot acceleration ax1.plot(time_array, list(accel_data['x']), 'r-', label='X-axis', linewidth=2) ax1.plot(time_array, list(accel_data['y']), 'g-', label='Y-axis', linewidth=2) ax1.plot(time_array, list(accel_data['z']), 'b-', label='Z-axis', linewidth=2) ax1.set_title('Acceleration (m/s²)') ax1.set_ylabel('Acceleration') ax1.legend() ax1.grid(True, alpha=0.3)
# Plot gyroscope ax2.plot(time_array, list(gyro_data['x']), 'r-', label='X-rotation', linewidth=2) ax2.plot(time_array, list(gyro_data['y']), 'g-', label='Y-rotation', linewidth=2) ax2.plot(time_array, list(gyro_data['z']), 'b-', label='Z-rotation', linewidth=2) ax2.set_title('Gyroscope (rad/s)') ax2.set_xlabel('Time (seconds)') ax2.set_ylabel('Angular Velocity') ax2.legend() ax2.grid(True, alpha=0.3)
# Start animationprint(f"Listening for motion data on port {UDP_PORT}...")print("Start your tinyCore motion tracker!")
ani = animation.FuncAnimation(fig, update_plot, interval=50, blit=False)plt.tight_layout()plt.show()Running the Visualizer
Section titled “Running the Visualizer”- Install required Python packages:
- Run the script:
- Start moving your tinyCore - you should see real-time graphs!
Part 4: Testing Your Motion Tracker
Section titled “Part 4: Testing Your Motion Tracker”Experiment Ideas
Section titled “Experiment Ideas”Try these movements and watch the data patterns:
1. Gravity Test
- Place tinyCore flat on table
- Z-axis acceleration should read ~9.8 m/s² (gravity!)
- Other axes should be near zero
2. Shake Test
- Shake the device back and forth
- Watch acceleration spikes in all directions
- Gyroscope should show rotational movement
3. Circle Drawing
- Draw smooth circles in the air
- Look for sine wave patterns in the data
- Try different orientations and speeds
4. Drop Test (Carefully!)
- Drop the tinyCore a few inches onto a soft surface
- You should see a brief period of zero acceleration (free fall!)
Data Analysis
Section titled “Data Analysis”Your SD card now contains CSV files with all your motion data! You can:
- Import into Excel/Google Sheets for analysis
- Use Python pandas for advanced processing
- Calculate total movement, detect patterns, or train ML models
Understanding the Results
Section titled “Understanding the Results”Reading the Graphs
Section titled “Reading the Graphs”Acceleration Data:
- Steady values around ±9.8: Device orientation relative to gravity
- Sharp spikes: Quick movements or impacts
- Smooth curves: Rotational movements
Gyroscope Data:
- Values near zero: No rotation
- Positive/negative peaks: Rotation direction and speed
- Smooth curves: Consistent spinning motion
Troubleshooting
Section titled “Troubleshooting”No WiFi connection?
- Double-check your network credentials
- Make sure you’re on a 2.4GHz network (ESP32 doesn’t support 5GHz)
- Try moving closer to your router
SD card not working?
- Ensure the card is properly inserted
- Try reformatting as FAT32
- Check that the card isn’t write-protected
Python script not receiving data?
- Verify IP addresses match between Arduino code and your computer
- Check that both devices are on the same network
- Make sure no firewall is blocking UDP traffic
What’s Next?
Section titled “What’s Next?”You’ve built a complete IoT motion sensing system! Here are some ways to expand it:
Hardware Additions:
- Add external sensors via the QWIIC connectors
- Connect LEDs or buzzers for motion-triggered alerts
- Attach a battery for portable operation
Software Enhancements:
- Implement Kalman filtering for smoother data
- Add gesture recognition algorithms
- Create a web dashboard for remote monitoring
- Set up cloud data logging
Project Ideas:
- Fitness Tracker: Count reps, detect exercise types
- Security System: Motion-triggered alerts
- Musical Interface: Control sound with gestures
- Physics Experiments: Measure pendulum motion, free fall
- IoT Sensor Network: Multiple tinyCore devices reporting to central hub
Wrap Up
Section titled “Wrap Up”In about 30 minutes, you’ve built a professional-grade motion tracking system that combines:
- Real-time sensor data acquisition
- Local data logging with timestamps
- Wireless data transmission
- Computer-based visualization
- Expandable architecture for future projects
This is the foundation for countless IoT applications. The integrated design of the tinyCore made this possible without breadboard wiring or complex setup – just code, upload, and go!
Now get creative and see what motion-based projects you can dream up. The world needs more makers who can turn ideas into working prototypes this quickly.
**🎉 Achievement Unlocked: IoT Motion Tracker Complete!**You’ve successfully built and programmed a complete wireless motion sensing system. Time to show it off!
**❓ Need Help?**Join our Discord or email support@mr.industries – we love seeing what you build!