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?

No comments:

Post a Comment