CDS55 Photoresistor
Loading...
Searching...
No Matches
CDS-55 Photoresistor Module for STM32 (C)

A lightweight C module for reading analog light levels from the CDS-55 (KLS6-3537) photoresistor using STM32 HAL drivers. Designed for polling-mode ADC use, with optional scaled output for control applications like PID loops, logging, or UI display.

Features

  • Supports 12-bit ADC (or higher)
  • Optional scaled output (0–100%)
  • Tracks both raw and scaled values
  • Simple initialization and usage
  • Based on CDS-55 photoresistor characteristics

Target Sensor

  • Model: CDS-55 (a.k.a. KLS6-3537)
  • Light resistance: 18–50 kΩ @ 10 lux
  • Dark resistance: ≥2 MΩ
  • Spectral peak: 540 nm
  • Response time: ~30 ms

Usage

photoCell_t sensor;
photoCell_init(&sensor, true, 200, 3900); // scaled = true, map raw ADC [200–3900] to 0–100
uint8_t light = readSensor(&sensor);
printf("Light: %d (raw: %d)\n", sensor.current_level, sensor.last_raw_value);
````
## File Layout
uint8_t readSensor(photoCell_t *sensor)
Reads the photocell value from ADC and updates the sensor state.
Definition photocell.c:51
void photoCell_init(photoCell_t *sensor, bool scaled, uint16_t min_value, uint16_t max_value)
Initializes a photoCell_t instance with the specified configuration.
Definition photocell.c:34
Definition photocell.h:10
uint8_t current_level
Definition photocell.h:14
uint16_t last_raw_value
Definition photocell.h:15

include/ PhotoCell.h src/ PhotoCell.c examples/ main.c // Example integration with HAL ADC

## License
MIT