Language Switcher


Notify LINE when your mail arrives (sleep version)

Make things

Last time, we introduce this article (Notify LINE when your mail arrives!).

This time, we’ll use obniz Board 1Y to update the power-saving mail notification system using sleep.

Notify LINE when the mail arrives

Change it a bit from the previous system and create a system with the following flow.

  1. A tilt sensor is attached to the slot of the mailbox and detects the tilt.
  2. When the mail is placed in the mailbox, the mail slot tilts to detect that the mail has been delivered.
  3. LINE Notify’s API will be used to notify LINE when it detects that mail has arrived.
  4. You’ll be happy to know your mail has arrived at hand!


How to make

Hardware Connection

Connect a tilt sensor to an obniz Board like the table and the image below.

obniz tilt sensor
0 Signal
+ Vcc


LINE Notify

Please refer to “Notify LINE when your mail arrives!” because it has the same steps.

Don’t forget to note token. You cannot get token if you leave the page.


Write the program that notifies through LINE Notify if the mailbox slot is tilted.

  • Replace the LINE_NOTIFY_TOKEN_HERE (line6) with the noted token.
  • Replace the OBNIZ_ID_HERE (line24) with your obniz ID.

Then, install packages of request and obniz from npm.


The program is written in Node.js.

const fs = require(‘fs’),
request = require(‘request’),
Obniz = require(‘obniz’);

const LINE_NOTIFY_URL = ‘’;

const MESSAGE = “郵便物が投函されました。”;
const HEADERS = {
‘Content-Type’: ‘application/x-www-form-urlencoded’,
‘Authorization’: ‘Bearer ‘ + TOKEN

const OPTIONS = {
method: ‘POST’,
headers: HEADERS,
json: true,
form: { message: MESSAGE }

let obniz = new Obniz(‘OBNIZ_ID_HERE’);
let isFirstCall = true;

obniz.onconnect = async () => {

isFirstCall = !isFirstCall;
await request(OPTIONS, async(error, response, body) => {



At the obniz.sleepIoTrigger(false) (line40), enters the sleep state, which is released when the voltage of obniz’s pin 0 goes from HIGH to LOW (see Sleep | obniz.js for details).

The tilt sensor used this time is the mechanism that detects the tilt by contacting the built-in ball when it tilts. When this ball makes contact, pin 0 of obniz is set to LOW, and sleep is released.

Each time the sleep mode is released, a message will be sent to LINE as soon as the mail has arrived from the mailbox.

How to use

Connect the power to the obniz Board and place it behind the mailbox’s drop-off point. At this time, pay attention to the direction of installation so that the sensor responds to the tilt of the lid when the mail is thrown in.

When you run the program, you’ll be notified by LINE Notify every time your mail arrives.

With the sleep feature added to obniz Board 1Y, you can save power and make your system last longer.
There are a lot of benefits, such as reducing the frequency of battery replacement and not having to be aware of the location of the outlet due to power savings. I hope you’ll take advantage of it.