Jeopardy! style buzzer game for two players with ATtiny85 chip

My latest project is a Jeopardy! style buzzer for two players. Players press the buttons on either side of the board to activate the buzzer and light the respective LED. Once a player has buzzed in, their LED remains lit for approximately five seconds, during which the other player cannot buzz in. Once the five seconds have expired (and the LED turns off), either player is free to buzz in again.

Image

This project is unique from my previous projects because I have replaced the Arduino Uno board with a low cost ATtiny 85 chip. This chip is similar to the ATMega chip that is the brains of the Arduino Uno, but scaled down. The ATtiny has far fewer digital input/outputs, less memory and runs slower. With a price tag of $2.85 this chip is the perfect replacement for the $25 Arduino Uno, assuming that you using 5 or less inputs/outputs. Additionally, the ATtiny can be powered from a small 3.3 volt coin cell battery, as seen in the above photo.

Here are the materials I used:

(1) ATtiny 85 microcontroller chip

(1) Breadboard

(1) Coin cell battery holder for CR2032 battery

(1) CR2032 battery

(2) Mini push button switches, breadboard compatible

(2) 10mm LEDs (I used 1 red and 1 green)

(2) 10k ohm resistors

(2) 330 ohm resistors

(1) buzzer

Various jumper wires

Here’s a link to the complete list of parts at Sparkfun Electronics: https://www.sparkfun.com/wish_lists/44673. They can be had for around $20.

You’ll need to program the ATtiny85 chip with an Arduino board. The instructions for doing so can be found at the MIT High-Low Tech club site, found here: http://hlt.media.mit.edu/?p=1695. Basically, you configure your Arduino to pass code on to the ATtiny chip.

Here’s the code I wrote the project:

// Jeopardy! style, two person buzzer game for ATtiny85 chip.
// by Joel Swenson, joelswenson at me dot com

#define LED1 1 //LED 1 (red) connected to pin 1 on ATtiny
#define LED2 3 //LED 2 (green) connected to pin 3
#define BUTTON1 2 //button #1 red connnected to pin 2
#define BUTTON2 4 //button #2 green connected to pin 8
#define BUZZ 0 // buzzer to pin 0

int val1 = 0; //stored val for #1
int val2 = 0; //stored val for #2

int old_val1 = 0; //previous stored val for #1
int old_val2 = 0; //previous stored val for #2

int state1 = 0; // initial state of button #1
int state2 = 0; // initial state of button #2

// Setting up input/output for LEDs and buttons

void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
pinMode(BUZZ, OUTPUT);
}

void loop()
//check button 1 and light 1 if pressed
{
val1=digitalRead(BUTTON1); // detect if the button was pressed
if ((val1 == HIGH) && (old_val1 == LOW))
{
state1 = 1 – state1;
delay(10);
}
old_val1 = val1;
if (state1 == 1) // if the button is pressed
{
digitalWrite(BUZZ, HIGH); //activate buzzer
delay(20);
digitalWrite(LED1, HIGH); //light LED
digitalWrite(BUZZ, LOW); //deactivate buzzer
delay(500); // wait 5 seconds to lock out all buttons
digitalWrite(LED1,LOW); // LED off
state1 = 0; // return the button state to unpressed
} else // if button is not pressed. this part might be unnecessary
{
digitalWrite(LED1,LOW); // turn off light
}
//check button 2 and light 2 if pressed
// same code except varibles, button and LED changed for #2
val2=digitalRead(BUTTON2);
if ((val2 == HIGH) && (old_val2 == LOW))
{
state2 = 1 – state2;
delay(10);
}
old_val2 = val2;
if (state2 == 1)
{ digitalWrite(BUZZ, HIGH);
delay(20);
digitalWrite(LED2, HIGH);
digitalWrite(BUZZ, LOW);
delay(500);
digitalWrite(LED2, HIGH);
state2 = 0;
} else
{
digitalWrite(LED2,LOW);
}
}

If you have any specific questions or suggestions about the project please let me know in the comments.

Tagged ,

Introducing @Norfolk_Pine! My Botanicalls plant

I recently acquired a new plant, a Norfolk Island Pine. Of course, I had to install my Botanicalls (http://www.botanicalls.com/) so it could tweet when it needed to be watered. Here’s a photo:

Handsome plant, wouldn’t you say?

So far it hasn’t needed to be watered, but I had it tweet a couple of times for testing purposes. If you’re interested you can follow it’s health @Norfolk_Pine. I won’t think you’re a weirdo for following a plant on twitter. I promise.

Tagged , ,

Twinkle LEDs- Update

In the previous post, I set up nine LEDs to randomly twinkle. While watching my LEDs twinkle, I noticed that one of them wasn’t lighting up. I checked all of the jumper wire connections and they seemed to be fine. After watching them twinkle for a few minutes, I noticed the LED in question did, in fact, work. Instead of waiting patiently, I came up with the following idea to test the LEDs. When the device first turns on, I could have it blink the LEDs in order down the line. Then, you would immediately know if one of them is faulty. Here’s the I came up with:

//Light each LED individually 
 for(int start = 1; start <10; start++) {
 LED_on(start);
 delay(200);
 LED_off(start);
 }

Insert this code at the end of the void setup() section of your code. Now, watch as your LEDs light up one after another. If one doesn’t light up, you know it’s a hardware problem, as opposed to the software just taking it’s time to randomly twinkle that LED.

Let me know if it works for you in the comments or if you have any suggestions. Thanks.

Tagged ,

Twinkle LEDs

Like many of my posts, this isn’t the most practical project. However, the end result is a pretty cool twinkling row of LED lights. I got the idea for the project from this tutorial on Sparkfun (http://www.sparkfun.com/tutorials/312). While the tutorial is for the LilyPad, a sewable micro controller for fabrics, it works fine with an Arduino Uno.

Here’s what you’ll need:

  • 9 LEDs
  • Lots of jumper wires
  • Arduino Uno or similar board
  • Solderless breadboard

And here’s what you’ll do:

You can lay out your breadboard however you choose, but an easy way to do so is to line up the LEDs in a row across the breadboard. For the sake of keeping things organized and tidy, have all the the positive pins of the LEDs (the longer pin) pointing towards the left and the negative towards the right (the shorter pin). Each positive pin on the LEDs will be connected by a jumper wire to a digital input on the Arduino. I’m using digital pins 2 through 10. Each negative pin is connected to the negative rail of the breadboard with one wire on that rail connected to ground on the Arduino. Here a couple of photos to get you started:

It’s a semi-organized mess of wires. There certainly could be a better way of wiring it that would use fewer jumpers, but this gets the job done. Also, I’m completely ignoring the fact that a resistor should be used in each LED circuit. I’m not too concerned about damaging my Arduino. I only plan on running these twinkling lights for a few minutes at a time. If you want LEDs that you could leave twinkling for hours, you’ll have to redesign the circuit to use something like a 330K ohm resistor on the negative end of each LED. So, just be aware that I’m encouraging bad behavior.

On to the software. This I took almost line by line from the SparkFun tutorial. Upload the following code to your Arduino:

// Twinkle code for 9 LEDS
#define LED1 2
#define LED2 3
#define LED3 4
#define LED4 5
#define LED5 6
#define LED6 7
#define LED7 8
#define LED8 9
#define LED9 10
#define interval 11000
#define dead_time 1000
unsigned long PWM_counter = 0;
int offset = 0;
int step_size = 200;
unsigned long on_time = 0;
unsigned long cycle_start = 0;
char dir = 1;
int offset2 = 0;
int step_size2 = 200;
unsigned long on_time2 = 0;
unsigned long cycle_start2 = 0;
char dir2 = 1;
byte LED_tracker1 = 1;
byte LED_tracker2 = 1;
void setup() {
 Serial.begin(57600);
 pinMode(LED1, OUTPUT); 
 pinMode(LED2, OUTPUT); 
 pinMode(LED3, OUTPUT); 
 pinMode(LED4, OUTPUT); 
 pinMode(LED5, OUTPUT); 
 pinMode(LED6, OUTPUT); 
 pinMode(LED7, OUTPUT); 
 pinMode(LED8, OUTPUT); 
 pinMode(LED9, OUTPUT); 
 offset = random(2500,7500);
 offset2 = random(2500,7500);
}
void loop()
{
 PWM_counter = micros();

 if( (PWM_counter + offset - cycle_start) >= interval) { // completed cycle, start over
 on_time += step_size*dir;
 cycle_start = PWM_counter;
 if (on_time >= (interval - dead_time) ) {
 dir *= -1;
 on_time = interval - dead_time;
 }
 else if (on_time <= 0) {
 on_time = 0;
 dir *= -1;
 LED_tracker1 = LED_tracker2;
 while (LED_tracker1 == LED_tracker2) LED_tracker1 = random(1,10);
 offset2 = random(0,4000);
 }
 }
 else if( (PWM_counter + offset - cycle_start) >= (dead_time + on_time) ) { // time to switch LED off
 //digitalWrite(LED1, LOW);
 LED_off(LED_tracker1);
 }
 else if( (PWM_counter + offset - cycle_start) >= dead_time) { // time to switch LED on
 //digitalWrite(LED1, HIGH);
 LED_on(LED_tracker1);
 } 

 if( (PWM_counter + offset2 - cycle_start2) >= interval) { // completed cycle, start over
 on_time2 += step_size2*dir2;
 cycle_start2 = PWM_counter;
 if (on_time2 >= (interval - dead_time) ) {
 dir2 *= -1;
 on_time2 = interval - dead_time;
 }
 else if (on_time2 <= 0) {
 on_time2 = 0;
 dir2 *= -1;
 LED_tracker2 = LED_tracker1;
 while (LED_tracker2 == LED_tracker1) LED_tracker2 = random(1,10);
 offset2 = random(0,4000);
 }
 }
 else if( (PWM_counter + offset2 - cycle_start2) >= (dead_time + on_time2) ) { // time to switch LED off
 //digitalWrite(LED1, LOW);
 LED_off(LED_tracker2);
 }
 else if( (PWM_counter + offset2 - cycle_start2) >= dead_time) { // time to switch LED on
 //digitalWrite(LED1, HIGH);
 LED_on(LED_tracker2);
 }
}
void LED_on(byte LED)
{
 if (LED == 1) digitalWrite(LED1, HIGH);
 if (LED == 2) digitalWrite(LED2, HIGH);
 if (LED == 3) digitalWrite(LED3, HIGH);
 if (LED == 4) digitalWrite(LED4, HIGH);
 if (LED == 5) digitalWrite(LED5, HIGH);
 if (LED == 6) digitalWrite(LED6, HIGH);
 if (LED == 7) digitalWrite(LED7, HIGH);
 if (LED == 8) digitalWrite(LED8, HIGH);
 if (LED == 9) digitalWrite(LED9, HIGH);
}
void LED_off(byte LED)
{
 if (LED == 1) digitalWrite(LED1, LOW);
 if (LED == 2) digitalWrite(LED2, LOW);
 if (LED == 3) digitalWrite(LED3, LOW);
 if (LED == 4) digitalWrite(LED4, LOW);
 if (LED == 5) digitalWrite(LED5, LOW);
 if (LED == 6) digitalWrite(LED6, LOW);
 if (LED == 7) digitalWrite(LED7, LOW);
 if (LED == 8) digitalWrite(LED8, LOW);
 if (LED == 9) digitalWrite(LED9, LOW);
}

That’s it. Afterward you should see all nine LEDs turning off and on randomly for a twinkle effect. Once again, thanks to Dia on SparkFun tutorials for the code and inspiration. Please let me know in the comments if you could think of a practical project that could incorporate these lights, or if you built it and simply enjoy staring into them. Actually, just tell me anything in the comments. I’d like to know that someone else is reading this and may actually find it useful.

Here’s a photo of the LEDs twinkling:

Tagged ,

Garage Door Status Server Prototype

Do you ever wonder if you remembered to close the garage door? With an Arduino micro controller board, an ethernet shield, network connection and a few basic components, you can make a simple web server that detects the status of your garage door.

There are many home automation projects across the internet where an Arduino is used to open and close a garage door. Today, I’m just interested in the most basic part of garage door control: determining whether or not the garage door is open or closed. We’ll leave controlling the garage door remotely for another time. Also, I’m not ready to start running wires in the garage quite yet, so we’ll just build a table top prototype.

Here’s what you’ll need:

  • Arduino Uno or similar board
  • Arduino Ethernet Shield
  • Solderless breadboard
  • One LED
  • One momentary push button
  • Two 320 OHM resistors
  • A few jumper wires
  • ethernet cable
  • USB cable

Step 1: Building the Circuit

The circuit for our garage door status server prototype is simple. Coming off the the Arduino and Ethernet Shield, there is a circuit for the  LED and a circuit for the momentary push button. These share the negative rail for ground connections. Here’s a photo:

Here are the connections:

  • Ground on the Arduino is connected with a jumper to negative rail of the breadboard
  • Pin 3 on the Arduino is connected with a jumper to the positive end of the LED
  • 320 Ohm resistor connects negative end of the LED to negative rail of the breadboard
  • 5 volt pin on Arduino is connected with a jumper to one end of the momentary push button switch
  • Pin 2 on the Arduino is connected with a jumper to other end of the momentary push button switch
  • 320 Ohm resistor connects the other end of the momentary push button to the negative rail

Step 2: Programming the software

First, copy and paste the following code into a new Arduino sketch:
/*
 Garage Door Protype

 Arduino Uno + Ethernet Shield
 Button or switch on pin 2
 LED on 3
 When button is pressed, LED lights, web server reports door closed

 Based on examples from Arduino.cc
 joesgizmos.wordpress.com
 */
// Libraries to be included
#include <SPI.h>
#include <Ethernet.h>
// pins for LED and Switch
const int LED = 3;
const int SWITCH = 2;
int state = 0; // state of switch, high = closed, low = open
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,1, 177); // Static IP needed for webserver
// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
 // Setup input & output pins
 pinMode (LED, OUTPUT);
 pinMode (SWITCH,INPUT);

 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
 ; // wait for serial port to connect. Needed for Leonardo only
 }
// start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.print("server is at ");
 Serial.println(Ethernet.localIP());
}

void loop() {
 // listen for incoming clients
 EthernetClient client = server.available();
 if (client) {
 Serial.println("new client");
 // an http request ends with a blank line
 boolean currentLineIsBlank = true;
 while (client.connected()) {
 if (client.available()) {
 char c = client.read();
 Serial.write(c);
 // if you've gotten to the end of the line (received a newline
 // character) and the line is blank, the http request has ended,
 // so you can send a reply
 if (c == '\n' && currentLineIsBlank) {
 // send a standard http response header
 client.println("HTTP/1.1 200 OK");
 client.println("Content-Type: text/html");
 client.println("Connnection: close");
 client.println();
 client.println("<!DOCTYPE HTML>");
 client.println("<html>");
 // add a meta refresh tag, so the browser pulls again every 5 seconds:
 client.println("<meta http-equiv=\"refresh\" content=\"5\">");

 // Web info goes here
 client.print("The garage door is ");
 if (state == HIGH){
 client.print ("closed");
 }
 else {
 client.print("open");
 }
 client.println("</html>");
 break;
 }
 if (c == '\n') {
 // you're starting a new line
 currentLineIsBlank = true;
 } 
 else if (c != '\r') {
 // you've gotten a character on the current line
 currentLineIsBlank = false;}
 }
 }
 // give the web browser time to receive the data
 delay(1);
 // close the connection:
 client.stop();
 Serial.println("client disonnected");
 }
 // Check state of switch
 state = digitalRead(SWITCH);
 if (state == HIGH) { 
 // turn on LED
 digitalWrite (LED, HIGH);
 }
 else { // turn off
 digitalWrite(LED, LOW);
 }

}
Next, find the following section of code:
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,1, 177); // Static IP needed for web server

For the line beginning with byte mac[] =, put the Ethernet MAC address of your ethernet shield between the curly brackets {}. The MAC address is often found on a sticker on the box or actual ethernet shield. It’s okay to use the default MAC address, if no other device on your network has that exact address. For more about MAC addresses, see: http://en.wikipedia.org/wiki/MAC_address.

For the line beginning with IPAddress, enter an IP address that is open on your network between the parenthesizes. Make sure it’s not an IP address that your DHCP server would give out to another client. 192.168.1.177 should be fine for most simple home networks. For more on IP addresses, see: http://en.wikipedia.org/wiki/IP_address. Remember this IP address for step 3.

Connect the ethernet cable or your network and the USB cable to your computer’s USB port. Upload the sketch.

The device is now properly programmed!

Step 3: Operation

To operate our Garage Door Status Server, navigate your web browser to the IP address you specified earlier. The default is 192.168.1.177.  Here’s what you should see:
This web page shows you the status of your garage door. It defaults to stating that the garage door is open. It also automatically reloads every five seconds and checks the status of the door. Watch what happens when you press and hold the button.
The web server now reports the garage door as being closed and the LED on the breadboard lights up. Notice you have to keep pressing down the button for it to report as closed.
Another item to note is that this web page is only available within your local network. It will take some work with port forwarding on your router to make it available publicly. We’ll leave that for a another post.
And there you have it!
To take this beyond the prototype form, I plan on using a magnetic reed switch to determine if the door is open or closed. It should be as simple as replacing the momentary push button switch with a magnetic reed switch.
Let me know in the comments if this worked for you or if you have any suggestions for improvements.
Tagged , ,

Customizing Botanicalls: Part 3, Alternative Method

As I mentioned in part 2, the Botanicalls Arduino code has not been updated in over a year and that I had to rewrite the code to make it compatible with Arduino 1.01 programming environment. My coding skills aren’t the best, and I believe there may be some minor problems with my alterations. Particularly, my code may be checking too frequently for a DHCP lease and may not properly renew them.  This may, or may not be a problem, depending on your unique home network.

As a workaround to my poor coding skills, I discovered a simple way to customize the original Botanicalls code. It involves downloading an earlier version of the Arduino IDE and installing the now outdated code libraries.  Here are the instructions:

Step 1: Download, install and rename Arduino 0.22

First of all, you’ll need to download version 0.22 of the Arduino IDE software found on Arduino.cc here. Scroll down in the previous IDE versions sections until you find Arduino 0022. Select the correct link for your operating system and download. It’s a 77 megabyte download, so it should take a few minutes depending on your connection speed.

Next, we’ll install and rename the program. It’s important to rename this earlier version of Arduino IDE so that the current version isn’t accidentally over written and so you can tell the difference between the two. I use a Mac, so the installation instructions will be different if you’re using Windows or Linux. Here’s what you’ll see after the download finishes:

Instead of moving the Arduino program to the “Applications” folder, move it instead to the desktop. Then rename the file to “Arduino.22″. Finally, drag it into the “Applications” folder. Now you should have both an”Arduino” and “Arduino.22″ in your applications folder.

While your computer can simultaneously run Arduino versions at the same time, I suggest using Arduino.22 only for customizing your Botanicalls. Sketches saved in Arduino 1.0 (and 1.01) won’t open in Arduino .22 because of changes to the file extensions. Even copying and pasting code between the two may result in some incompatibilities, as libraries and commands have changed.

It’s easy to tell that you’re working in Arduino .22, because the look is different:

Arduino.22

As you can see, the toolbar icons are slightly different, and the overall color of Arduino.22 is dark blue compared to the green tone of Arduino 1.0 and 1.01. Fortunately, the program works in entirely the same manner.

Step 2: Download and install code libraries and Botanicalls Code

Next, you’ll need to download the FTDI cable drivers and the third-party libraries used in the original Botanicalls code. This is similar to the instructions in part 1 of this series.

You can download the FTDI drivers from: http://www.ftdichip.com/Drivers/VCP.htm. Choose your operating system and version, download and install.

Download the following libraries from their respective links:

Arduino Ethernet: http://gkaindl.com/php/download.php?key=ArduinoEthernet

Twitter: http://arduino.cc/playground/uploads/Code/Library-Twitter-1.3.zip

TrueRandom: http://tinkerit.googlecode.com/files/TrueRandom.zip

All of these files need to be unzipped, which is simple enough. The Twitter and TrueRandom libraries are easy to install, simply move the “Twitter” and “TrueRandom” folders to Documents/Arduino/libraries. The Arduino Ethernet library requires an extra step. Open the “Arduino Ethernet” folder and select the “Ethernet DHCP” and “EthernetDNS” folders. Move those to the Documents/Arduino/libraries folder.

All of the libraries are now properly installed. If it is running, you’ll need to quit and reopen Arduino.22 before using them.

Step 3: Obtain a Twitter Token

This step is identical to step 3 in part 2.

Step 4: Downloading the Official Botanicalls code, customizing and uploading.

This final step is similar to what I outlined in step 4 of part 2, but instead uses the Official Botanicalls code and Arduino .22.

First, download the Official Botanicalls software from this link:

http://code.google.com/p/botanicalls/downloads/detail?name=BotanicallsTwitter2_v3.01.zip&can=2&q=

Next, unzip and open the “BotanicallsTwitter2_v.301″ code in Arduino .22. Look for the following line of code:

#define TOKEN “14052394-9gYsPnSXTyw0RFVNKMFU14GwNY9RiJXw6Xt3moTkQ”

As in part 2, replace the text between the quotation marks with your unique Twitter token.

Next, just as in part 2, scroll down in Arduino .22 and look for the following code:

#define URGENT_WATER “URGENT! Water me!”
#define WATER “Water me please.”
#define THANK_YOU “Thank you for watering me!”
#define OVER_WATERED “You over watered me.”
#define UNDER_WATERED “You didn’t water me enough.”

These are the various messages your plant can tweet to you based on the moisture level. To customize the messages, simply change the text between the quotation marks. Remember to keep your messages less than 129 characters. When you’ve finished customizing, be sure to save your changes.

Next, connect the FTDI cable to your computer’s USB port outlined in part 2.

Now, back in Arduino.22, go to the “Tools” menu. Choose “Board” and select “Arduino Duemilanove w/ ATMega 328″.  Then, Choose “File” -> “Upload”. Wait a couple of minutes for the code to upload, and you’re done!

You’ve done it. Now your Botanicalls is both customized and running with the original code.

Please let me know in the comments if these instructions work successfully or if you have any problems.

Tagged , ,

Customizing Botanicalls: Part 2

6/27/12 Update- I’ve updated the Arduino sketch to check the DHCP lease once per hour. Thanks to Simon for the code suggestions.

In part 1, I explained how you’ll need an 3.3 volt FTDI cable or adapter and how to download and install the third party libraries that the Botanicalls Arduino Sketch will use (steps 1 and 2). Here in part 2, I’ll show you how to setup the Botanicalls for use with your own twitter account by getting a twitter token (step 3) and customizing the Arduino code (step 4).

Step 3: Obtaining a Twitter Token:

If you don’t have a twitter account, or want a new twitter account specifically for your Botanicalls, sign up for one at twitter.com. It’s easy and fast.

Next, visit the following website: http://arduino-tweet.appspot.com/. This site coressponds with the Twitter library for Arduino you installed in the previous post. It will create a unique token that your Botanicalls can use to interact with Twitter.

Click on “Step 1: Get a token to post a message using OAuth”. You should see the following page:

Choose “Authorize App”. Doing so gives your Botanicalls permission to tweet on your behalf. (Usually, only humans are allowed to tweet). You may have to enter your Twitter username and password if you are not already logged in. It will return with your Twitter Token, which is a long string of numbers and letters. Copy this token and save it somewhere safe. You’ll use it in the next step when programming the Botanicalls.

Step 4: Download and customize the Botanicalls Arduino sketch.

The Botanicalls software hasn’t been updated in a year and some of the libraries are no longer compatible with the Arduino software. I have modified it to work with the latest Arduino (version 1.01 as June 18, 2012). Please keep in mind that I am not a professional programmer, so this code may not be perfect. I do not foresee any problems with it, but I cannot guarantee it. If that didn’t scare you away, you can download it here.

Hopefully, Botanicalls will make an official update soon and I’ll update this post when that happens.

Download and unzip the file. It should be a folder called “New_Botanicalls_Download”. Add this folder to the folder where your Arduino sketches are stored. On a Mac, it should be <your-username>/Documents/Arduino.

Next, open the Arduino IDE application on your computer. (If you don’t already have it, you can download it from: http://arduino.cc/en/Main/Software). Open the “New_Botanicalls_Download” sketch. You should see something similar to the screenshot below:

Now, we’ll edit the code and do some customization. Look for the line that states:

#define TOKEN “insert your token here! “

Between the quotation marks, copy and paste in your Twitter token from step 3. This will allow the Botanicalls to tweet from the account you want, not the default shared account.

If you’d like to change the messages your plant sends you, scroll down further and find the following lines of code:

#define URGENT_WATER “URGENT! Water me!”
#define WATER “Water me please.”
#define THANK_YOU “Thank you for watering me!”
#define OVER_WATERED “You over watered me.”
#define UNDER_WATERED “You didn’t water me enough.”

These are the various messages your plant can tweet to you based on the moisture level. To customize the messages, simply change the text between the quotation marks. Remember to keep your messages less than 129 characters. When you’ve finished customizing, be sure to save your changes.

Now, to upload the code to your Botanicalls!

First, take your FTDI cable or adapter and connect it to the Botanicalls. The end of the connector with the black wire should be towards to top of the unit, while the green wire should go towards the bottom, as shown in the photo below. Next, connect the other end of the cable to your computer’s USB port. Botanicalls should now power on.

Now, back in the Arduino programming environment, go to the “Tools” menu. Choose “Board” and select “Arduino Duemilanove w/ ATMega 328″.  Then, Choose “File” -> “Upload”. Wait a couple of minutes for the code to upload, and you’re done!

Remember to check your Twitter feed and enjoy your customized Botanicalls! Let me know if you successfully followed the steps or had any problems.

Tagged , ,

Customizing Botanicalls: Part 1

Update: Please note that two of the Arduino libraries mentioned are no longer needed. They are crossed out below.

Now that my Botanicalls is assembled (with the exception of the missing metal probe) and working, the next step is to customize it. You can change it from using the preconfigured twitter feed to your own twitter feed and customize the messages it sends you.

The official Botanicalls website outlines how to customize it here. It’s not entirely straight forward and some additional steps are necessary to make the software compatible with Arduino 1.0.

Step 1: Get a 3.3 Volt FTDI cable or adapter

Unlike an Arduino board, Botanicalls doesn’t have a USB connector, so it cannot communicate with your computer. In order to customize the program, you’ll need a 3.3 Volt FTDI cable or adapter. The main difference between the two is that the FTDI cable connects straight to your computer, while the adapter needs a mini-USB cable to connect to the computer. The adapter has LEDs indicating that is the communicating between the devices and automatically resets the Arduino/Botanicalls after programming it. There are 5 volt cables and adapters available, however, those are not compatible with Botanicalls.

I ordered the FTDI cable from SparkFun for simplicity.

Keep this cable handy for later steps. It will power the Botanicalls, allow you to send it a custom Arduino sketch and show you debugging information.

Step 2: Download and install drivers and libraries

The FTDI cable will need a software driver for your system and the Botanicalls’ Arduino sketch will need four two third party libraries.

You can download the FTDI drivers from: http://www.ftdichip.com/Drivers/VCP.htm. Choose your operating system and version, download and install.

Next, download the libraries. Here are the links:

EthernetDCHP: http://gkaindl.com/software/arduino-ethernet

EthernetDNS: http://gkaindl.com/software/arduino-ethernet

Twitter:  http://www.arduino.cc/playground/Code/TwitterLibrary

TrueRandom: http://code.google.com/p/tinkerit/wiki/TrueRandom

Install these libraries in “libraries” folder in the “Arduino” folder where the sketches are stored.

That’s all for this post. Look for part 2, where I’ll tell you how to modify the libraries to work with Arduino 1.01 customize a new Arduino sketch for the Botanicalls and how to setup a custom twitter account.

Tagged , , , , ,

Botanicalls: A twittering moisture meter for your plant

My latest Arduino project is the Botancialls Kit from SparkFun Electronics. Botanicalls is basically an Arduino micro controller with an integrated ethernet port and plant moisture meter. It tweets the moisture level of your plant and reminds you to water it. (For more information on Botanicalls, see the official website).

At nearly one hundred dollars, it’s certainly an expensive way to remind you to water a single plant. However, I thought it would also be a fun project for practicing soldering and learning more about programming an Arduino.

Here’s what I received in the mail from SparkFun:

Botanicalls Box

And here’s what was inside, laid out and ready to solder:

There’s the leaf shaped circuit board, the ethernet module, five resistors, two buttons, a ATMEGA micro controller chip, various capacitors, headers and other parts, and metal probes for reading the moisture level of the plant.

Note that one of the metal probe is missing. I contacted SparkFun requested that they send me a replacement. I haven’t heard back from them yet, but I’ve received good customer service from them in the past. I fully expect to receive it soon.

Putting it together:

To assemble the Botanicalls Kit, I followed the instructions on the official Botanticalls site, found here:

http://www.botanicalls.com/kits/assemble/

The directions are straightforward and simple. Basically, it tells you where each component goes on the circuit board and give tips how to solder them in. Here’s a few pictures of the soldering process:

The resistors, LEDs, capacitors and buttons were easy to solder. However, the IC pin socket, shown below, was more difficult.

One of the holes for the IC socket was accidentally got a drop of solder in it. So, I couldn’t insert the socket into the board. When I tried to force it, one of the metal pins in the socket popped out. I thought I had broken it. Fortunately, I was able to pop the pin back into the socket. I used a desoldering braid to remove most of the unwanted solder from the hole. I heated up the solder remaining in the hole and inserted the IC socket. It worked, which was a relief.

Here’s a photo of the completed soldering job. It took me maybe an hour and a half to complete.

At this point, I was worried that it was not going to work. I’m not the best at soldering (as the small burn on my finger proves) and after the difficulty with the IC socket, I wasn’t sure if the connections were good.

Plugging in the ethernet and power cables, the green status button turned on. Also, the green and amber lights on the ethernet port lit on. All good signs, but could it send a tweet?

Pressing the test button on the circuit board, the red comm LED lit up for a few seconds. Another good sign.

All Botanicalls are preprogrammed to use a shared twitter account (@botanicallstest). Each has a specific ID number, shown in brackets after the text of the tweet. Mine is 405a. Checking the twitter feed, I discovered that I was successful!

As you can see from the above screenshot, my Botanicalls is reporting a 0% moisture level. Given that it’s not installed in a plant, this is accurate. Success!

My next steps are to wait to receive the replacement metal probe from SparkFun and install the Botanicalls in a plant. Also, I would like to customize it to use it’s own twitter feed, as outlined here on the Botanicalls website.

Tagged , ,

Making Things Talk- Project#1- Update

Last time I posted about my frustrations with the first project, Typing Brighter in Making Things Talk. The problem was that I used a different type of tri-color LED that recommended in the book. Here’s how to modify the code for a common anode RGB LED.

First of all, add the following code to the end of the void setup () section:

// turn pins to HIGH, so that they are off to begin with
 digitalWrite(redPin, HIGH);
 digitalWrite(greenPin, HIGH);
 digitalWrite(bluePin, HIGH);

This code turns all of the bulbs off at the beginning of the program. Thanks to some googling, I figured out the the voltages are the opposite with the common anode LED. So, by default, all of the pins are set to LOW making all of the LEDs on. By setting all of the LED bulbs to HIGH at the beginning of the program, it turns them off.

The next change I figured out in the last post. In the void loop() section, change this code:

brightness = map(inByte, ’0′, ’9′, 0, 255);

to:

brightness = map(inByte, ’0′, ’9′, 255, 0);
 This code change is also because of the opposite voltage. It makes it so entering a ’0′ for the brightness level turns the respective LED bulb off and a ’9′ sets it to full brightness.
While these code changes make the project function as described in the book, it doesn’t fix the problem of the red LED bulb overpowering the others. When the red LED is set to 9, the other bulbs, no matter their brightness level, will go out. I think this is a hardware problem, and can’t be fixed by any code change.
And there you have it. Now the project should function just as in the book.
Tagged ,
Follow

Get every new post delivered to your Inbox.

Join 265 other followers