1. Home
  2. /
  3. Zephyr-rtos
  4. /
  5. Sensor Reading Example

Sensor Reading Example - Zephyr-rtos Typing CST Test

Loading…

Sensor Reading Example — Zephyr-rtos Code

Read data from a sensor and print values periodically.

#include <zephyr.h>
#include <device.h>
#include <drivers/sensor.h>

void main(void)
{
	struct device *dev = device_get_binding("SENSOR_0");
	struct sensor_value val;

	while(1) {
		sensor_sample_fetch(dev);
		sensor_channel_get(dev, SENSOR_CHAN_ALL, &val);
		printk("Sensor value: %d\n", val.val1);
		k_sleep(K_SECONDS(2));
	}
}

Zephyr-rtos Language Guide

Zephyr RTOS is a scalable, open-source real-time operating system designed for resource-constrained embedded devices. It provides a small, configurable kernel, drivers, and networking stacks to enable IoT, wearable, and sensor-based applications with predictable timing and low memory footprint.

Primary Use Cases

  • ▸Real-time task scheduling for embedded applications
  • ▸Low-power IoT devices and wearables
  • ▸Sensor data acquisition and processing
  • ▸Networking-enabled devices with MQTT, CoAP, or BLE
  • ▸Industrial automation and edge computing

Notable Features

  • ▸Modular and configurable kernel
  • ▸Support for multiple architectures and boards
  • ▸Extensive device driver library
  • ▸Real-time thread management and synchronization
  • ▸Networking stack including Bluetooth, IPv4/IPv6, and 6LoWPAN

Origin & Creator

Initially developed by Wind River and now governed by the Linux Foundation, Zephyr was created to provide a lightweight, open-source RTOS for embedded devices and IoT applications.

Industrial Note

Critical for embedded developers who require a deterministic, low-memory RTOS for safety-critical, battery-powered, or connected devices, enabling rapid development and robust device behavior.

More Zephyr-rtos Typing Exercises

Blink LED TaskPeriodic Thread Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher