Tweet-O-Temp – Intermediate Project 1

The Tweet-O-Temp is the first intermediate project I designed. The name basically says all the device does, using a SparkFun Redboard it is possible to read the current temperature and to send it to Twitter at the push of a button.

CS111 Intermediate Project 1- 2

The Tweet-O-Temp is made up of a temperature sensor that is constantly reading the temperature of wherever it is. It does this by taking the voltage running through it and converting it to degrees Celsius and then, since I live in America and we like a different system, it converts the temperature from Celsius to Fahrenheit. The device also has an Adafruit GPS breakout module which constantly is reading the position, time, and date of the device and sending it to the Arduino. The device usually records time in GMT (Greenwich Mean Time), so it had to be converted from this to Chicago Central Time. It would also have to be adjusted manually for daylight savings time too, which at the time of this post is not in effect. Finally it use an Arduino Ethernet shield and an Ethernet cable to connect to the Internet and at the push of a push button it will send the information from the GPS and temperature sensor to Twitter. The device is also set up so that it automatically sends a Tweet at a certain time of the day with the time, date, location, and current temperature.

This was the first assigned project that had no set qualifications, other than simply to experiment with different pieces of equipment and ideas to gain a wider understanding of physical computing. It took me a while to decide what I wanted to do for it. I knew I really wanted to try and use the Ethernet shield so that I could play around with my Redboard sending a message to Twitter. I first heard about this idea when hearing about the device that would Tweet when plants they were hooked up to were low on water. I really liked this idea of sending Tweets from an Arduino so I began to think of device to utilize this ability. Eventually after looking over the parts I had available I thought of the idea of using the temperature sensor and the GPS and using it as my current device is set up.

CS111 Intermediate Project 1- 3

I did run into a lot of problems along the way of designing this project. Originally I had intended for the project to use the Arduino’s built in EEPROM memory to have it so that the system would save the temperature at a given time and then would update it every two minutes. I would then have it that at the push of a different button the circuit would send the stored value and a different message to Twitter. Unfortunately due to the limited memory on the Arduino Uno/ SparkFun Redboard I did not have the space to keep this function working. I did keep the code that should accomplish this task in the main code, but I had to comment it out. If upgraded to an Arduino with more memory it may be possible to then uncomment and use this code. Also due to this shortage of memory the device seems to be unstable sometimes. If the code is reset it will work fine again, but this can be an annoying hassle. I also had to seek out a lot of help on how to organize the code correctly. Several times I would mistakenly misuse integer and float values. The GPS can also be a pain to work with as it has difficulties receiving a signal indoors. Also as stated above it took a little time to get the device to effectively convert to the correct time zone and day, since it would change the day based on the GMT time and not my time zone.

CS111- Intermediate Project 1- 1

If you would like to build your own Tweet-O-Temp keep reading below for parts, schematics, sketches, and code.

Parts:
(1) Arduino Uno/ SparkFun Redboard (a microcontroller with more memory may make the device more stable.)
(1) Arduino Ethernet Shield
(1) Ethernet Cable
(1) TMP 36 Temperature Sensor
(1) Adafruit GPS Breakout (an Adafruit GPS Ultimate Breakout should also work)
(1) Push Button
(1) 10K Ohm resistor
Several wires

The basic schematic and sketch can be seen below.

Intermediate Project 1 schematic

Intermediate Project 1 sketch_bb

You obviously want to put the Ethernet shield over the Arduino/Redboard. Then run five volts into one end of the button, and from the other end have a resistor run to ground and a cable running to a digital input pin, I used 5. This will mean that the current runs into the button and when the switch is open, or the button is unpressed, the current will flow through the resistor into ground. Then when it is closed it will flow into the pin on the Arduino which we set up as an input in the code. Then with the flat end of the temperature sensor facing you you want to run ground on the right, 5 volts on the left, and run the middle to an analog pin, I used A0. This will allow the current to run into the sensor and depending on the temperature it will send a current to the analog pin and the rest will be passed to ground. Then on the GPS you want to run 5 volts to into the VIN pin on the GPS, run the pin labeled GND on the GPS to ground, then run the RX pin to pin 2 on the Arduino and the TX pin to pin 3. This works the similarly running in the five volts into the device and to ground to complete the circuit and using the two pins on the Arduino to receive the information.

The code can be found from the link below

Intermediate_Project_1

The comments on the code explain the majority of how it works, but I will highlight the key feature of how it sends the Tweet. The Arduino monitors the state of the button and when it registers that it has been pushed it will then call the function below. This function works by first calling a function to adjust the time to the correct time zone and day. Then it reads the temperature and depending on what the temperature is will send a message to Twitter. The %d in the message are place holders which will insert the appropriate information and thus make the message actually have the appropriate readings.

void sendTweet(int degreesF) {
  getTime();
  if (degreesF >= 70) {
    sprintf(msg, "Date:%d/%d/20%d  Time:%d:%d:%d It is currently %d °F near %d°, %d°. Look's like a hot one today. Bust out the shorts! - Arduino", GPS.month, GPS.day, GPS.year, GPS.hour, GPS.minute, GPS.seconds, degreesF, int(GPS.latitudeDegrees), int(GPS.longitudeDegrees));
  }

  if ((degreesF < 70) && (degreesF >= 40)) {
    sprintf(msg, "Date:%d/%d/20%d Time:%d:%d:%d It is currently %d °F near %d°, %d°.  LIttle chilly today, better take a jacket with you. - Arduino.", GPS.month, GPS.day, GPS.year, GPS.hour, GPS.minute, GPS.seconds, degreesF, int(GPS.latitudeDegrees), int(GPS.longitudeDegrees));
  }
  if ((degreesF <= 40) && (degreesF >= 0)) {
    sprintf(msg, "Date:%d/%d/20%d Time:%d:%d:%d It is currently %d °F near %d°, %d°.  Better bundle up, looks cold out there. - Arduino", GPS.month, GPS.day, GPS.year, GPS.hour, GPS.minute, GPS.seconds, degreesF, int(GPS.latitudeDegrees), int(GPS.longitudeDegrees));

  }
  if (degreesF < 0) {
    sprintf(msg, "Date:%d/%d/20%d Time:%d:%d:%d It is currently %d °F near %d°, %d°.  It's freezing out there, you should stay in. -Arduino", GPS.month, GPS.day, GPS.year, GPS.hour, GPS.minute, GPS.seconds, degreesF, int(GPS.latitudeDegrees), int(GPS.longitudeDegrees));
  }

  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.");
  }
  delay(3000);
}

As I have already mentioned the project could use some major improvements. Again, using a device with a larger memory should make the circuit more stable. Also it would allow for the ability to store values on the Arduino itself which could make the device more practical when paired with a battery. Also pairing it with a Wifi shield would allow for a another more practical device which could send without being connected to the wall. Also the temperature sensor seems to be touchy about its accuracy. I am not sure it this is a problem in the code or just the device itself, I believe it is the latter. But if this could be improved this would definitely help the device to be more accurate. Also since the GPS device works much better outside it would be much better to build a case for it so that it could be stored outside and then have the button inside for easier access.

Thanks for reading!