Project tutorial
Tweeting Thermostat with Arduino!

Tweeting Thermostat with Arduino! © GPL3+

With Tweepy and Serial, make a tweeting thermostat using the dht11 temperature sensor and Arduino board with Python.

  • 3,927 views
  • 0 comments
  • 9 respects

Components and supplies

Apps and online services

About this project

Welcome to the Tweeting thermostat! To get started, you will need to install a couple of libraries. First, you will use pip and get tweepy. Use: pip install tweepy in your terminal or command prompt. Then you will need to go onto https://apps.twitter.com and sign into your twitter account. From there select "New Application" and fill in the title. You will then need your API keys, so click on your project and scroll to the app settings. From there you can copy and paste your consumer key and secret into the python code. Next, generate an access token and secret. Copy/paste those into the code as well. Head on over to the Arduino IDE and load in the Arduino code. Connect the circuit that is shown in the schematic. For this project I used the Arduino Mega 2560, but any 5v Arduino board will work. Then select your serial port from the "tools" menu. Go back to the python code and change the serial port to whatever port you selected in the Arduino IDE. Go to "Sketch" -> "Libraries" -> "Manage Libraries" -> and search for "dht11". Install it into your IDE and then upload to your board. Run the python code and you are set to tweet your current temperature! It will update every 20 minutes and will avoid duplicate readings. Enjoy your new tweeting thermostat! Here is a picture of mine: 

You can follow my bot at: @BottHavingmc

Happy tweeting!

Code

Arduino SideC/C++
Just copy and paste
#include <DHT.h>

#define DHTPIN 2     // what digital pin we're connected to

#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHT11 Temperature Tweeter!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements. Wait 20 minutes
  delay(1200000);
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);
//print temp data
  Serial.println(f);
  
}
tweetBot.pyPython
Just copy and paste. Fill in all missing areas with your info.
import tweepy
import serial
import time
auth = tweepy.OAuthHandler('<Your consumer key>,<consumer secret>)
auth.set_access_token(<access token>,<access token secret>)

api = tweepy.API(auth)

ser = serial.Serial(<Your Arduino serial port>,9600)
while True:
    temp = ser.readline()
    print temp
    pastTemp = temp
    if temp == pastTemp:
        time.sleep(20 * 60)
    else:
        api.update_status("This is my current temp: " + str(temp))
        time.sleep(20 * 60)

Schematics

Schematic
Use any 5v Arduino board
Dht11

Comments

Similar projects you might like

Arduino LCD Thermostat

Project tutorial by Arduino “having11” Guy

  • 15,383 views
  • 22 comments
  • 30 respects

Thermostat with Relative Humidity Control

by Correia_VSM

  • 1,379 views
  • 0 comments
  • 6 respects

The smart thermostat

Project in progress by Daniel Roman

  • 8,851 views
  • 1 comment
  • 12 respects

Smart Thermostat

Project tutorial by Arduino_Genuino

  • 69,288 views
  • 10 comments
  • 83 respects

Arduino Humidifier Control

Project tutorial by Arduino “having11” Guy

  • 7,633 views
  • 5 comments
  • 6 respects

Thirsty Tweeting Office Plants

Project tutorial by Brian Carbonette

  • 6,949 views
  • 10 comments
  • 29 respects
Add projectSign up / Login