# **衣物雨天守護神** 主要目的為幫忙曬衣服於陽台時,如遇到突發性下雨天,無法即時將衣服收取時,透過Raspberry Pi配合雨滴雨水感測器,通過Line bot的即時通知下雨了,並降下防水簾,防止衣服被雨水淋濕,待雨停了,Line bot會再進行通知雨停了,並將防水簾打開加速乾衣。並可以下指令開關防水簾。 --- 影片Demo --- https://www.youtube.com/watch?v=Mlfh4Z30jZ4  --- 需要材料 --- * Raspberry pi3B * 3.3V 雨水雨滴感測器 * 5V步進馬達加上ULN2003驅動板 * 導線、杜邦線 * 木板、熱熔膠、膠帶、竹筷子、吸管、防水塑膠布 --- Step1 --- 1. 於Line Developer申請一個Channel 2. 存取Channel access token及Channel secret 加入程式中。(參考程式碼修改) ``` line_bot_api = LineBotApi('YOUR_CHANNEL_ACCESS_TOKEN') handler = WebhookHandler('YOUR_CHANNEL_SECRET') ``` 4. Your user ID加入程式中,程式透過line回傳。 `line_bot_api.push_message("Your user ID", TextSendMessage(text='Line顯示的內容!!'))` 5. 下載&申請一個ngrok帳號,然後在終端器上輸入:(依照你的flask port改變數字,我是使用5000),每次重開機都需要修改。 `./ngrok http 5000` 5. 取得https開頭的整串網址,並回到Line Developer,在Message API中更改 Webhook URL,記得要確認輸入正確的網址! `https://取得的網址.io/callback` Step2. 雨滴雨水感測器安裝 --- 1. 將感測驅動板接上Raspberry pi 感測驅動板VCC、GND、DO接至Raspberry pi VCC=>PIN1、GND=>PIN6、DO=>PIN18  正常情況下只會亮一顆綠燈,如亮兩顆綠燈則為異常,請拔掉杜邦線重接。 2. 程式表BCM GPIO24 轉換為 BOARD PIN18 (參考程式碼修改) ``` 原程式碼 GPIO.setmode(GPIO.BCM) Pin_rain=24 改為 GPIO.setmode(GPIO.BOARD) Pin_rain=18 ``` Step3. 步進馬達加上ULN2003驅動板 --- 1. 將步進馬達接上ULN2003驅動板(有防呆裝置) ULN2003驅動板正極接至Raspberry pi的PIN2正極,Raspberry pi 5V的電源。 ULN2003驅動板負極接至Raspberry pi 的PIN6負極 ULN2003驅動板的IN1~IN4接至Raspberry pi 的PIN29,31,35,37   2. 可視實務需求修改正轉反轉步數,每一步等待秒數(參考程式碼修改) ``` forward(2000,0.002) #正轉2000步,每一步等待0.002秒 revers(2000,0.002) #反轉2000步,每一步等待0.002秒 ``` --- 程式碼 --- * 雨水感測自動開關防水簾 `python app_handler_rain0106.py` * 手動開關防水簾 `python app_handler_test1220_2.py` * 程式碼路徑 https://drive.google.com/drive/folders/1J-peYzlwcd6SHZnJK4wTnV1MvpQHxRxO Reference --- * 雨滴雨水感測器 [https://www.gushiciku.cn/pl/p5kV/zh-tw](https://) * Raspberry pi 步進馬達 [http://hophd.com/raspberry-pi-stepper-motor-control/](https://) * Line BOT [https://github.com/line/line-bot-sdk-python](https://) [https://steam.oxxostudio.tw/category/python/example/line-push-message.html](https://)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up