Project tutorial
Arduino, IFTTT and Telegram

Arduino, IFTTT and Telegram © CC BY-SA

Arduino sends a simple command through serial port then the pyscript act as server for services like IFTTT or Telegram.

  • 4,724 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

Arduino sends a simple command throgh serial port then the pyscript act as server for services like IFTTT or Telegram

Step1: IFTTT

You may want to register a IFTTT account at https://ifttt.com/join

On IFTTT you must activate Maker and iOS Notification (or similar) channels. When Maker is active you have a key!

When IFTTT is active you have to create a receiver similar to the one I already created.

Step2: Telegram

You have to create a bot, more documentation at https://core.telegram.org/bots

The simplest process is:

  • write him /newbot and follow the instruction
  • get the API key

Almost ready

Now connect Arduino to a USB port of your computer, open IDE and get the name of serial port (something like /dev/tty.usbmodem314)

Download files

open pyscript.py write your correct keys and change the messages!

Complete the easy circuit, load Arduino.ino to your board and finally run python pyscript.py

It works!

Code

Arduino.inoArduino
Main file to load on board
// Hey Emacs, this is Arduino, but you can consider as if it were -*-c++-*-
//******
//*Schetch for Arduino to talk with a server
//*which possibly call an API
//*circuit is simply a button to pin A0
//*

#define buttonpin A0

void setup(){
Serial.begin(9600);
}

void loop(){
  Serial.println(0);
  //if button is pressed server is activated
  if(digitalRead(buttonpin)) Serial.println(1);
  //improve stability  
delay(1);
}
pyscript.pyPython
Works as server on your machine
import serial #serial communication
import time
import requests #API requests

trigger='<event_name>'
IFTTTkey='<key>'
url='https://maker.ifttt.com/trigger/'+trigger+'/with/key/'+IFTTTkey+'?value1=running%20python'
response=requests.get(url)

#open serial port
#change this!
try:
    port = serial.Serial('/dev/tty.usbmodem641',9600)
except:
    port = serial.Serial('/dev/tty.usbmodem441',9600)

#wait Arduino to reset
time.sleep(3)

token='bot123:loremipsum'
id='<chat_id>'
message='Hello IoT!'
#useful to get chat_id
response=requests.get('https://api.telegram.org/'+token+'/getUpdates?limit=5')
url='https://api.telegram.org/'+token+'/sendMessage?chat_id='+id+'&text='+message

port.write('begins')

while True:
    read= port.readline() #read Arduino's Serial port
    print type(read)
    print read
    try:
        intread=int(read)
        if intread==1:
            print 'sent'
            response=requests.get(url)
            print response
            break
    except:
        print read

Schematics

Circuit
Scheme
Scheme

Comments

Similar projects you might like

Telegram Bot with ESP8266

Project tutorial by Team CodersCafe

  • 64,288 views
  • 53 comments
  • 91 respects

Using IFTTT with BLynk

by Kaustubh Agarwal

  • 12,235 views
  • 6 comments
  • 34 respects

Laundry IFTTT Alert

Project tutorial by danvanf

  • 5,379 views
  • 1 comment
  • 13 respects

Snap Circuits® - Snapino IFTTT

Project showcase by Daniel Porrey

  • 4,797 views
  • 0 comments
  • 11 respects

Weather forecast station with LYT led bulb and IFTTT

Project tutorial by Team Authometion

  • 4,166 views
  • 0 comments
  • 2 respects

Telegram Bot Library

by Arduino_Genuino

  • 81,096 views
  • 35 comments
  • 112 respects
Add projectSign up / Login