Tweet with “#obniz”! Flag will shake!

Make things

The flag shake when someone tweets with hashtag “#obniz.”

Materials

How to make

Hardware connection

Connect a Servo Motor to an obniz Board like the table and the image below by referring to Servo Motor Library.

obniz Servo Motor
0 signal
1 Vcc
2 GND

Then, attach a flag to the Servo Motor and connect power to the obniz Board.

Software

Get four keys from Twitter Developer Platform and input these your keys to ConsumerKey , Secret , TokenKey , TokenSecret of the program.

let client = new Twitter({
  consumer_key: 'ConsumerKey',
  consumer_secret: 'Secret',
  access_token_key: 'TokenKey',
  access_token_secret: 'TokenSecret'
});

The program monitors tweets with “#obniz” at this part. The flag will wave if anyone tweets with “#obniz.”

let stream = client.stream('statuses/filter', {track: '#obniz'});

Program

This program is written by Node.js.

const Obniz = require(“obniz”); const Twitter = require(“twitter”); let obniz = new Obniz(“OBNIZ_ID_HERE”); let connected = await obniz.connectWait({ timeout: 10 }); if (connected) { let servo = obniz.wired(“ServoMotor”, { signal: 0, vcc: 1, gnd: 2 }); servo.angle(10); } let client = new Twitter({ consumer_key: “ConsumerKey”, consumer_secret: “Secret”, access_token_key: “TokenKey”, access_token_secret: “TokenSecret” }); let stream = client.stream(“statuses/filter”, { track: “#obniz” }); stream.on(“data”, event => { if (event) { let count = 0; let angles = [10, 50, 10, 50, 10, 50, 10]; let timer = setInterval(() => { count++; servo.angle(angles[count]); if (count >= 6) { clearInterval(timer); } }, 1000); } });