A Simple Arduino Contact Sense Module with Web Output
Lots of quite expensive equipment used in telecommunications, television and
security still use contact sens outputs for reporting error conditions.
This project was put together in the space of 24 hours to allow Nagios to
monitor some contact closures.
Total bill of parts was less than AU$100
The project requirements were:
- simple construction
- fast construction
- easy configuration
- reasonable cost
The final design used:
The EtherTen provided in a single board an Ethernet interface and an SD card
- the SD card provided a simple mechanism for configuring the project. In
particular, it allowed easy configuration of the MAC address and IP parameters
by writing a text configuration file onto the SD card on a separate computer.
Nagios (www.nagios.org) determines
if the contacts are closed using the standard check_http plugin and
checks that the string matches "0 CtctCls" otherwise the plugin
goes critical. Please note that the Arduino does not respond to
ICMP so ensure that a dummy host check is used in the host
configuration.
The sketch (ContactClose.ino):
- Initialises the input pins and pulls them high
- Initialises the serial port for debugging
- Reads the config file "ip.cfg" form the SD card
- Creates a trivial web server
- The loop:
- Reads the digital inputs and constructs an integer based on
the digital inputs (inverted bit shifted)
- if a client has connected a trivial web page containing
the integer and the identifier is returned
The synthesising of the bit map is a result of the physical layout of the
screw terminals and their connection to input pins - the screw terminals used
are based on 0.2 inch dot pitch rather than the usual 0.1 inch - this was
to simplify the hardware for trivial construction.
The sketch employs a custom library (ConfigFile.zip) that parses a simple
key value configuration file. Configuration files may contain comments
delimited by a hash ("#") and terminiated by a new line. Keys and values are
separated by an equals ("=") sign and terminated by a new line. The library employs a simple state machine design.
As with all library files the library should be unpacked in your library folder to install it.
The keys used in the configuration file are:
- mac
- Colon separated mac address
- ip
- IP Address of the Arduino or "DHCP" for auto-configuration
- netmask
- Netmask
- identifier
- 8 character board identifier
- port
- Port to act as web server on Arduino
- gw
- Address of network gateway (optional). If not set the Arduino can
only talk to the local network
Files:
- ConfigFile.zip Library for key value configuration files
- ContactClose.ino Arduino sketch to implement the contact closure and trivial web page
- ip.cfg Sample configuration file to be placed on SD card to configure the web display
Links:
- Arduino - Programming software and environment for board
- EtherTen - Integrated Arduino Uno, SD Card reader and Ethernet
Back to Electronics / Blog:
OddsAndEnds: An Occassional Blog by a Specialising Non-Specialist / Twitter: @MauriceDCastro