This little project aims to provide a small and handy tool to retro fit older devices that signal events via light (LEDs for example). To achive this we use a photo resistor and a small microcontroller to translate the light signal into "on" and "off". The change of state can then be processed further.
As microcontroller a D1 Mini (ESP8266 based) is used. The photo resistor is a GL5528 and additionally a 10kΩ resistor is needed.
The basic layout of the circuit can be found as sketch on a breadboard in the following picture:
This image was created with Fritzing |
The red connections are the 3V3 connection, the blue one is ground. The yellow connection is transfering data (meassuring voltage) and the green one is needed to be able to wake from deepsleep.
As programming language micropython is used.
For more information about using micropython on the D1 mini see here: Quick Start
Micropython knows two special files:
- boot.py which is executed directly after booting.
- main.py which is exectued after boot.py completes.
In this app boot.py is used to load the config parameters from config.json. The main.py holds the logic and executes after all config parameters are loaded.
The config.json holds all parameters for easy configuration of the app.
sleep_time=10000 # the milliseconds to sleep between each measurement
First assemble the circuit as shown above.
Connect the controller to your PC and install the firmware as described here: Install micropython
Edit the config.json and add the parameters you need.
To upload the files you can use ampy. Upload the following files:
- boot.py
- main.py
- data.txt
- config.json