LM 335 issues

2.9 volts, 2* 3.3 volts
Those LM335 issues as stated in my last blog entry are still bothering me. I did some additional tests and found out something interesting (at least for me). If the voltage drops below 3 volts, the LM335 begins to post erroneous values. That may be no surprise because the circuit has a typical operating output voltage of 2.98 volts (at 25°C) according to the datasheet (page 2 "Temperature Accuracy").

I wonder if 3.3 volts as used in the preceding experiments are enough power to operate the LM335. I couldn't find any minimum operating voltage specs in the datasheet except an application information on page 6 ("Minimum Temperature Sensing") where V+ is 15 volts for three temperature sensors. My guess is, apart from powering the LM335 with the needed current  through R1 (400µA to 5mA) you need at least 5 volts for stable operation. Tell me if I'm on the wrong track.
I'm also still wondering how to calculate R1, which in my understanding supplies the required current to the LM335. Any input from a reader would be very welcome.
At the moment I'm preparing chapter 6 "Sleeping, then changing the world" where operation with two AA-Batteries is used to power the end nodes. Having the questions above I'm wondering if any operation only from batteries and without voltage regulator is possible at all. The XBees will be no problem - they operate from 2.1 to 3.6 volts according to the datasheet (the PRO needs 3 to 3.4 volts). But what about the LM335?

Update: While surfing the web I found some entries how to calculate R1. As the temperature sensor acts like a voltage divider and everything bases on Ohms law you have to calculate the circuit voltage (in our experiment 3.3 volts) minus the LM335 voltage (depending on the temperature, at 25°C 2.98 volts) and divide it by the needed current (400µA to 5 mA). In short: R1= (Vcc - Vlm335)/ (0.4 to 5mA).
That gives you an envelope which you have to adjust to your expected temperature range.

Sounds a bit confusing? Here are some examples:

Vcc is 3.3 volts, temperature is 25°C (= 2.98volts Vout LM335):

R1 = (3.3V - 2.98V)/ 0.0004A = 800 ohms (400µA = 0.0004A)
R1 = (3.3V - 2.98V)/ 0.005A = 64 ohms (5mA = 0.005A)

So for "room temperature" (25°C) the suggested value of 300 ohms for the circuit works well (everything from 800 to 64 ohms actually should work at least exactly with 25°C ambient temperature according to the datasheet).

What if temperatur changes?

It's 10mV per °K so to reach 3.3V as output from the LM335, everything above 55°C might be a problem because supply voltage almost equals LM335 output voltage (2.73 volts + 0.55 volts = 3.28 volts). At -40°C (= 2,33 volts Vout LM335) and 64 ohms (as calculated above) you would exceed the current with a value of 6.25mA. With 300 ohms you are still safe (3.3mA current for LM335 at -40°C).

So from -40°C to ~55°C and 3.3 volts supply voltage taking 300 ohms for R1 we might be safe.

What if supply voltage changes?

Let's assume supply voltage drops to 2.93 volts generated by two (rechargeable) batteries. At "room temperature" (= 2.98 volts Vout LM335 at 25°C) we might have a problem (at least in a normal climate condition).
Temperature has to drop to about 10°C or lower (2,83 volts Vout LM335) where you could use a R1 from 2 ohms (5mA LM335 current) to 20 ohms (400 µA LM335 current). With the suggested 300 ohms you would fall below the required current for the LM335.

The options:
  1. You could use a second power supply/ step-up converter with at least 3.8 volts (according to the datasheet the LM335 operates up to 100°C). You might have to adjust the resistor value for R1 to your expected temperature range. Same for digital sensors like DS18S20/ DS18B20 because power supply ist 3 to 5.5 volts according to the datasheet.
  2. Take an alternative temperature sensor like the TMP36. This part needs a supply voltage from 2.7 to 5.5 volts which would be almost perfect for two-batterie powered devices and maybe also for a two rechargeable batterie-pack if the voltage stays above 1.35 volts each (I'm not sure how low the voltage might drop before the TMP36 quits working).
For more insight on temperature sensors there is a great tutorial at Ladyada.net.


Hot and cold bee(r)s

Voltage regulator, XBee, LM335
One of the most common applications (with microcontrollers) is measuring temperature. Whether it's the current outside temperature, the climate in your freezer or for controlling the heating installation in your house - you will need at least a thermal sensor. With XBee you need no long wires at all and additionally you can create a temperature network around the house and display everything on your computer (with a little help of Processing). Awesome!

LM2937ET-3.3 (top), LF33CV (bottom)
That's what the "Simple Sensor Network" is about in chapter 5. New to the game are 3.3 volt regulators and the very ubiquitous temperature sensor LM 335 (Datasheet). I couldn't get the recommended LD1117V33 and bought two different voltage regulators instead - LM2937ET-3.3 and LF33CV . Two different ones because I wanted to test how much power they use while regulating and which one would be better for any power saving mode, if there is a difference at all (more on that later). In any case check the order of the legs - in my case for both regulators from left to right with the writing on the front: IN, GND, OUT (the LD1117V33 has GND, OUT, IN).

Update 5-15-2011: I was revisiting the voltage regulator wiring as I was beginning the "Direct Actuation Example" in Chapter 6, pages 172 following. It looks like the LD1117V33 is wired the wrong way in Figure 5-6. According to the datasheet the legs are GND, Vout and Vin when viewed from the front. The upper rail for GND  in Figure 5-6 is connected to Vout, Vcc 3.3 volts is connected to Vin. It also looks like the capacitor and the hookup wires from the power plug are connected the wrong way. So be careful and double check the whole voltage regulation for this experiment. The text and figures 5-4 and 5-7 seem to be ok. I submitted it to the Errata and got the following answer:
"Unfortunately 3.3V regulators do not have standardized lead arrangements. As the instructions say on page 145, 'The regulator has three legs - typically, ground, output, and input - when viewed from the front (where the writing is). Sometimes these legs are in a different order, so find and check the data sheet if you're not sure!'
Fritzing uses one of the alternate pin arrangements (IGO). We can bring this up with them and redo the diagram in a future printing, but the caution still applies." 
Setting up the three XBees is a nobrainer - the AT commands are very well explained in the same chapter so no surprise at all. If you haven't done so it's now time to solder another breakout board for the new XBee. Then everything has to be placed on the breadboards.

There is little room near the voltage regulator if you take (bigger) capacitors (e.g. suited for higher voltages) - Figure 5-4 looks a bit crowded near the regulator. I took capacitors with a small form factor rated for 16 volts which might be more than enough. Anyway you could place them as suggested in Figure 5-6 (page 149) then you have more room for everything. I'm not sure the capacitors should be very near the regulator, maybe someone out there could answer this question.

Be aware that the resistor connected to the + (middle pin) of the LM335 is 300 ohms and not 300 kohms as described in figure 5-6 and 5-7.The voltage regulator (labeled with "7833") and the temperature sensor are both labeled "U2" in Figure 5-7 - only a minor typo - but you should "cut" the ground connection from Pin1 (XBee) and the voltage regulator. Figure 5-6 shows the correct connections.

Next is installing "Processing". Everything went fine on my computer and I only had to replace the COM-port entry which is "COMx"  (x stands for the port number) in Windows. I had two sensors connected and after starting the Simple_Sensor_Network.pde everything took place like it is described in the book. There was only one error in the lower window: "[XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.PacketStream] Found unescaped special byte base10=19,base16=0x13,base2=00010011 at position 4". The program worked anyway.

One thing you really have to think about if you are planning to use the LM335 is calibrating the sensor. I have five sensors and some are "wrong" up to 3 degrees centigrade. I also had some trouble calibrating the sensors and it looked like they were still shifting after calibrating them. In the past I used to take the (digital 1-wire) DS18x20 temperature sensors - I'm still not sure if there is a way to connect them directly to the XBee and send the data to the coordinator for displaying it on the computer (another new item on my TO-DO-list).


Happy Easter!

Currently I'm working on the "simple sensor network". Well, this is how it sometimes looks like in my shop while working on the projects. But this time strange objects found their way on the table!

Happy Easter!


Twilight Bee

Chapter 4 shows how to use the XBee direct without help of the Arduino (at least on the sensor side). This was one thing I was really waiting for, because getting rid of the microcontroller makes the whole thing much smaller and less energy consuming (and also cheaper!). There is no logic in the XBee used in the book, but you can already do a lot of things with the existing digital/ analog pins.

Romantic lighting sensor
For the "romantic lighting sensor" a LDR (for more background read this fantastic LDR tutorial) is used as the sensor connected to the XBee. Theory: The "data" is acquired by a voltage divider which ideally and depending on the fixed resistor puts out a voltage of up to 1.2 volts.

I had some LDRs on stock which had values of about 1 kOhm at 100 lux and about 8 kOhm at 10 lux (the darker the more resistance). This was almost equal to the LDRs recommended in the books parts list (page 94) so I could also use the 20kOhm resistor. Could I?

added lines of code to print the values
Although everything is described very well in the book I had to really think about this whole voltage divider idea. I finally think I found (my) error. Until now I always connected the variable resistor to Vcc and the fixed resistor to ground in other experiments. So if the resistance went down (brighter light) the higher the value on the anlaog input pin on the microcontroller and vice versa. The code on pages 101-103 says exactly this. But this time the values were inverse. The brighter the light the lower the resulting value/ volts.

In my example this meant (I added some lines of code to get the results in the serial monitor):

~ 100 lux

~ 100 lux: analogValue of 97 (0.11 volts)
~ 10 lux: analogValue of  611 (0.71 volts)

In the experiment the LDR is connected to ground and the fixed resistor to Vcc. If I calculate the formula:

Vout = (R2 (LDR)/ R1 (fixed resistor) * R2 (LDR)) * Vin

~ 10 lux

I get (at ~ 100 lux, LDR resistance ~ 1 kOhm, fixed resistor = 20 kOhm):
Vout = (1 kOhm/ 20 kOhm + 1 kOhm) * 3.3 volts
Vout = 0.157 volts

for ~ 10 lux (LDR resistance ~ 8 kOhm):
Vout = (8 kOhm / 20 kOhm + 8 kOhm) * 3.3 volts
Vout = 0.94 volts

The calculated values show the same trend I found in the practical excercise.

LDR covered to lower the brightness
The funny thing is that the experiment exactly works as it should be. If it's too bright (in my case at about 20 lux) the light goes out and if it's too dark (< 10 lux) the same. In between the LED is on.

I'm kind of stuck now with this experiment. Do I have an error in reasoning or should the code tell exactly the inverse: analogValue low = too bright, analogValue high = too dark)?

Anyone to the rescue?

230 volts power switch interface

For the "direct actuation example" (chapter 6) I still needed an alternative for the power switch tails (SFE COM-09842) because in europe there is largely 230 volts in the power grid.

Parts of SI 230-2
I found the SI 230-2 230 volts switch interface at ELV (thanks to Olli!) which you can either assemble by yourself (14,95 Euro/ ~ $21.53) or buy the already assembled part (24.95 Euro/ ~$35.90). I chose to build it by myself and it's quite easy to solder and put together. No SMD parts and everything fits very well. Only the instructions could be a bit more detailed.
You can switch the interface with 4-18 volts DC (6-48 mA) with a maximum switching frequency of 0.5 Hz which means you can switch every second or longer.
Assembled SI 230-2
It operates up to 230 volts with 16 amps - so you could drive almost everything needed in the house. The switch input socket is for a 3.5mm audio mono jack plug.

In the meantime I also built the "romantic lighting sensor" and will post the results in a few days.


Buzz LightBee

Arduino meets XBee.

After some Arduino basics, installing the IDE was quite easy. You only have to watch for installing the windows drivers for the Arduino Uno board. That's what I forgot, but after reading the IDE-installing-tutorial everything went fine.

If you already did some programming in C or any similar language and played with some microcontrollers the IDE and language look quite familiar. If questions arise, there are a lot of tutorials and information available not only on the Arduino Homepage but in serveral other Arduino communities and information sites (s. page 64/ 65) around the web.

Next is heating up the soldering iron because the breakout boards have to be finished. If you plan to order the breakout boards from Sparkfun pay attention to the wrong part number in the parts list on page 67. The right part number is "BOB-08276". If you have to order additional electronics parts like LEDs or resistors, consider buying the 2.54mm/ 0.1" headers and the 2mm female headers there. They might be much cheaper there.

Fixing the male headers
Third hand tool
A very good advice mentioned in the book is putting the male headers into a breadboard and then putting the breakout board on top and soldering both together. After that you can put the female headers into the breakout board, turn it upside down and use a third hand tool to solder the female headers.

3.3V voltage check
Wiring the boards together is quite easy because there aren't that much connections. Just remember to unplug the wire into RX (pin 0) on the Arduino before uploading the compiled code. Also a good advice is checking the voltage BEFORE putting the XBee on the breakout board. One drawback in the printed (black & white) edition is that Vcc/ GND (+/-) are not labeled, so you have to take care when wiring everything together. Any labeling in future (printed) editions would be a great help.

Button system
If you don't want to buy the long jumper wires, you can solder them easily by yourself by connecting any adequate wire and a single headerpin of the male 0.1" headers, solder both together and put a heat shrink tube over the connection.

There is not much more to say about the button and the bell system. Everything is described very well, so I did not hit any roadblock. Except I first had a buzzer which draw too much current and didn't buzz but sounded more like whining, I had no issues at all. After replacing it with a 5mA type, the buzzer was clearly audible.


Offroad: With RSSI one XBee finds the other

I like manuals.

After my first very basic range experiments (see previous blog Bee-Chat) I questioned myself if there is a more accurate way to determine signal strength. Of course there is and you only have to look into the XBee manual.
Search for "RSSI" (RX Signal Strength Indicator) and you will find at least two sections where the RSSI function is described in detail.

For example in AT-mode, which means the XBee is either capable of command or transparent mode, you could type in "hello" then put the XBee in command mode with "+++" and then enter "ATDB". You get a hexadecimal value which "returns the RSSI value (measured in –dBm) of the last received packet". This only works if there is a direct connection, but for the moment this is the case and it does the job.

Very simple distance check
The lower the value the better. 

I got hexadecimal "1A" when laying two XBees side by side. As far as I understand this means -26dBm. I tried some other positions (inside my house) and the value went up to hexadecimal "5C"/ decimal 92 in the corner furthermost away.

This opens a lot of options for future applications.

If you are one of those people who regularly forget where they left their keys, two XBees could help. Or you need any sort of very simple distance meter (yes, radio waves are not that great for accurate distance measurement), proximity sensor or whatever application where a raw value of distance of two things is needed - two XBees would do. A lot of things might be possible with this already embedded function...



After I could configure one XBee module to communicate via the serial terminal application Tera Term (Hyperterminal/ Windows XP also worked for me) the next step in the book was the "Basic XBee Chat".
I wrote down the low bit of the 64-bit address of each XBee and set up everything as described (PAN ID, ATDH and ATDL). I programmed everything with ATWR to the modules and double checked the configuration by typing in the AT commands without values.
I connected both XBee modules with the computers and both responded to my inputs in Tera Term.

Time to chat.

Nothing happened. Uh.

Finally I ran into trouble (but thats what I like most, at least most of the time). It was quite easy to find my mistake by reading the Troubleshooting and turning my brain on. Of course you have to tell the Coordinator XBee the destination address of the Router XBee and vice versa. The bees chatted a bit and then it was time to do some extra work for them. A range test.

I was impressed how far you can go with only 2 milliwatts. I covered every place in my house which has quite thick stone walls and is 3 floors high plus attic.Every signal was received by the coordinator which sat in the other corner of the house. So there is no need for a bee-network at all - at least in the house - and for everything else there are much more powerful bees out there.

For more thoroughly checks one could build a signal strength meter, if range is crucial. Time to read the XBee manual.


Talking to my bee

Today I started with the practical part (page 32). I downloaded and installed X-CTU from digi.com and even if digi.com says the software is suited only for 32bit systems everything went well on my Windows 7 64-bit. I don't use Linux or Macintosh on my desktop so I can't say much about that.

After installing and updating the new firmware versions I attached one XBee on the XBee explorer USB adapter and connected it with my USB A-to-B-mini cable to my laptop. Windows automatically installed the required USB/ serial drivers.

With X-CTU I could conduct the "test/ query" option on the "PC Settings Tab". Also reading the modem configuration was easy and worked well from the beginning. I then configured two XBees as described - one as a Coordinator AT and one as a Router AT. I marked them with a label "C" and "R". Again, no hassle at all.

The book makes a wonderful job describing everything so accurate. So there were no problems installing Tera Term, configuring it and typing the three "+++".


I just talked to my bee!

Using AT commands went smooth again - I just have to get used to not to press return after the three "+++". Talking with one bee now seems easy - next will be the bee-chat.


Delivered, Part II

Before ultimately beginning with the experiments , I again scanned through the book one more time and looked through the parts lists, almost sure I forgot something to order.

So I discovered that I would need some temperature sensors (LM335) and 3.3V voltage regulators (I took 2 LM 2937 ET3,3 and 2 LF 33 CV instead of LD1117V33). I will explain later, why I took two different regulators. I'm also not sure if the 500 mA they deliver will be sufficient. Anyway I have to substitute the 110V Power Switch Tails (parts list printed edition page 173), because in germany we have 220 volts. I have an idea for a workaround, but more on that later.

LM 335, LM 2937, LF 33 CV, headers and resistors
I also ordered some male and female headers and some resistors which I didn't find in my inventory.
I really like the german online-distributor Reichelt, where you can get almost everything you need if it's about electronic parts. They are almost always a bargain. But this time - and it was the first time ever I had an issue with them - they delivered a parcel weighing 1305 grams but the electronic parts are only 34 grams. Not very eco-friendly - maybe that's their standard package for the smallest deliveries they have.
Xbee explorer, breakout boards, Arduino Uno, breadboard

I planned to etch some pcb's later on as mentioned before. But for the time being I switched back to buy assembled parts. That saves time (I'm already quite impatient to wait any longer to start). So I ordered some required parts at Tinkersoup (thanks to Anton for replying my mail so fast) - there I also got the badly needed xbee breakout boards! That was the fourth order for this project and it went as smooth as all the others. Great service.
And: Thank you Internet!