In this tutorial, we are going create a bot that sends push notification when infrared sensor is triggered. With this kind of technology, it notifies the owner when certain event occurs. Also, we do not need any extra node installation.
Hardware that you gonna use:
- Raspberry Pi 3 with 8GB MicroSD installed with Raspbian OS*
- 3 Female to Female Jumper Wire
- Infrared Sensor or PIR Sensor
- Micro USB Power Adapter or Power Bank
- Screwdriver
*If you don’t know how to install Raspbian OS, you might want to go here
Step 1: Create Your Own Bot
Before we get started, you need to have a Telegram account. You can use your account from web browser or from your phone.
- Open your web telegram and find @botfather at search.
- To start it,type: /newbot
- Follow the instruction given by @botfather such as giving your chatbot name. Follow @botfather until it’s finish, like figure below:
- Tips: it is better to name your bot with “_bot” or ”Bot” at the end of the name.
- Once you finished, create Telegram group and add your bot in that telegram group.
- Upgrade it to supergroup.
STEP 2: Assemble the Wiring
Follow with these schematic:
Raspberry Pi 3 Pin | PIR Sensor |
---|---|
2 | VCC |
7 | Out |
6 | GND |
*Sometime there are some infrared sensors only show “+” instead VCC, but it also can be interpreted as VCC and “-” as GND since that sensor are quite small in size.
STEP 3: Let's NODE-Red it
*Insert micro usb to raspberry pi and wait until it powers up.
Ensure your raspberry pi has internet connection.
Open terminal by clicking the terminal icon at top left or press keyboard “Ctrl+Alt+T”
Type “node-red-start” and copy the IP address
Open web browser and paste the IP address that is shown in terminal.
Drag rpi-gpio-in node from Raspberry Pi Group to Flow.
In node properties, at Pin section, choose number 7(GPIO 04) and Debounce Value set to 500ms and click Done
In Function group, drag switch node to detect if that IR is triggered, into flow and set as below, and Click Done.
In Function group, drag another switch node to select if the value give from GPIO is 0, into flow and set as below, and Click Done.
*Explanation: In this node, node-red checks the value of numbers that are carried from gpio node here, before this node can carried forward to the next node.
- In Input group, drag http request node into flow
Set your http node properties as below:
Method: GET
URL: https://api.telegram.org/bot<YOUR_API_TOKEN>/sendMessage?chat_id=-100<YOUR_CHAT_ID>&text=<YOUR_TEXT>
Name: Chatbot push notification
*Copy your API Token from @BotFather earlier, and paste in <YOUR_API_TOKEN>
**To get chat id from supergroup, go to web telegram and go to your telegram group you have created and at the URL from browser, your chatID is in between letter “S” and character “_”. Copy it and paste is at <YOUR_CHAT_ID>
Connect each node as shown below. And Click Deployto test it.
Now your bot is working but then the bot sends several messages in a second. So, in order to reduce the redundancy of message from chat, we need to drag function node from Function group. And set the property shown below:
And link the function node from IR_Trigger node, and it will look like this.
- Finally click again button Deploy to deploy your final version of bot push notification.
- And you’re done. Congratulation.
Here the screenshot from phone
Congratulations @amir3hamzah! You received a personal award!
Click here to view your Board
Do not miss the last post from @steemitboard:
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @amir3hamzah! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit