Newbie looking for help


Please forgive a newbie for asking for assistance for a project.

To automate a large dolls house set up.

Required multiple outputs (about 50)
To be timed
MP3 player to play selected tracks on time command
Display to show status of running program

I understand that I will need more than 1 Picaxe controller to do this, can I link the output from 1 controller to the input of another to trigger events? Or can 1 real time clock be connected to 2 controllers to activate events

?? In my head I have the idea that I have a Realtime clock running.

At a defined time, I would like the program to run, this would switch on lights in various rooms at various times (to simulate people moving about)

Also, at various times the mp3 player would need to activate selected tracks to play sound effects (i.e. dog barking, people talking, clock chiming)

The outputs only need to supply low current for miniature lights, they are 12vdc

Does this make sense and if so, what do I need to buy to get started

I am currently reading the manuals and think that what I want to do is possible

Simple flow chart ….

At 6:00 Pm switch on lamp 1
At 6:03 pm sound dog bark
At 6:10 switch on lamps 2/7/8/11

Hope someone will assist me in getting started


Senior Member
The outputs only need to supply low current for miniature lights, they are 12vdc
12V would damage a picaxe--you would need to use something in between to switch the lights--for instance, 2n7000 mosfets (or beefier for brighter lights--would 5V LEDs that could be directly driven not work?).

If all you need for many of your outputs are simple ON/OFFs, you could use these I2C I/O expanders (which can be chained to give as many digital I/Os as you like--within reason): MCP23017 A 28X2 with two of these might provide all the I/Os and coding space you would need.

For your timing, you could use a ds3231 rtc module.
Last edited:


Thank you, I will have to re read all the pixace manuals and try to increase my knowledge, your suggestion makes sense as all the outputs need to do is be on or off. I seem to be stuck with supplying 12 volt as all of the dolls house lighting appears to be set at 12v.
Would I be wise to get the axe091u starter kit to learn more


A belated Welcome to the Forum and no need to apologise.

I'm sure you'll get lots of help in the next day or two.

And a question please:

What scale is your Doll's house?


It is 1:12 scale. Wifes long term project, I need to get all electrics installed so she can progress :) We want it to be a "living house" so automation is my aim. I need to adapt my programming knowledge from (visual basic in excel) to the picaxe terminology.
Lots to learn. Already have ideas for other projects (don't run before I can walk) :)


Senior Member
Hi and welcome,
I seem to be stuck with supplying 12 volt as all of the dolls house lighting appears to be set at 12v.
Would I be wise to get the axe091u starter kit to learn more
Initially, you don't need to buy anything to get started, you can use the PE6 Program Editor with its "Simulator".

To endorse what's been said, the PICaxe (and most logic integrated circuits) cannot directly drive 12 volt lamps. The simplest solution is to use a "Darlington" driver IC which has 7 or 8 inputs and outputs, each with a capability of >12 volts and some hundreds of mA. Note that it's a "low side switch", so you connect the "other" pin of each lamp directly to the 12 volt supply. There are several PICaxe boards which include such a driver IC, for example I suggest starting with a 14 or 20M2 Starter Pack, which includes the "universal" programming cable. Also, as you've mentioned MP3, IMHO the MP3+14M2 combined kit is a bargain. ;)

The PICaxe can "keep time" to better than 1% which should be fine for sequencing a realistic lighting effect. But if you want the lights to come on at precisely (say) 6.00 pm every day without any manual control, then you will need a "Real Time Clock" chip as suggested above. 60 lights is quite a lot - are they all to be controlled independently? If so, you will need to plan the "system architecture" quite carefully (which we can help with), to avoid unnecessary complication or duplication.

Cheers, Alan.


New member
Hi Hedingham,

I think your project is quite doable with Picaxe, and a great project which will interest you both. While it will be a big project when complete, it is really made up of a number of simple tasks, each of which is easily handled by the software and simple hardware. Well, there might be a bit more to the MP4 feature, but that will still be achievable after you become comfortable with the easier functions.

You could start with just the editor as has been suggested, but I know that I find it easier if I have a purpose for exploring an aspect of the programming language, and actually assemble the hardware that is intended to run the code in parallel with developing the software. You will need the download cable, but then you can work with just a breadboard (though the little board to carry the download socket mentioned in another recent thread is a good idea). Or you could get any of the starter kits, also discussed in another recent thread. Even an 08M2+ chip would do each of the individual functions you require and allow you to test code snippets, or a 14M2 as already suggested. Section 3 of the manuals will give you several ideas for the interfacing circuits you will need. Then try each block with a few components on a breadboard. You will soon see when to change to a bigger chip when you see how the system works, and have a few tested working functions. Many code snippets will work on different target chips with only attention to appropriate pin numbers or very minor syntax changes. As you are already familiar with one form of basic, you will not find it difficult, remember section 2 is your best friend for making sure you have the correct syntax for the commands. I would start with a separate battery box for the Picaxe power supply, but eventually you can add regulated power supplies to give the required 12 V and 5 V supplies either on board or on a separate small board. Just go one step at a time, and the project will grow.

And post updates as you go. I am sure you will get lots of help from others here.

I am quite new to the forum though I have been building the odd project over the years, so comments from others on my post will also be welcome.



Technical Support
Staff member
Does this make sense and if so, what do I need to buy to get started
All makes sense to me and it might be worth looking through the forum for past posts on controlling model villages, fun fairs and railway layouts; they are all of a similar theme when it comes to controlling numerous lights from a PICAXE.

As to getting started; the main issue will be how the lights are to be controlled, how the wiring needs to be so it can be installed which allows your wife to progress with her side of things.

To get things moving quickly it may simply be a case of getting the bulb wiring done, leaving wires which can then be soldered to when the doll's house is finished or at some appropriate time. That way your wife can get on with doing the house without waiting for you to do your thing, and you can get on with yours without needing the actual doll's house and having to hold your wife up.

I would then split the project into two parts; actually controlling the lights, turning them on and off, and the PICAXE part which commands them to be turned on and off to a schedule. The PICAXE part itself can be split into two phases; just getting the lights to work, and then adding scheduling. Triggering sound can be a separate sub-project with the resulting code integrated into the sequencing later.


Senior Member
Here's a proof-of-concept program, using the 18 available output pins on a 28X2. This will run, if slowly, in the simulator.

The on/off settings are kept in a table (picaxe TABLE memory) with up to 64 4-byte entries, where the bytes represent hour, minute, duration, and port (pin).

Through timekeeping, either on a real 28X2 with a DS3221 RTC, or in simulation where each second represents a minute, the program walks through the ordered table. When the clock hour and minute matches the table entry, the port (pin) is turned on, The hour and minute when it should be turned off is calculated and placed in an array of 2-byte end-times in ram.

Each minute (real or simulated), this off-time array is scanned and if the time value in the array is less than or equal to the current time, the pin is set low and the array slot is set to $FFFF (which is higher than any possible time).

The simulation on a PC is pretty slow--about 6 seconds per simulated minute--because of the need to scan for a turn-off time for all the ports. On a real chip, this would take less than a second.

The use of a byte to hold the duration of on-time in minutes means that the maximum on-time for a single table entry is 255 minutes, or 4 hours and 15 minutes. To have a light on for 10 hours, you would need 3 table entries. For instance, to have a light on from 8am until 6pm, you would have these entries (interspersed with others)

table position,(8,00,241,C.1)
table position,(12,00,241,C.1)
table position,(16,00,120,C.1)

The extra minute (241 instead of 240 for 4 hours) assures that the light will not go off and then immediately on again. If a table entry turns on a pin which is already on, the new duration replaces whatever time was previously remaining.

With this code, 54 lights could be controlled with 3 separate 28X2s. If one 28X2 and 2 16-output MCP23017s were used, the code would have to be modified for pin numbers above those available on the 28X2.

I generated the table with a random increment in time of 0-10 minutes, random duration between 1 and 32 minutes, and random port between 0 and 19, excluding the I2C ports C.3 and C.4, and the SEROUT port, A.4.

Note that the picaxe port designations, e.g., C.3, A.1, are actually numbers, where B.0-7 are 0-7, C.0-7 are 8-15, and A.0-4 are 16-20.

The text below the code logs every minute in HHMM format (with leading 0s suppressed). A time followed by "+" indicated that a pin was turned on. For instance, "1 +6/25 +0/2" indicates that at minute "1", pin 6 (B.6) was turned on for 25 minutes, and pin 0 (B.0) was turned on for 2 minutes. A time followed by a "-" indicates a pin was turned off. For instance, "3 -0" means that at minute 3, pin 0 (B.0) was turned off.

I ran this for a simulated 6 hours--over an hour of run time on my laptop. I'm not sure I have a 28X2 with me. If I can dig one out I'll try to run the program on the picaxe. . . . [Later: I had a 40X2 handy--the program ran with only "#picaxe 40X2" changed and "# SIMULATOR" commented out--about 7 minutes to simulate 6 hours with a tick of about once second per minute.]

' 28lights.bas
#terminal 4800

#define FASTSIM ' either simulator or simulation on chip
#define SIMULATOR ' simulator on PC

symbol tableMax=60             ' number of turn-on entries
symbol tableTopAddr=tableMax-1 ' top address of turn-on entries
symbol timeEndAddrBase=60     ' ram address of endtime for port 0
  symbol cNoPins=20
  symbol cTopPin=19
  symbol cNoPins=50
  symbol cTopPin=49

table 0,(0,1,25,6) ' hour, minute, time-on in minutes, pin
table 4,(0,1,2,0)
table 8,(0,4,9,8)
table 12,(0,11,52,17)
table 16,(0,19,15,15)
table 20,(0,20,21,7)
table 24,(0,28,2,16)
table 28,(0,37,15,15)
table 32,(0,46,20,4)
table 36,(0,54,32,19)
table 40,(0,57,30,3)
table 44,(1,3,9,2)
table 48,(1,4,5,1)
table 52,(1,11,6,13)
table 56,(1,19,10,18)
table 60,(1,27,15,15)
table 64,(1,31,21,5)
table 68,(1,33,4,0)
table 72,(1,36,31,3)
table 76,(1,42,18,8)
table 80,(1,45,9,10)
table 84,(1,46,1,4)
table 88,(1,54,2,8)
table 92,(2,1,14,19)
table 96,(2,5,14,19)
table 100,(2,12,9,18)
table 104,(2,14,3,4)
table 108,(2,22,24,17)
table 112,(2,31,27,6)
table 116,(2,35,24,13)
table 120,(2,42,25,10)
table 124,(2,46,7,1)
table 128,(2,55,17,0)
table 132,(3,2,2,8)
table 136,(3,6,9,14)
table 140,(3,9,8,1)
table 144,(3,18,28,14)
table 148,(3,26,28,2)
table 152,(3,29,28,2)
table 156,(3,31,31,7)
table 160,(3,41,24,1)
table 164,(3,49,26,2)
table 168,(3,52,9,10)
table 172,(3,58,7,13)
table 176,(4,7,22,1)
table 180,(4,16,10,14)
table 184,(4,18,13,3)
table 188,(4,28,4,8)
table 192,(4,33,32,7)
table 196,(4,38,28,2)
table 200,(4,47,27,10)
table 204,(4,56,22,17)
table 208,(4,57,10,18)
table 212,(5,4,16,15)
table 216,(5,13,31,15)
table 220,(5,20,17,16)
table 224,(5,23,8,17)
table 228,(5,24,30,3)
table 232,(5,24,30,7)
table 236,(5,34,16,7)

symbol timePrior=w2
symbol timeNow=w3
symbol timeTable=w4 ' made up of b8&b9
symbol timeEnd=w5
symbol wScratch=w6

symbol tableAddr=b14
symbol port=b15
symbol duration=b16
symbol timeEndAddr=b17
symbol minute=b18
symbol hour=b19
symbol scratch=b20
symbol endHour=b21
symbol loopCnt=b22

i2cslave %11010000, i2cslow, i2cbyte ' $68, 104 set up RTC

wScratch=$FFFF: for loopCnt=0 to cTopPin: poke timeEndAddr, WORD wScratch: timeEndAddr=timeEndAddr+2: next loopCnt
readtable tableAddr,b9,b8,duration,port ' b9,b8=timeNow

  gosub getTime
  if timeNow <> timePrior then
    sertxd(#timeNow," ")
    if timeNow = 57 or timeNow = 59 then
      scratch=0 ' do nothing--used for break at runtime
    do while timeTable=timeNow
      high port
      sertxd("+",#port,"/",#duration," ")
      do while wScratch > 59
        inc endHour
      timeEnd=endHour*100+wScratch ' end time as hhmm
      timeEndAddr=timeEndAddrBase+port+port ' upper ram address of off-time as WORD hhmm
      poke timeEndAddr, WORD timeEnd ' off time for this port
      readtable tableAddr,b9,b8,duration,port ' b9,b8=timeTable
    loop ' while timeTable=timeNow
    ' next loop to turn off any needed ports
    wScratch=$FFFF ' invalid (off the time scale) end time
    for loopCnt=0 to cTopPin
      if loopCnt <> C.3 and loopCnt <> C.4 then ' skip i2c ports
        peek timeEndAddr, WORD timeEnd
        if timeEnd <= timeNow then
          low loopCnt
          if timeEnd <> 0 then
            sertxd("-",#loopCnt," ") ' log the off-time
          poke timeEndAddr, WORD wScratch ' inactive
      timeEndAddr=timeEndAddr+2 ' next off-time
    next loopCnt

  #ifndef FASTSIM ' normal execution
    readi2c 1, (minute,hour) ' read minute, hour
    scratch=minute and %00001111 ' strip high BCD value
    scratch=hour and %00001111 ' strip high BCD value
    ' use seconds for minutes and minutes for hours
'    readi2c 0, (minute,hour) ' read sec, minute
    #ifndef SIMULATOR ' on-chip simulation
      pause 1000
    inc minute
    if minute > 59 then
      inc hour
The SERTXD log:
1 +6/25 +0/2 2 3 -0 4 +8/9 5 6 7 8 9 10 11 +17/52 12 13 -8 14 15 16 17 18 19 +15/15 20 +7/21 21 22 23 24 25 26 -6 27 28 +16/2 29 30 -16 31 32 33 34 -15 35 36 37 +15/15 38 39 40 41 -7 42 43 44 45 46 +4/20 47 48 49 50 51 52 -15 53 54 +19/32 55 56 57 +3/30 58 59 100 101 102 103 +2/9 -17 104 +1/5 105 106 -4 107 108 109 -1 110 111 +13/6 112 -2 113 114 115 116 117 -13 118 119 +18/10 120 121 122 123 124 125 126 -19 127 +15/15 -3 128 129 -18 130 131 +5/21 132 133 +0/4 134 135 136 +3/31 137 -0 138 139 140 141 142 +8/18 -15 143 144 145 +10/9 146 +4/1 147 -4 148 149 150 151 152 -5 153 154 +8/2 -10 155 156 -8 157 158 159 200 201 +19/14 202 203 204 205 +19/14 206 207 -3 208 209 210 211 212 +18/9 213 214 +4/3 215 216 217 -4 218 219 -19 220 221 -18 222 +17/24 223 224 225 226 227 228 229 230 231 +6/27 232 233 234 235 +13/24 236 237 238 239 240 241 242 +10/25 243 244 245 246 +1/7 -17 247 248 249 250 251 252 253 -1 254 255 +0/17 256 257 258 -6 259 -13 300 301 302 +8/2 303 304 -8 305 306 +14/9 307 -10 308 309 +1/8 310 311 312 -0 313 314 315 -14 316 317 -1 318 +14/28 319 320 321 322 323 324 325 326 +2/28 327 328 329 +2/28 330 331 +7/31 332 333 334 335 336 337 338 339 340 341 +1/24 342 343 344 345 346 -14 347 348 349 +2/26 350 351 352 +10/9 353 354 355 356 357 358 +13/7 359 400 401 -10 402 -7 403 404 405 -1 -13 406 407 +1/22 408 409 410 411 412 413 414 415 -2 416 +14/10 417 418 +3/13 419 420 421 422 423 424 425 426 -14 427 428 +8/4 429 -1 430 431 -3 432 -8 433 +7/32 434 435 436 437 438 +2/28 439 440 441 442 443 444 445 446 447 +10/27 448 449 450 451 452 453 454 455 456 +17/22 457 +18/10 458 459 500 501 502 503 504 +15/16 505 -7 506 -2 507 -18 508 509 510 511 512 513 +15/31 514 -10 515 516 517 518 -17 519 520 +16/17 521 522 523 +17/8 524 +3/30 +7/30 525 526 527 528 529 530 531 -17 532 533 534 +7/16 535 536 537 -16 538 539 540 541 542 543 544 -15 545 546 547 548 549 550 -7 551 552 553 5
Simulation screenshot:
Last edited:


Senior Member
@Hedinghamlook at the content posted by user @jensmith25. This person has many posts on integrating lighting and such in various models and dollhouses. There might be some gold nuggets or tips and tricks to help with your project :)


Technical Support
Staff member
The on/off settings are kept in a table (picaxe TABLE memory) with up to 64 4-byte entries, where the bytes represent hour, minute, duration, and port (pin).
There is nothing wrong with the principle of what's proposed but 64 entries is probably not enough for a sequencer which is controlling 50 or so lamps and triggering sound effects. Note there are 512 bytes of Table on the 14M2, 18M2, 20M2 so that would allow 120, 182 if Eeprom were also used.

One can compact the data into three bytes of TABLE which increases the number of steps to 85, 170 or 256.

A better option may be single byte commands with a couple of bits to indicate what each byte means -

Delay some hours
Delay some minutes
Delay some seconds
Turn a pin on
Turn a pin off
Trigger an event
Restart from top of table

That would hopefully get most steps down to two bytes, 128, 256 or 384 steps.

To create the Table and Eeprom it would make sense to use an external PC program to order the table and calculate delays and commands. That also has the advantage that one only needs to step through the table, one does not have to match times every minute.

A quick test showed the 60 entries in your example code could be reduced to 203 bytes using that means, about a 20% saving. That is admittedly less than the 30%-50% saving I'd hoped to see.

Using a duration rather than separate on and off commands should save space and increase the number of steps; so that is definitely something to consider.

As with most things, it's probably not possible to say which solution is best or required without having some actual data to work with. The bottom line is, however it's done, it should be possible.


Senior Member
64 entries is probably not enough for a sequencer which is controlling 50 or so lamps and triggering sound effects. Note there are 512 bytes of Table on the 14M2, 18M2, 20M2 so that would allow 120, 182 if Eeprom were also used.
Right. I do plan on a 20M2 version for the extra table size. I was thinking that if 3 28X2s were used, controlling up to 19 outputs each, the 64-entry table might work. And since speed of development and ease of understanding the use of the table seemed important for proof-of-concept, I went with what seemed quickest.

Since the code itself is brief (540 out of 4096 bytes), additional code to put entries to ram could be used, including in additional slots. One awaits requirements from the OP.
Last edited:


Senior Member

Yes, I would also ask the OP how much hardware he wants to either design and make himself, or to get "off the shelf".

For example three (or four) of the 20(M2)-Project Boards will give all the required (logic) outputs, and about half of the Darlington buffers. The remaining buffers then could be easily fitted on a piece of Veroboard (stripboard) to give a reasonably off-the-shelf construction. The multiple PICaxes might run identical program code, (e.g. for separate floors), or different programs for tasks such as MP3 player, Timekeeping and User Interface, etc.. Conversely, a single 20M2 could generate all the "logical" output requirements, using additional hardware methods such as multiplexing or I2C bus expanders, etc..

Cheers, Alan.


Wow Many thanks guys, you have really provided me with info I need to digest.
I think I like the idea of 1 processor with I2C bus expanders but I will carefully try to understand everyones replies.
I like the idea of off the shelf solutions but also would like to fully understand and build it from scratch.
I will also look at the info @jensmith25 to pick up pointers
Again many thanks.....


Senior Member
Here is a version which uses both slots on a 20M2--a total of 1K bytes of table memory, for 256 entries. It runs on the 20M2 in 8 minutes--simulating 24 hours of running. The code in the two slots is nearly identical except for initializations and, of course, the table definitions.

The hardware consists of a 20M2 and one MCP23017 i/o extender--32 I/Os minus the i2c pins, B.5 and B.7, and the dedicated input pin, C.6--for a total of 29 outputs. Additional MCP23017s would add more outputs (but some adjustments would be needed in the code to account for them).

Three MCP23017s plus the 7 available pins on the portC would give you 55 outputs, and would leave C.6 available as an input and B.0-B.4 and B.6 as inputs/outputs for other purposes. So the project looks very do-able if 256 table entries will suffice.

The code for each slot exceeds 10K characters, so I've zipped the code and attached it.

Photo of the setup:


Last edited:


Senior Member
I thought that this project, with 12V control and many outputs, would be a good excuse to add to the picaxe bag of tricks, so I designed 3 PCBs which are scheduled to arrive Monday from JLCPCB. One is to add 2 ULN2803As to the ebay MCP23017 module, another is to add one ULN2803A to a row of output pins, and the third would be a 20M2 module which would take the ebay MCP23017 module and two of the single ULN2803A PCBs.

This is the approximate layout--sorry for the clumsiness and lack of exact scaling.
This could control 29 lights, so 2 of them could control the 50 requested with some pins left over for other uses. Once tested, I'll post the Eagle CAD .SCH and .BRD files so anyone can order them from JLCPCB or elsewhere. 10 of the small boards and 5 each of the other two would be about $17 (slow boat), and $10-15 more for express delivery in about 10 days.


Senior Member
I have published the code, Eagle sch & pcb files, and gerbers for the above here. Interesting project--hope to hear more about it.


I have published the code, Eagle sch & pcb files, and gerbers for the above here. Interesting project--hope to hear more about it.
Thank you so much for this info. I am currently learning as much as I can from the AXE091 development kit.
Once I have understood things I will be getting my teeth into the project. I will see if I can order the items (not sure if they will ship to Uk)