Twitter [Ethernet Shield, RTC, TMP36]
This tutorial will allow you to track the temperature using the TMP 36.
The calculated temperature will react accordingly with the twitter: tweet when temperature reaches below 25 degrees Celcius or above 30 degrees Celcius.
Also, a LED would be used to lighten up when the temperature is within a given range.
= Twitter + Temperature sensor + Arduino
The calculated temperature will react accordingly with the twitter: tweet when temperature reaches below 25 degrees Celcius or above 30 degrees Celcius.
Also, a LED would be used to lighten up when the temperature is within a given range.
= Twitter + Temperature sensor + Arduino
#include <SPI.h> // libraries for twitter setup
#include <Ethernet.h>
#include <Twitter.h>
#include <Wire.h> // library for Real Time Clock
#include "RTClib.h"
RTC_DS1307 RTC; // setting the DS1307 up
int temperaturePin = A2; // analog pin to read temperature
// digital pins for the LED
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
// Ethernet Shield Settings (found on the back of your shield, on the white sticker)
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x9D, 0x80 };
// IP address (can be found by running the ip address example in the library)
byte ip[] = { 192, 168, 2, 3 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("1957730400-TXF6G4kDE7Wq8RsRVQClk5VhxRcBFpbwC755LmW");
//setting up specific messages for circumstance b1 and b2
char b1[] = "below 25 degrees Celcius";
char b2[] = "over 30 degrees Celcius";
// setting up a blank message for msg
char msg[] = " ";
void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
Serial.begin(9600); // be sure to check the Serial Monitor for 9600
Serial.print("begin...");
// the temperature sensor will be our input source
pinMode(2, INPUT);
// the 3 LEDs (rgb) will be our output source
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
// making the digitalWrite HIGH as default switches the settings around
// ex) if you want the LED to light up, you have to set it as LOW, not HIGH
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
// void setup for the RTC to gather data
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void tweet(char msg[])
{
// setup for the twitter's connection
Serial.println("connecting...");
if (twitter.post(msg)){
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK");
}
else {
Serial.print("failed : code ");
Serial.println(status);
}
}
else ;{
Serial.println("connection failed.");
}
}
void loop()
{
// temperature setting
int reading = analogRead(temperaturePin); // reading the value of the temperaturePin
float voltage = reading * 5.0; // converting that reading to voltage, for 3.3v arduino use 3.3
voltage /= 1024.0;
// Serial.print(voltage); Serial.println(" volts");
// uncomment if necessary to see the value of the voltage
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
// to degrees ((voltage - 500mV) times 100)
// print the temperature on Serial Monitor
Serial.println(" ");
Serial.print(temperatureC);
Serial.println(" degrees C");
// start RTC
DateTime now = RTC.now();
// print the time on Serial Monitor
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
// setting up specific char for when the temperature is less than 25 degrees
char buffer1[100]; // Could be smaller
sprintf(buffer1, "%s %s %d:%d:%d", b1, msg, now.hour(), now.minute(), now.second());
// setting up specific char for when the temperature is more than 30 degrees
char buffer2[100]; // Could be smaller
sprintf(buffer2, "%s %s %d:%d:%d", b2, msg, now.hour(), now.minute(), now.second());
if (temperatureC < 25) { // if the temperature is read to be lower than 25 degrees Celcius
tweet (buffer1); // tweet the given message, buffer1
digitalWrite (greenPin, HIGH);
digitalWrite (redPin, HIGH);
digitalWrite (bluePin, LOW); // turn on the blue LED
delay(9000); // this delay will prevent you from sending out too many tweets; one tweet per 9 seconds
}
else if (temperatureC > 30) { // if the temperature is read to be higher than 30 degrees Celcius
tweet (buffer2); // tweet the given message, buffer 2
digitalWrite (greenPin, HIGH);
digitalWrite (redPin, LOW); // turn on the red LED
digitalWrite (bluePin, HIGH);
delay (9000); // this delay will prevent you from sending out too many tweets; one tweet per 9 seconds
}
else { // for any temperature between 25 and 30
digitalWrite (greenPin, LOW); // turn on the green LED
digitalWrite (redPin, HIGH);
digitalWrite (bluePin, HIGH);
}
// this delay will allow the Serial Monitor to print out values every 2 seconds
delay (2000);
}