Raspberry Pi iButton system

Over the years, I have come across various security door access systems such as keypad access, magnetic strip, RFID tags and iButtons. I have found ibuttons and RFID tags to be the most user-friendly. The basic iButton contains just a unique serial number and advanced models contain various amounts of EPROM, EEPROM, NVRAM, clocks, temperature sensors and so on. The iButton is a chip enclosed in a stainless steel can. The steel button can be mounted virtually anywhere because it is rugged enough to withstand harsh environments, indoors or outdoors. It is durable enough to attach to a key fob, ring, watch, or other personal items and used daily for applications such as access control to buildings and computers.

iButtons can be read using a 1-wire bus. The 1-Wire bus is a system that has a single bus master and one or more slaves. In all instances, the iButton is a slave device. The bus master is typically a microcontroller or PC.
A number of iButton door lock systems are available on the market: Commercial iButton systems
As an engineer, I always aim to design my own system that can be adapted specifically to my application at low cost. A raspberry pi is a low cost standalone computer that could in principle be used as an iButton reader and an access controller. The 1-wire interface on a raspberry pi can be access by using the w1-gpio kernel on linux running on the raspberry pi. The instructions to build a Raspberry Pi iButton are as follows:

Activate the 1-wire bus driver and the GPIO

modprobe w1-gpio
modprobe w1-smem

Set permissions

chmod a+w /sys/devices/w1_bus_master1/w1_master_slaves
chmod a+w /sys/devices/w1_bus_master1/w1_master_remove
chmod a+w /sys/devices/w1_bus_master1/w1_master_search

Connect an iButton probe to the Raspberry Pi as shown below. IButton probes are nothing fancy and can be made easily. I chose to buy one from Farnell. Most major online electronic shops sell them.

ibutton connection

After the connections has been made, try an ibutton on the probe… and have a look in this folder of the raspberry pi:

Et voila! You should see the ID number of the iButton.
I have written a python script to make reading iButton easier. It basically read an iButton and compares the ID with a database. If the ID is on the database, it toggles a pin to high for a few seconds. It also saves the ID of all the iButtons, that make contact with the probe, in a database. My python script is as follows:
import os
import time
import datetime as date
import sqlite3 as lite
import RPi.GPIO as GPIO

os.system('modprobe wire timeout=1 slave_ttl=5')
os.system('modprobe w1-gpio')
os.system('modprobe w1-smem')
base_dir = '/sys/devices/w1_bus_master1/w1_master_slaves'
delete_dir = '/sys/devices/w1_bus_master1/w1_master_remove' 

while True:
 f = open(base_dir, "r")
 ID = f.read()
 inlist = lite.connect('in.db')
 data = lite.connect('accesslist.db')
 curs = data.cursor()
 curs.execute("SELECT * FROM user")
 cursin = inlist.cursor()
 now = time.strftime("%c")
 rows = curs.fetchall()
 if ID != 'not found.\n':
 for row in rows:
   if str(ID) ==str(row[1])+"\n":
     cursin.execute('INSERT INTO listin(name, date) VALUES (?,?)',(row[0],now))
 if ID != 'not found.\n':
   d = open(delete_dir, "w")

I will comment the code when I get some time. For now, happy programming internet people! 🙂


Due to recent updates on the linux kernel, the 1-wire feature is disabled by default. To enable it, add the following line to /boot/config.txt and reboot the Pi.


To speed the reading time:
Edit this file as Sudo
Add this text:

options wire timeout=1 slave_ttl=3

We have now made a simplified updated post on the ibutton system. Check it out.


Add a Comment

Your email address will not be published. Required fields are marked *