Tuesday, October 24, 2017

Reading iButton with Arduino

by / Friday, 03 December 2010 / Published in Arduino

iButtons  readerWe all are familiar with iButton devices - a small chip used as a key almost everywhere:Those keys use Maxim's (formerly Dallas Semiconductor) 1-Wire protocol. It's a nice thing and it is used in many other devices, like temperature sensors (DS18B20, DS18S20 for instance).

As it comes from the name, 1-Wire devices require only one wire for data transfer. Some devices are also capable of using ithis line as a power source. (However, one will still need another wire - for ground).You can attach a large number of devices to the same line. That's especially well when you are using Arduino - OneWire line takes only one digital pin, and you theoretically can plug all you OneWire sensors, keys etc to this line.

 Each iButton key contains a unique 48-bit ID. You can use it the same way as an ordinary key - when you touch contact pad with your key, reader's controller acquires ID of the key and looks for a match in the database. Then, depending on the result, the controller can open the door, raise an alarm etc. You can easily use iButtons in your projects, gadgets - for instance, to lock a PC.

I've created a small sketch that reads the ID from the iButton, and displays it on an LCD, so you don't need the computer to read the key. If you don't have an LCD, simply change lcd.print to Serial.print in the code (and remove library inclusions +lcd.begin(...) instructions).

All you need is an Arduino, iButton (DS1990A), 2.2k resistor, a couple or wires and an 8x2 character LCD (optional). If you do not have iButton contact pad, simply touch the central key's contact with data wire, and outer contact with ground wire.

scheme4ibutton

And here is the sketch.(OneWire Arduino library is required).
Unlike most projects available on the web, my sketch reverses the byte order before displaying it (so you read the ID exactly as it is lasered on the key -

00AABBCCDDEE

instead of

1 EE DD CC BB AA 00

that most similar sketches show to the serial port).

#include <LiquidCrystal.h>
#include <OneWire.h>

OneWire  ds(12);
LiquidCrystal lcd(7,6,5,4,3,2);
byte addr[8];
String keyStatus="";

void setup(void) {
  Serial.begin(115200);
  lcd.begin(16,2);
}

void loop(void) {
  getKeyCode();
  lcd.clear();
  if(keyStatus=="ok"){
      byte i;
      for( i = 5; i >0; i--) {
           lcd.print(":");
           lcd.print(addr[i], HEX);           
      }
  }
  else if (keyStatus!="") { lcd.print(keyStatus);}
 
  delay(1000);
}

void getKeyCode(){
  byte present = 0;
  byte data[12];
  keyStatus="";
 
  if ( !ds.search(addr)) {
      ds.reset_search();
      return;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      keyStatus="CRC invalid";
      return;
  }
 
  if ( addr[0] != 0x01) {
      keyStatus="not DS1990A";
      return;
  }
  keyStatus="ok";
  ds.reset();
}

If you don't have an LCD, simply change lcd.print to Serial.print in the code (and remove library inclusions + lcd.begin(...) instructions).

Basing on these notes, you can create projects that use iButton keys. To begin with: add a check, whether the current key matches the value stored inside the program: if so, turn the LED on. ;)

These instructions are provided 'AS IS'. NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. YOU USE AT YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS INFORMATION. ANY ILLEGAL USE OR APPLICATION OF THIS INFORMATION IS PROHIBITED, THE AUTHOR WILL NOT BE RESPONSIBLE FOR THIS.
Read 6739 times Last modified on Sunday, 08 March 2015 21:11

Do you like this? Please share!

Simon Tushev

Simon is IT professional with interests in web design, electronics, photography and astronomy. He writes about PHP, Yii, Joomla!, Arduino and several other topics.

Welcome!

Here I publish articles related to my areas of interest, my brief notes that may save some time to others, as well as some of my works.

This site is a work in progress. I will add more sections in the future, such as

  • More photos to photogallery
  • More Joomla!-related articles
  • ...

 

themeforest

New Posts

Using dynamic GeoIP module with nginx (CentOS)

nginx introduced dynamic module support in v. 1.9.11. This brief article provides step-by-step procedure...

13-04-2016 in Linux, BSD, Unix

READ MORE

Visual difference between pseudo and true random data

This is is "random" image generated using PHP rand() function: And this is an image...

20-11-2015 in Blog

READ MORE

Best EEPROM practices

(this article is a work in progress). My own advice will be added later...   Having...

12-10-2015 in Arduino

READ MORE
Scroll to top

We use cookies, just to track visits to our website, we store no personal details Privacy policy