This example demonstrates how to control a 120-volt light by switching a relay with the Raspberry Pi 5 or Raspberry Pi 4. A word of caution: since this project can work with household voltage of 120 or 240 volts, please be careful, as household electricity can be dangerous. Please ensure that you know what you are doing.
The lgpio library can be installed Raspberry Pi OS (6 July 2023) and instructions are available at http://abyz.me.uk/lg/download.html
Install instructions are:
- install Raspberry Pi OS (64-bit)
- Open a terminal and type the following commands:
- sudo apt install swig python3-dev
- sudo apt install python3-setuptools
- sudo apt install libunwind8
- wget https://github.com/joan2937/lg/archive/master.zip
- unzip master.zip
- cd lg-master
- make
- sudo make install
- create a Light example program and copy the program and libraries to the RaspberryPi Desktop
- give the executable permission to run with something like: 'sudo chmod +x Light'
- run the program with something like: 'sudo ./Light'