Table of Contents

Sensors

Related to: [HW] Sensors Module

This library contains functions to use different sensors in the HomeLab kit.

Data Types

Infrared distance sensor distance calculation parameters structure. Formula for distance calculation is a / (ADC + b) - k. Structure members:

Constants

Sharp GP2Y0A21YK distance calculation formula parameters.

Functions

Calculates thermistor temperature in Celsius degrees from ADC conversion result. Functions use pre-calculated conversion table. Parameters:

Calculates distance from ADC result received from IR distance sensor voltage. Parameters:

Measures distance with ultrasonic distance sensor SRF04. Function generates a trigger pulse on one pin and measures the time of echo pulse on another pin. Distance is calculated from the time. Function expects a 14.7456 MHz clock frequency. Measuring may take up to 36 ms. Parameters:

Measures distance with ultrasonic distance sensor SRF05 in one wire regime. Function generates a trigger pulse on the pin and measures the time of echo pulse on the same pin. Distance is calculated from the time. Function expects a 14.7456 MHz clock frequency. Measuring may take up to 36 ms. Parameters:

Example

The following program demonstrates usage of IR and ultrasonic distance sensor SRF05.

#include <homelab/module/sensors.h>
 
// Ultrasonic distance sensor control pins.
pin pin_triggerecho    = PIN(G, 0);
 
int main(void)
{
	unsigned short adc_value = 400; // random ADC result.
	signed short distance;
 
	// Distance calculation from IR distance sensor ADC result.
	distance = ir_distance_calculate_cm(GP2Y0A21YK, adc_value);
 
	// Measuring with ultrasonic distance sensor.
	distance = ultrasonic_measure_srf05(pin_triggerecho);
}