8000 GitHub - madworx/rpi_ldr_toy: Minimal LDR driver for Raspberry Pi (Linux)
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

madworx/rpi_ldr_toy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Minimal LDR driver for Raspberry Pi (Linux)

Measure ambient light levels using an LDR and a Raspberry Pi. (But seriously, consider a regular I²C-based lux sensor breakout board like the BH1750 for under $2.)

Circuit and Linux kernel driver that times the charge/discharge of a capacitor through an LDR.

The measured charge/discharge time varies between 100 µs (bright light) and 1500 µs (darkness).

Components

  • LDR: GL5506
  • Resistor: 100 kΩ
  • Capacitor: 0.1μF

Schematics

            \ \
             \ \
              v v

GPIO5 ---+---/\/\/\---+------||------ GND
         |   GL5506   |     0.1uF
         |            |
         |            |
         +---/\/\/\---+
              100kΩ   |
                      |
                      |
                      
                    GPIO6
  • GPIO5: Sets HIGH to charge the capacitor.
  • GPIO6: Detects voltage and measures charge/discharge time.

N.B: Any interrupt-capable GPIO pin can be used for this setup. Ensure the pins are not used by other peripherals, and update the pin configuration in the driver code if necessary.

Kernel driver

Kernel driver exposes /dev/ldr_sensor, for reading the timing data (in microseconds).

The driver measures the time for the voltage across the capacitor to reach the GPIO pin's threshold. This time is proportional to the resistance of the LDR, which varies non-linearly with light intensity. The measured timing is exposed as a readable value in /dev/ldr_sensor. Ensure the kernel module is loaded correctly before reading data.

Source code: see ldr_driver.c.

Build the driver:

$ make

Load the kernel module:

$ insmod ldr_driver.ko

Read the data:

$ cat /dev/ldr_sensor

Example data

Timing diagram plotted over 10 hour period

About

Minimal LDR driver for Raspberry Pi (Linux)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0