RF Pulse Distance Measurement System Using ESP8266 and RTL-SDR

Project Overview

This project aims to create a simple RF-based distance measurement system using an ESP8266 microcontroller to generate PWM pulses, an FM transmitter built with two 2N3904 transistors, and an RTL-SDR receiver to capture the transmitted signals. The system will measure the time taken for a signal to travel to a reflective surface and back, allowing for distance calculations based on the time-of-flight principle.

Components Needed

Hardware Components

  1. ESP8266 Module (e.g., NodeMCU or Wemos D1 Mini)
  2. FM Transmitter Circuit:
    • Two 2N3904 NPN transistors
    • Resistors (e.g., 10kΩ)
    • Capacitors (e.g., 10nF)
    • Inductor (optional for tuning)
  3. RTL-SDR Receiver: USB SDR receiver for signal processing.
  4. Custom Antennas: For both the transmitter and receiver.
  5. Power Supply: Suitable for the components (e.g., USB power bank).
  6. Wires and Connectors: For connections between components.
  7. Breadboard or PCB: For assembling the circuit.
  8. Computer with SDR Software: To process received signals.

Software Components

  1. Arduino IDE: For programming the ESP8266.
  2. SDR Software: Such as SDR# (SDRSharp) or GQRX for signal analysis.

Detailed Steps for Implementation

Step 1: Building the FM Transmitter Circuit

1.1 Circuit Design

The FM transmitter circuit will use two 2N3904 transistors to create a simple oscillator and amplifier configuration.

  • Schematic Diagram:

    +Vcc
      |
      R1
      |
      |-------| 
      |       | 
     C1      C2
      |       |
     ---     ---
     | |     | |
     ---     ---
      |       |
    ----      ----
    |  |      |  |
    |  |      |  |
    ----      ----
     T1       T2
    (2N3904) (2N3904)
      |       |
     Antenna  |
              GND
    
  • Component Values:

    • R1: 10kΩ resistor
    • C1, C2: 10nF capacitors
    • T1, T2: NPN transistors (2N3904)
    • Antenna: A simple dipole antenna tuned to your desired frequency.

1.2 Assembling the Circuit

  • Connect the components on a breadboard according to the schematic.
  • Ensure proper connections for power supply and ground.

Step 2: Setting Up the ESP8266

2.1 Install Arduino IDE

  • Download and install Arduino IDE from the official website.

2.2 Install ESP8266 Board Package

  • Open Arduino IDE, go to File > Preferences, and add this URL to "Additional Board Manager URLs":
    http://arduino.esp8266.com/stable/package_esp8266com_index.json
    
  • Go to Tools > Board > Board Manager, search for "ESP8266", and install it.

2.3 Connect ESP8266

  • Use a USB-to-serial converter to connect the ESP8266 to your computer.
  • Select the appropriate board (NodeMCU or similar) from Tools > Board.

Step 3: Writing Code for ESP8266

3.1 PWM Signal Generation Code

The following code generates PWM pulses on a specified pin connected to the base of the FM transmitter:

const int pwmPin = D1; // Pin connected to FM transmitter base
const int pulseDuration = 100; // Pulse duration in milliseconds

void setup() {
    pinMode(pwmPin, OUTPUT);
}

void loop() {
    // Send pulse
    analogWrite(pwmPin, 255); // Full duty cycle
    delay(pulseDuration);
    analogWrite(pwmPin, 0); // Turn off pulse
    delay(1000); // Wait before sending next pulse
}

Step 4: Setting Up RTL-SDR Receiver

4.1 Connect RTL-SDR Receiver

  • Plug your RTL-SDR receiver into a USB port on your computer.

4.2 Install SDR Software

  • Download software like SDR# (SDRSharp) or GQRX to process received signals.

4.3 Configure SDR Software

  • Set up your software to tune into the frequency used by your FM transmitter (e.g., around 100 MHz).
  • Use a custom antenna designed for optimal reception at your chosen frequency.

Step 5: Implementing Distance Calculation Protocol

5.1 Sending Pulses with Timing

When you send a pulse from the ESP8266, start a timer immediately.

5.2 Receiving Signal with RTL-SDR

Use SDR software to monitor when the pulse is received.

5.3 Calculating Distance

Use the formula:
where:

  • = Time taken for the signal to return.
  • = Speed of light (approximately m/s).

Example Code Snippet for Timing Calculation on Computer:

import time
import numpy as np
from rtlsdr import RtlSdr

sdr = RtlSdr()

# Configure SDR parameters
sdr.sample_rate = 2.048e6 # Sample rate in Hz
sdr.center_freq = 100e6 # Set this to your transmitter frequency in Hz
sdr.gain = 'auto'

# Start receiving samples
print("Starting reception...")

start_time = time.time()

# Read samples and check for pulse (this is simplified)
samples = sdr.read_samples(256*1024)

# Process samples here (detect pulse)
# This could involve analyzing FFT or other methods

end_time = time.time()

# Calculate round-trip time in seconds
round_trip_time = end_time - start_time

# Calculate distance in meters
distance = (round_trip_time * 299792458) / 2 

print(f"Distance measured: {distance} meters")

sdr.close()

Step 6: Testing and Calibration

6.1 Test Distance Measurements

Verify that your RF pulses are being transmitted correctly by monitoring them with SDR software.

6.2 Calibrate Timing Measurements

Ensure accurate timing by comparing against known distances.

6.3 Combine Results

Use both RF distance measurements and any additional data from accelerometers if desired for enhanced accuracy.

Conclusion

This project outlines how to create an RF Pulse Distance Measurement System using an ESP8266, an FM transmitter built with two NPN transistors, and an RTL-SDR receiver. By following these steps, you can build a functional system capable of measuring distances based on time-of-flight principles using RF signals.

If you have any specific questions regarding components, wiring diagrams, or programming examples, feel free to ask!