Saturday, May 14, 2011

Sunrise Alarm Clock - May 14, 2011

This week:
  • Added dimmer leads to circuit board, connected via transistors
  • Added battery switch to side of case
  • Added switch and momentary button for LCD backlight
  • Implemented time logic needed for the alarm
  • Ran first successful full overnight test
  • Split the code from the .pde file into .cpp and .h files for easier IDE editing
Problems (resolved):
  • Hit maximum code size
    • temporarily switched out code sections
  • Int overflow in time calculation
    • switched to long
  • C++ modulus operator returns a negative value when using a negative value
    • Ex: -12 % 7 = 2, but arduino returns negative value for this operation (-5, I believe)
    • (needed modulus for time calculations)
    • Wrote custom modulus function to always return positive values
  • Difficulty getting am/pm correct when adding/subtracting time
    • lots of testing, println statements
    • to make this easier, should have tested this off-board (in java, etc.)
Problems (unresolved):
  • Trouble running on battery power - voltage falls quickly on standard 9V batteries, even with LCD backlight turned off.
    • Single used 9V battery (tried several)
      • Voltage quickly falls (to below 5V), but recovers after being disconnected
    • 3 x 9V batteries (all new) in parallel (still 9V, but 3 times the available current)
      •  Voltage fell to near 8V, but started to stabilize
      •  Seems like it may last for one night, but very expensive
    • 8 x AA batteries in series (1.4 V * 8 = 11.2 V total)
      • Seemed to be working and holding supply voltage above 10V
      • Also seems expensive (12 AA batteries for one device)
    • Putting battery-operation aside for now, leaving 9V connector and battery switch, which switches both (-) and (+) to help prevent draining
  • LCD display corrupted with the new code
    • a friend says this may be because of power supply issues
    • for future troubleshooting
Details:

This  week's work was more difficult than expected.  The time calculations (simple addition/subtraction) took quite a bit of work.  I ran into problems with integer number of seconds when I tried to add 5 or 6 hours (21600 seconds) to the current time.  I also had trouble with the update time calculation.  At first, I tried storing the next update time for each lamp separately.  In the end, I made an array of all of the update times, tagged with which light they were for.  The above may be confusing without more detail:

The idea of the alarm is to set an 'alarm time' by which one/both/all lights will be in the 'fully on' state.  The dimmers I use have 4 states: off, low, medium, and high.  Because I want the 'sunrise' to happen gradually, the clock increases the state of the dimmers in even time intervals.  The total duration of the 'sunrise' is given in the configuration file.

An example (not in config file format):

For two lamps both starting in the off state:

Alarm time:
8:00:00 am


Sunrise duration:
30 min

Update times:
7:30 am - change lamp 2 to low
7:36 am - change lamp 1 to low
7:42 am - change lamp 2 to med
7:48 am - change lamp 1 to med
7:54 am - change lamp 2 to high
8:00 am - change lamp 1 to high

By alternating lamps and incrementing the brightness slowly, the system simulates a 30-minute sunrise.  The sunrise can be as short as about 3 minutes or over an hour long (I assume, as I have not yet tested long durations).

Because of the large number of test-println's I needed to get this working correctly, I temporarily disabled the code to play a sound alarm and the code to read settings from the SD card.

Pictures:

The updated setup.  The switch and momentary in the middle are to control the backlight.  The orange and purple wires in the center-top connect to the dimmers.  They are attached to the collector of a transistor whose base is connected in parallel with LEDs.  When the program turns on the LEDs momentarily, the collector is connected to the base (resistor to ground), and the dimmer is updated.

The two large black boxes are simple touch-dimmers.  Normally, a user would touch the black disc to change the light strength.  In this case, the orange and purple wires allow the Arduino circuit to control the dimmers (see above for details).  These simple dimmers cost about $8 each, an excellent alternative to expensive relay circuits, etc.  The dimmers above can control up to 120 watts each.  Because they are a basic model, they are also easy to open (caution: live 120VAC inside).

The lamps controlled by the dimmers.  The left lamp has one 3-way 150Watt bulb, with the lamp switch set to 150W.  The right lamp has 3 x 40 Watt bulbs.  The dimmers only work (well) with incandescent lights, which is why the CFL in the left lamp is off.  The picture above shows both lamps at full brightness.

Next week:
  • Add sound alarm to play at the end of the sunrise
  • Re-enable reading settings from SD card
  • Remove or comment out unneeded testing println's
  • Fix LCD corruption problem
  • Clean up cpp/h structure (if time available)

No comments:

Post a Comment