PymateIO-time-relay
Jump to navigation
Jump to search
Abstract
The Time Relay is a very popular application.
Click the button and lights turn on a minute or so.
Click the button while the timer is running just resets the timer (for a full period of time).
Wiring
Here a typical wiring (exactly the same as the "remote control"):
- Push Buttons are connected to IN3 (connected in parallels)
- Stairs lights are controlled by OUT5 (via a relay)
Script
Here an commented example of main.py script that can be used with PymateIO Core.
The TimeoutTimer class is used to start a Timeout of 2 seconds when the button is pressed.
Any additional button press will be ignored within that period of time.
Once the 2 seconds expired, a new button press will be accepted.
from machine import Pin
from pymate import TimeoutTimer
from pymate.pymateio import PymateIO
# 15 sec for demonstration purpose.
# 120 sec (2 min) would be more appropriate.
RELAY_TIME_SEC = 15
button = PymateIO( "In3", Pin.IN )
relay = PymateIO( "Out5", Pin.OUT )
relay.write( 0 )
# Start a timer that expires immediately
t = TimeoutTimer(0.1)
while True:
# Button Pressed
if button.read():
relay.write( 1 )
t.set( RELAY_TIME_SEC )
# Resets the output when timer expires
if t.expired and relay.read():
relay.write( 0 )PymateIO all right reserved © 2026 - Written by MCHobby for PymateIO
