A multi-threaded sensor logger written in C ⚡ that simulates temperature 🌡️, humidity 💧, and light 💡 sensors.
Data from each sensor is collected concurrently using POSIX threads and logged to a CSV file 📑 with timestamps ⏱️.
👉 This project is especially useful as a teaching tool and as a foundation for real-time applications in Embedded Linux 🐧, such as IoT devices, Raspberry Pi data loggers, or sensor gateways.
sensor-logger/
├── bin/ # Executable + generated CSV logs
│ ├── sensor_logger # Compiled binary
│ └── 2025-08-29 17:12:39.csv
├── include/ # Headers and implementations
│ ├── csv_logger.c
│ ├── csv_logger.h
│ ├── threads.c
│ └── threads.h
├── src/ # Entry point
│ └── main.c
└── Makefile # Build script
- 🧵 Concurrent threads for:
- 🌡️ Temperature sensor
- 💧 Humidity sensor
- 💡 Light sensor
- 📑 CSV logger
- 🔒 Thread synchronization using
pthread_mutexandpthread_cond - 📊 CSV file output with timestamp-based filenames
- 🛠️ Easily extendable for real sensors (replace
rand()with hardware drivers) - ⚡ Designed with Embedded Linux real-time logging in mind
makeThis will create the executable in bin/sensor_logger ⚙️.
./bin/sensor_loggerThe program generates a CSV log in the bin/ folder 📂 with the current timestamp ⏱️ as its filename.
Example content:
timestamp,temp,humidity,light
2025-08-29 17:12:41,25.00,60.00,128
2025-08-29 17:12:42,30.00,55.00,200
2025-08-29 17:12:43,28.00,70.00,90- 🖥️ GCC compiler
- 🧵 POSIX threads (
pthread)
✅ Tested on:
- Ubuntu 22.04 🐧
- GCC 11+
- 🛑 Add graceful exit handling (e.g., stop threads on
CTRL+C) - ⚙️ Add configuration file for sampling rate
- 🌍 Replace simulated values with real sensor readings
- 📂 Add JSON/SQLite logging in addition to CSV
This project is licensed under the MIT License — feel free to use and modify it.