4CH Relay-board Controlled With Push Buttons

My goal is to upgrade my Anet A8 3D-printer by adding a power supply control via the Octoprint interface. Nevertheless, I also want to be able to start "manually" my 3D-printer, meaning not using the web interface but just pressing a button.

Step 1: The Wiring

The AC-DC PSU is connected with a Smart-plug (TP-Link) which is controllable by means of a smartphone (App Kasa) or a button.

This PSU power the Raspberry Pi 3 B+ by means of a LM2596 DC-DC Buck Converter Module (12V - 5V). The 4-Relay Module 5V with Optocoupler Low-Level-Trigger is directly connected to the RPI 3B+ (no need of 3.3V tuning).

4 Push buttons are connected as "pull-up resistor" to the RPI 3B+.

For the wiring, just have a look to the sketch.

Step 2: The Software

For the control by means of push-buttons, I've used Python to write the program, inspiriting me by reading the following thread:





To insure the interaction with the control via Octoprint, there is a test to check the current status of the relay and change it.

The script is attached.

As the Relay 1 controls the motherboard, I wanted to add a security by switching off with the push-button. The goal was to maintain the button pressed during 5 seconds to confirm the switch-off. Unfortunately, the script works but not reliably due to rebound effect. If you have a correction to suggest feel free to share it.

For the control by means of Octoprint, it's well documented on the web.

There is two steps:

1- Edit the /etc/init.d/octoprint file by adding in the block "do_start()" just after RETVAL="$?:

gpio export 6 out
gpio -g write 6 1

gpio export 13 out

gpio -g write 13 1

gpio export 19 out

gpio -g write 19 1

gpio export 26 out

gpio -g write 26 1

2- Edit the /home/pi/.octoprint/config.yaml file by adding in the block "System":

- action: Relay-1 ON

command: gpio write 6 0

name: Relay-1 ON

- action: Relay-1 OFF

command: gpio write 6 1

name: Relay-1 OFF

- action: Relay-2 ON

command: gpio write 13 0

name: Relay-2 ON

- action: Relay-2 OFF

command: gpio write 13 1

name: Relay-2 OFF

- action: Relay-3 ON

command: gpio write 19 0

name: Relay-3 ON

- action: Relay-3 OFF

command: gpio write 19 1

name: Relay-3 OFF

- action: Relay-4 ON

command: gpio write 26 0

name: Relay-4 ON

- action: Relay-4 OFF

command: gpio write 26 1

name: Relay-4 OFF

Step 3: The Test

It works!

The behavior of the push-buttons is a bit tricky but after a few trials you get it.

Step 4: Finalize the Concept

Now I will solder the push-buttons on a perfboard and add a 5 pins connector.

Finally, I have designed and print 2 cases:

- one for the RPI 3 B+ and the relay-board

- one to cover the wiring at the base of the PSU and to fix the LM2596 DC-DC Buck Converter Module.

You can find the *.stl and *.gcode files on www.thingiverse.com

- https://www.thingiverse.com/thing:3668558




    • Fandom Contest

      Fandom Contest
    • Backyard Contest

      Backyard Contest
    • Beauty Tips Contest

      Beauty Tips Contest