6/24/2011

Temperature-Sensor Network with RTC and LCD Part IV

Are you ready to continue? I have to give an advance warning because the project becomes a bit confusing regarding the Fritzing-Schematics.
Nevertheless I will post the final add-on for the base station just to be complete: the 16x2 backlight LCD. If you are not sure about how to connect a 16x2 LCD there is a fantastic site which will give you full information about this topic: How to connect Arduino with a character LCD. In the meantime this is the current version of the breadboard. 
If you followed up to this point it will be no big effort to connect the last item!

Although we haven't built the remote sensor yet, I will start to show the sketch so you have a break building circuits.

Let's start with some information about the project and the configuration of the Xbees - I already mentioned the base station XBee configuration here.

Sketch Part I: project description, explanation how to configure the XBees (this is done via X-CTU and/ or terminal program):

/* REMOTE AND LOCAL TEMPERATURE SENSOR WITH:
ARDUINO UNO, TMP36, AD22100KT, RTC DS1307, TWO SERIES 2 XBEES
AND 16*2 LCD-DISPLAY
Ver 0.1
by Markus Ulsass
http://lookmanowire.blogspot.com/
*/

/*
*** XBEE CONFIGURATION ***
 

 RECEIVER: (BASE STATION)
 COORDINATOR
 ATID 2001 (PAN ID)
 ATDH 0
 ATDL 0
 ATAP 1 API mode enable
 ATSP AF0 sleep period according to longest sleep period on end device

 SENDER: (REMOTE SENSOR )
 END DEVICE
 ATID 2001 (PAN ID)
 ATDH 0
 ATDL 0
 ATD0 2   pin 0 in analog in mode with TMP36
 ATIR 3E8 sample rate 1000 millisecs (hex 3E8)
 ATSM 4   sleep mode cyclic sleep mode
 ATSP AFO sleep period (AFO = 2800 ms * 10 = 28 seconds)
 ATST 7D0 time before sleep 2 seconds (hex 7D0 = 2000 ms)
 
*/

As mentioned before you should already be familiar with the configuration of the base station ("RECEIVER"), I will now explain the settings for the remote sensor:
  • ATID 2001: We select the same PAN ID for the end device, else we would likely have serious communication problems between coordinator and end device
  • ATDH 0, ATDL 0:  We leave both destination addresses at 0 (no broadcast) to send any information directly to the coordinator
  • ATD0 2: Analog Pin 0 (physical pin 20) is set to analog input mode. Remember the XBee will look for a maximum of 1.2 volt input so you might have to use a voltage divider depending on your analog sensor
  • ATIR 3E8: The periodic I/O Sampling Rate is set to 1000 milliseconds (that's 3E8 in HEX), this means a sample is sent every second from the remote sensor to the coordinator, given that the end device is awake
  • ATSM 4: We set the Sleep Mode to "4" which means we enable the cyclic sleep mode for the XBee end device
  • ATSP AF0: The Sleep Period is set to the maximum of 28 seconds hence we set the parameter to AF0 (HEX) or 2800 milliseconds. Because the sleep period is multiplied by 10 we get our 28 seconds.
  • ATST 7D0: This value sets the Sleep Timer which decrements the given parameter before the end device falls asleep again provided there is no RF signal received. For testing purposes we set this value to 7D0 (HEX) which is 2000 milliseconds. Later we could decrease this value to save energy. For the time being I will keep this value this high, because we could easier get access to the XBee if something goes wrong.
Sketch Part II: including libraries, declaring and initializing values:

// include the library for liquid crystal code:
#include <LiquidCrystal.h>

// include the library for DS1307 RTC connected via I2C and Wire Library
#include <Wire.h>
#include <RTClib.h>

RTC_DS1307 RTC;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int debugLED = 13;            // for debugging purposes only
int analogValue = 0;          // declare and initialize analogValue for remote sensor
float temperatureInside = 0;  // declare and initialize temperatureInside for local temperature

Not a lot to explain, just the settings for the several devices connected and some values set for later use.

Sketch Part III:Setup:

void setup() {
 
  pinMode(debugLED,OUTPUT); //debugging LED set to output

  Serial.begin(9600); // start serial transmission with 9600 baud
  Serial.flush();     // flush the serial port

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  // start Wire and RTC
  Wire.begin();
  RTC.begin();

  // check if RTC is running
 
  if (! RTC.isrunning())
    Serial.println("RTC is NOT running!");

Again the comments should be sufficient to explain the code. If there are any open questions regarding the language check the reference on the Arduino homepage.

I think that might be enough for this time. In the next part we will continue with the sketch and will start with the remote temperature sensor.

6/18/2011

Temperature-Sensor Network with RTC and LCD Part III

We continue with the base station and start to implement the temperature sensor.

There are a lot of temperature sensors available. You could use simple thermistors, analog temperature ICs (like TMP36 or LM335) or digital ones like the Dallas DS18X20 (X stands for S/ B). They all have their pros and cons and I like to experiment with different sensors.

Analog Devices AD22100KT
This time I chose the Analog Devices AD22100KT in a TO-92 package. It's a "Voltage Output Temperature Sensor with Signal Conditioning" and has a large temperature span of 200°C (-50°C to +150°C) a nice linearity and accuracy (according to the datasheet). The datasheet declares an initial error of 0.5°C (at Ta = 25°C, AD22100KT) and a maximum error of 2°C. That sounds much better than the LM335 (at Ta = 25° it's 2°C inital error for LM335, max. 6°C) I worked with at some higher cost for the part and with 60°C more temperature range. Voltage supply is at least 4 (up to 6) volts and quiescent current ist 650µA maximum. As we connect the sensor directly to the Arduino both values are not that important this time (it will be if we connect a temperature sensor directly to the XBee - more on that later).

Datasheet Analog Devices AD22100
You will need a 1k ohm resistor and a 0.1µF capacitor between Vout and the analog input to drive the temperature sensor.
The datasheet also gives insight into the formula we later need to calculate the temperature from our analog readout: Vout = (V+/ 5V) * [1.375V + (22.5mV/ °C) * Ta]. It's the formula where we see the sensor has a temperature coefficient of 22.5mV/ °C (that's techspeak and means the voltage changes by 22.5 millivolts per degree celsius).




The next module ist the Real Time Clock (RTC) DS1307. It's one of Dallas Semiconductor (now Maxim Integrated Products) famous clock-ICs and it's quite easy to build and program. You connect the IC via analog inputs 4 and 5 to the Arduino. That are the I2C pins of the microcontroller and you can use one of the RTC libraries that are available (you can find a great tutorial here).You only need two resistors for the SDA and SCL lines, the 32,768kHz crystal and the 3 volts backup battery (like a Lithium 2032 3 volts coin cell).

Well so far we are almost done with the base station. Please be aware that the left and right power rails of the breadboard are not connected, because the left power rails have 3.3 volts and the right rails are supplied by the 5 volt output from the Arduino UNO.

Arduino UNO with XBee, RTC DS1307 and AD22100KT
In the next part we will finish the base station by connecting the LCD and having a look into the code for the Arduino UNO. In the meantime have fun!

6/13/2011

Temperature-Sensor Network with RTC and LCD Part II

XBee on perfboard
Part II of the temperature-sensor network starts with the Base Station.
The XBee Series 2 sitting on the base station connected to the Arduino UNO is configured in Coordinator API mode. I use the following settings (all other settings are the default Coordinator API setttings of the firmware) which are programmed via the X-CTU software from digi:
  •  AT ID 2001 (PAN ID) (see #1)
  •  AT DH 0 (see #2)
  •  AT DL 0 (see #2)
  •  AT AP 1 (see #3)
  •  AT SP AF0 (see #4)
  1. The extended PAN ID for my network (AT ID = 2001) is 2001 (I hope it will be no "Space Odyssey" though)  - but you can take any 64-bit value up to 0xFFFFFFFFFFFFFFFF or even leave it to 0 where the Coordinator would select a random PAN ID. Be sure to set the same ID to the other devices which should join the network.
  2. The Destination High and Low Address is both set to 0 (AT DH = 0, AT DL =  0) which defines the coordinator.
  3. API mode (AT AP) is set to enable (=1) because we want to receive and parse packets instead of just routing the traffic via the serial port like you would do in transparent mode.
  4. Perfboard back side
  5. The last setting is for the sleep period according to longest sleep period on a/ the End Device(s) (AT SP = AF0). This is to take care that the Coordinator (or any Router which is configured to this length of sleep period) will buffer the messages for the End Device long enough to get them transferred when the End Device awakens (no snooze allowed!). The sleep period is set to 28 seconds on my End Device because the sleep period is multiplied by 10 the value is 2800ms in Decimal or AF0 in Hex.


Unfortunately and for the sake of formality I have to say that my wiring seen in the following picture could be of risk to damage your XBee! As the Arduino UNO runs on 5 volts and the level on the TX pin (digital pin 1) is about 5 volts when HIGH, the DIN pin of the XBee (pin 3) could be exposed to more power than allowed. So I give no guarantee that your XBee is as robust as mine - take care of it and use a level shifter in any case!
XBee with level shifter



Update: For the last days I tested a very simple level shifter, which works for me. I have very low traffic though and there may be problems with higher data transmit rates, but for the time being I just added two resistors (22kohm and 33kohm) as a simple voltage divider and now have maximum roughly 3 volts on DIN of the XBee. So that may be a quick workaround.



Part III will continue with the base station.

6/12/2011

Offroad: XBee Coordinator API + Arduino UNO + RTC +Temperature Sensor + LCD-Display AND Remote XBee (Sleep Mode with low power consumption) + Temperature Sensor - PART I

What a long headline you might think - but this actually describes very well my longer absence to the blog.

I'm sorry to be again off-road to the book, but before starting with the last Connect-Port experiment in Chapter 7 I still have some things on my to-do list that developed from the preceding chapters of the book.

With the knowledge of all the things learned until now I was eager to implement my first own little project to get a simple temperature sensor network (one outside/ one inside temperature) with a real time clock (RTC) and displaying everything on a LCD-display working.
Base Station (breadboard version)

It's consisiting of:


Base Station:
  • XBee in Coordinator API mode
  • connected to an Arduino UNO
  • Temperature sensor connected to Arduino (AD22100)
  • LCD-Display (16*2) connected to Arduino
  • Real-Time-Clock (RTC DS1307) connected to Arduino 
 Remote Sensor:
Remote Sensor
  • XBee End Device Sleep Mode
  • TMP36 temperature sensor connected
  • Voltage regulator MCP1700 (with very low quiescent current <2µA)
  • running on three AA rechargeable batteries



Part II will be on describing the Base Station.