0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

お風呂スイッチをラズパイのみに変更

Last updated at Posted at 2023-10-15

変更内容

下記で作った、ESP8266でのお風呂スイッチが壊れちゃいました、もともと、ラズパイのNode-REDでWEB-APIを叩く方式だったので、ラズパイ上にそのままサーボコントロールを書いて、動かすことにしました。

元に記事

https://qiita.com/ABK28/items/062d6d5dd331ba5e7c82

お礼

下記を参考にしました。
っていうか、ほぼそのままです。

ありがとうございます。

# pythonコード

上記サイトを編集して、下記コードを書きました。

import RPi.GPIO as GPIO
import time

INTERVAL = 0.6
PIN = 14
FREQ = 50

GPIO.setmode(GPIO.BCM)

GPIO.setup(PIN, GPIO.OUT)
servo = GPIO.PWM(PIN, FREQ)

#init
servo.start(0.0)

servo.ChangeDutyCycle(2.7)
time.sleep(INTERVAL)

servo.ChangeDutyCycle(4.0)
time.sleep(INTERVAL)

servo.ChangeDutyCycle(2.7)
time.sleep(INTERVAL)

GPIO.cleanup()

/home/ofro-sw/sg90.py として保存しました。

ラズパイの配線

4pin → 電源 5V
6pin → GND
8pin(GPIO14) → 制御線
です。

IMG_8815.jpg

IMG_8816.jpg

試し実行

/usr/bin.python /home/ofro-sw/sg90.py

動いた! 
OKです。

Node-REDの変更

これまで、WEB-APIを叩いてたところを、コマンド実行に置き換えます。

Node-RED_20231015.png

デプロイ

デプロイを忘れずに。

Alexaを試す

「アレクサ! お風呂をつけて」

うぃーーん。

#完成

めでたしめでたし

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?