Evan Rust
Published © GPL3+

Tweeting Thermostat with Arduino!

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

BeginnerFull instructions provided1 hour5,706
Tweeting Thermostat with Arduino!

Things used in this project

Hardware components

DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Arduino Mega 2560
Arduino Mega 2560
Any 5v Arduino board will work.
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Twitter
Twitter
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Use any 5v Arduino board

Code

Arduino Side

C/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.py

Python
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)

Credits

Evan Rust

Evan Rust

120 projects • 1053 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments