Thursday, May 14, 2026

Part 2: Your Phone Is Already a Robot Sensor (And It's Been Hiding This From You)

In Part 1, we "programmed" our robot's sensor to recognize what's a person, what's a chair, what's a phone...

Now let's go one step further. What if we want our robot to know how it's moving? Is it tilting left, or right? Standing still or spinning? This is where the concept of an IMU sensor (Inertial Measurement Unit) comes in.

Before you go out and buy an actual IMU sensor — guess what's already sitting in your pocket?

Your Android phone.

A modern Android phone works like a professional IMU sensor right out of the box. It already has built-in hardware: an accelerometer, a gyroscope, and a magnetometer. Data from these sensors can be streamed directly to your computer or laptop (and later, to microcontrollers like Raspberry Pi when we start building things that actually do something useful in the real world).

Now, technically, you could write your own Android app to do this. But someone already did the hard work for us. There are dedicated apps that read phone sensors and broadcast the data over Wi-Fi or Bluetooth. We'll use one called HyperIMU.


"Grand" Project #2: Using an Android Phone as an IMU Sensor

Think of HyperIMU as a secret agent — a 007 on your phone, reporting every movement back to HQ (your computer or laptop) in real time.


Download & Install HyperIMU

Get HyperIMU from the Google Play Store.





Step 1: Connect Both Devices to the Same Wi-Fi — Then Find Your PC's IP Address

Make sure your phone and your computer are on the same Wi-Fi network. Then grab your PC's IP address:


  • Windows: Open Command Prompt → type ipconfig → press Enter → look for IPv4 Address (e.g. 192.168.1.10)
  • Mac/Linux: Open Terminal → type ifconfig → press Enter → same idea


Write that IP address down. You'll need it in the next step.




Step 2: Set Up HyperIMU on Your Phone

Open the HyperIMU app. Go to Settings and configure the following:


  • Protocol: Choose UDP — it's recommended for real-time sensor streaming
  • Server IP / Target IP: Enter your PC's IP address from Step 1
  • Port: Set the same port on both devices (e.g. 5000 or 5555)
  • Sensors: Select Accelerometer and Gyroscope





Step 3: Write the Receiver Code on Your PC

Depending on what you want to do with the data, there are a couple of approaches:


  • Python: Use the socket library to write a simple receiver — basically a "phone answering machine" that picks up the call from your Android phone and processes the incoming data in real time.
  • Processing software: For visualization (like simulating your phone as a 3D airplane spinning in space), you can download Processing, install the UDP library, and run a sample sketch.


We'll skip the Processing option for now (even though it's genuinely cool) and focus on building a Python receiver on your computer — something that listens for the "turning, tilting, spinning" signals coming from your Android phone.

In plain terms: once this is set up, if you hold your phone like an airplane and pretend to fly it around — left, right, up, down — the receiver on your computer will print out exactly what's happening. That's it for now. No processing, no action. Just listening.


Create a new project and a new Python file (same as how you made Hello or detect in Part 1). Name it something like receiver.py. Paste the code below — and remember to update the IP and Port to match your setup.


import socket


# Configure IP and Port (must match HyperIMU app)

UDP_IP = "0.0.0.0" # Listen on all interfaces

UDP_PORT = 5000


sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

sock.bind((UDP_IP, UDP_PORT))


print("Listening for HyperIMU data...")

while True:

    data, addr = sock.recvfrom(1024) # Buffer size 1024

    print(f"Received: {data.decode('utf-8')}")

 

Hit Run. You should see something like the screenshot below. To stop, click the red STOP button in PyCharm.




So... does this project do anything impressive? Honestly? Not really. It just prints numbers on a screen.

But here's what actually matters: now you understand something real.

If you use an IMU sensor correctly, your robot will know when it's tilting, when it's spinning, when it's level. That's the foundation of drones and self-driving cars. The fancy stuff isn't magic — it's just this, done properly.


What We Have So Far

Congratulations — you've just completed Robot Project #2, still using nothing but stuff you already owned.

Let's take stock of what our "homegrown" setup can now do:


  • Part 1: The robot sees the world — it knows if there's a person, a phone, or a chair in front of it.
  • Part 2: The robot feels its own movement — it knows if it's tilting left, spinning right, or flying through the air (in your imagination, at least).


With the right sensors and the right code, a robot can know where it is, what's in front of it, and how it's moving.

The world of Robotics is looking for a lot less mysterious now, isn't it?

We're getting somewhere.