A PIC-Based Dollhouse Elevator and Lights

Abstract

Presented is a control system for a doll house based on a PIC16F876 microcontroller. The elevator is driven by a DC motor and position is sensed by both a limit switch and optical encoder. The controller also handles control of lights for the dollhouse allowing toggle on/off functions for each pushbutton. Foyer lights are automatically lit when the elevator arrives at a chosen floor and all lights are on an auto shut-off timer which conserves power and lamp life when left unattended.


Doll House

For Christmas of 2002 my wife and I built our daughter a doll house. At four feet high and four feet wide it is designed for Barbietm and other 11 inch dolls. The dollhouse itself features real tile floors in the bathroom area (lower right) and real hardwood floors in the dining area (middle left).Shown here in use the elevator is visible in the far left side of the unit on the top floor.

System Design

Doll House Elevator Elevator

In the doll house it was decided to use a PIC microcontroller to control all elevator and lighting functions. The elevator itself requires three user pushbutton switches (one to command the elevaor to move to each floor). As well, the elevator has two limit switches (top floor and bottom floor) making certain that the elevator car has arrived at floors 1 and 3 regardless of stretching of the winch cord or other mechanical effects. In order to locate floor 2, an optical IR encoder (salvaged from an old floppy disk drive) was used. This device is placed on the winch mechanism drive gear and provides a series of TTL pulses as the winch rotates. Using an oscilloscope to determine the characteristics of this encoder it was found to produce pulses of 0.5mS width at 35Hz max. as the winch runs (this is important for software design since it defines the 'real time' scope of the problem). The winch mechanism itself was adapted from a drive mechanism from an old VCR (the motor which loads and unloads the VHS cartridge). The number of pulses between floors was determined experimentally by using an emulator in place of the microcontroller and simply changing values until the elevator lands at the correct place for floor 2.

To control the motor (which runs from 12 VDC and consumes up to 200mA) two DPDT relays were employed, one to connect power to the motor and another to reverse polarity to make it run reverse. To make the elevator car move upwards, the POWER relay is activated. To make the elevator car move downwards, both the POWER and REVERSE relay are activated.

The I/O lines associated with the elevator are:

  • RA0 - Elevator motor POWER
  • RA1 - Elevator motor REVERSE
  • RA2 - Bottom Limit Switch (active low)
  • RA3 - Top Limit Switch (active low)
  • RA4 - Encoder Input (active low pulses)
  • RA5 - Floor 1 Pushbutton
  • RB7 - Floor 2 Pushbutton
  • RC7 - Floor 3 Pushbutton



Doll House Mechanism

The diagram to the left details the mechanism of the elevator and the lift. The mechanism is housed on the roof of the dollhouse in a box along with the controller. A small switching wall adapter supplying 5V at 2A and 12V at 0.25A powers the entire unit.

Key elements of the mechanism include limit switches (only one is shown, labelled "Floor 1 Switch" on the diagram, but there are two which tell the controller when the elevator has reached the bottom and the top floors). As well, the encoder shown generates pulses as the winch rotates which are then counted in the controller to determine the actual position of the elevator car. This is used to locate the position of the middle floor.

Lighting

Seven lighting circuits are installed in the dollhouse. Seven miniature pushbuttons are mounted on walls in the dollhouse and wired to the controller using thin hookup wire. Lights are rated at 5V at 100mA and are driven from a bank of high-gain TIP120 NPN darlington transistors. Some circuits have two lights driven - this is easily done since each TIP120 can handle a maximum current of 1A and little power is dissipated in the drivers since these are darlingtons and saturate easily.

I/O lines assigned to the lights are:

  • RB0 through RB6 - Pushbuttons (Active low = ON)
  • RC0 through RC6 - Lamps (Active high = ON)



Controller

The basic circuit is as follows:

Doll House Elevator Schematic
A larger version of the schematic may be found here

This diagram is incomplete and does not show that each RBx input connects to a separate pushbutton (whose function is to toggle the lights on and off) and each RCx output connects to a separate driver transistor to drive each light in the dollhouse. In addition, RC7, RB7, and RA5 are inputs from pushbuttons (only RB7, with pull-up resistor, is shown) which select the floor to which the elevator is to be dispatched. There are three parallel pushbuttons in the dollhouse, one set of three for each floor, so that the elevator may be dispatched to or from any floor. Finally, a crystal (3.6864 MHz), and bypass capacitors are not shown on the diagram but are incorporated (inspect the PCB layout as they are shown there). The function of each I/O line on the diagram may be verified by inspecting the ASM file.

The controller is constructed on a single PCB which includes the 16F876 microcontroller, motor drive relays, and seven power transistors to drive the lights. Overlays for components are provided on the PCB layout.

Download the complete PCB in AutoCad DWG format
Download the complete PCB in DXF format

Please do not ask if I can convert these drawings into some other format. I use ACAD which is limited to its own DWG format as well as a more universal DXF format. Many decent graphics packages (like PaintShop) will read DXF files.

Doll House PCB A view of the controller PCB located in the winch house atop the dollhouse. The MCU chip, with gold cap, is visible in the center of the board here

Doll House Winch The winch mechanism including the motor and spindle, with the back of the controller PCB visible.

Firmware

This is one of the best pieces of code I have ever written. An interrupt service routine keeps track of all timers. TMR0 produces interrupts at 15Hz which are then divided in the ISR to seconds. Timers are then used to protect the elevator (if no limit switch is hit within a preset time the elevator is shut down) as well as turn off lights automatically when a timer expires.

The main program scans for an elevator floor pushbutton as well as a light pushbutton. When an individual light pushbutton is pressed a corresponding bit in the 'Lights' register is XORed to invert it and hence toggle it on/off. As well, the arrival of the elevator at a floor sets a bit in the 'Foyer' register. Both registers are ORed together as follows to determine which light should be activated:

	movf      Lights,w
	iorwf     Foyer,w
	movwf     PORTC		;Turn ON appropriate lights

Download the firmware in MPLAB 5.50 assembler format