Saturday, December 8, 2012

Arduino - starting my own playground.

Arduino - starting my own playground.

I have to admit, I have been skeptical about the Arduino hype for a while. I thought it to be a hobby platform for complete amateurs or technically unsophisticated audience. It sure is, but now I just started to see that it is not a bad thing. It also does not exclude that platform from being useful to a little bit more electronics/programming/technically oriented audience, a category I'd like to include myself in.

It all started the day when my local Radio Shack store had some sale event. I bought an Arduino Uno R3 board and some "getting started" book on Amazon. After reading through few chapters and testing the example sketches I realized how awesome this idea was to create an open micro controller platform, easy to use and create community around it. There are tons of code examples, cheap hardware extensions/shields and there is this free IDE, which is so easy to use. If you hate soldering or you are not into creating highly custom electronic circuits, the Arduino is like the Lego blocks equivalent in the hobby electronics world. You buy the components, connect them together, use one or more of the freely available programming examples as a template for the programming part of your project and you are ready to go!

Since I bought the Arduino Uno board, I bought several shields and electronic kits/modules for arduino that were interesting to me. I got motor shield, Ethernet shield, serial port shield, RTC/EEPROM I2C module, SD card module (SPI), LCD/keypad shield, I2C 20x4 LCD module, another Arduino board (a clone that was included in some bundle) and I am still waiting for Arduino Mega board. This stuff is amazingly cheap and easy to put together and getting to work. Using widely available code examples from internet, arduino web site, arduino IDE or included with the shields/modules that I bought, I was able to test all the modules above in 2 short evening sessions. Just a little bit of soldering was required with some of the shields and modules since some of them arrived in the form of partially assembled kits or with soldering holes for optional pins or sockets.

As an example, I present you with this nice sandwiched circuit, consisting of Arduino Uno R3 board, serial port shield sitting on top of it, the LCD/keypad shield sitting on top of the serial port shield and the I2C RTC/EEPROM module sitting in the socket I soldered into the LCD/keypad module. It took me just few hours to learn this stuff, collect and write the code, solder extra pins and sockets and put it all together:

The program it runs is just a test of RTC module. The date/time is displayed on the LCD and also sent over the serial port:

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

  The LCD circuit:
 * LCD RS pin to digital pin 8
 * LCD Enable pin to digital pin 9
 * LCD D4 pin to digital pin 4
 * LCD D5 pin to digital pin 5
 * LCD D6 pin to digital pin 6
 * LCD D7 pin to digital pin 7
 * LCD BL pin to digital pin 10
 * KEY pin to analogl pin 0

#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
boolean bBlink = true;

void setup () {
  // initialize LCD keypad module
    lcd.begin(16, 2);
    lcd.print("RTC test");       
  // power to i2c_ds1307_at24c32 module provided via A2, A3 pins
    pinMode(A3, OUTPUT); 
    digitalWrite(A3, HIGH);
    pinMode(A2, OUTPUT);
    digitalWrite(A2, LOW);
  // start communication, I2C and RTC

  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 loop () {
    DateTime now =;

    Serial.print(now.year(), DEC);
    Serial.print(now.month(), DEC);
    Serial.print(, DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(now.minute(), DEC);
    Serial.print(now.second(), DEC);
    lcd.print(now.year(), DEC);
    lcd.print(now.month(), DEC);
    lcd.print(, DEC);
    lcd.print(' ');
    lcd.print(now.hour(), DEC);
    lcd.print(now.minute(), DEC);
    if (bBlink)
       bBlink = false;
       lcd.print(' ');
       bBlink = true;

    Serial.print(" since 1970 = ");
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);

    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now.unixtime() + 7 * 86400L + 30);

    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print(future.month(), DEC);
    Serial.print(, DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(future.minute(), DEC);
    Serial.print(future.second(), DEC);


For the rapid project development or ad-hoc circuit testing, Arduino is a great platform that also more technically sophisticated audience can use. Definitely not only for artists and kids learning electronic, as it is categorized by some.
Arduino will stay in my toolbox for the time to come.


I used code samples from following sources:

DS1307 RTC tutorial.

Code sample from eBay listing of Keypad Shield 1602 LCD For Arduino MEGA 2560 1280 UNO R3 A005.

Marek Karcz