Рет қаралды 22
How to control electronic external devices by your computer - USB , Relay
• How to control electro...
#USBRelay #Automation #TechTutorial #DIYElectronics #SmartHome #RelayControl #PCAutomation
ex 1
import os
Replace this with the correct Device Instance ID from Device Manager
inst = r"USB\VID_090C&PID_1000\6&371EC0B8&0&2"
import subprocess
def usb_power_windows(state):
"""Enable or disable USB power on Windows."""
if state == "off":
command = f"powershell.exe Disable-PnpDevice -InstanceId '{inst}' -Confirm:$false"
elif state == "on":
command = f"powershell.exe Enable-PnpDevice -InstanceId '{inst}' -Confirm:$false"
else:
print("Invalid state. Use 'on' or 'off'.")
return
Run the command
result = subprocess.run(command, shell=True, capture_output=True, text=True)
Check for errors
if result.returncode != 0:
print(f"Error: {result.stderr}")
else:
print(result.stdout)
Example usage
try:
x = int(input("Enter 1 for ON & 2 for OFF: "))
if x == 1:
usb_power_windows("on")
print("USB turned ON")
elif x == 2:
usb_power_windows("off")
print("USB turned OFF")
else:
print("No valid selection made.")
except ValueError:
print("Invalid input. Please enter 1 or 2.")
ex 2
import os
Replace this with the correct Device Instance ID from Device Manager
inst = r"USB\VID_090C&PID_1000\6&371EC0B8&0&2"
def usb_power_windows(state, inst):
"""Enable or disable USB power on Windows."""
if state == "off":
os.system(f"powershell.exe Disable-PnpDevice -InstanceId {inst} -Confirm:$false")
print("USB Power OFF")
elif state == "on":
os.system(f"powershell.exe Enable-PnpDevice -InstanceId {inst} -Confirm:$false")
print("USB Power ON")
else:
print("Invalid state. Use 'on' or 'off'.")
Example usage
x = int(input("Enter 1 for ON & 2 for OFF: "))
if x == 1:
usb_power_windows("on", inst)
elif x == 2:
usb_power_windows("off", inst)
else:
print("No valid selection.")
How to Control USB & Relay Devices from Your PC
USB & Relay Automation: Control Electronics with Your Computer
Mastering USB Relay Control for Home & Industrial Use
Automate External Devices via USB & Relay Modules
Turn Your PC into a Smart Controller: USB & Relay Guide
DIY USB Relay Control: Step-by-Step Tutorial
How to Use a Relay with USB for Smart Automation
Learn how to control external electronic devices using your computer via USB and relay modules! This tutorial explains the step-by-step process to turn your PC into a powerful automation tool. Whether for home automation, industrial applications, or DIY projects, this guide will help you master USB relay control efficiently. Subscribe for more tech and automation tips!
USB relay, relay control, computer automation, USB power switch, home automation, external device control, DIY electronics, smart automation, USB relay module, relay switching, USB controlled relay, Python USB relay, Windows relay control, power control, IoT automation, home tech, industrial automation, smart relay, PC controlled relay, USB electronics, Raspberry Pi relay, Arduino alternative, relay programming, Python relay control, USB power automation, control circuit, USB relay projects, electronics hacking, automation tutorial, USB on/off switch