A system to control a lamp accoding to sunlight or manually

This has these two parts in the garage. On the left is an old Radio Shack X-10 controller whose buttons wore out. On the right is the controller board whose photo is on the left. Outside on a pedestal is a weatherproof NEMA enclosure containing a X-10 appliance module. The lamp tops a pole next to it.

One power supply powers four devices

The Pole Lamp Control is actually a system of multiple devices

Controller Schematic.

The X-10 controller keys are not isolated from line voltage so the relays are needed to provide galvanic isolation. They are reed relays, connected across two keys using fine wires,

Pole Lamp Control Picaxe Basic Program

Program Description

All action occurs on interrupts. Processing of the signal requires that the pre-pulse be within limits and that a key sequence is received<br>

The lamp can be turned on or off from three sources:

1.  An ON or OFF control transmission. This may be manually initiated from one of the hand-held controllers, or by timers from a clock. These have key codes i and k. These act immediately. 

2.  A message received from the Solar Sensor of the Weather Station. This message includes a measurement of its solar array charging current. It is sent about once a minute and has the message key code "s" . After checking that its checksum matches the trailing checksum characters, the current field is retrieved from the message and converted to binary. The X-10 commands are derived indirectly from this current using an up-down counter. When a limit is reached, a command is sent to the X-10 Interface. This is repeated for subsequent messages of the same direction.

This mitigates against flashes of light.

Click the button for more information.

Declarations and Data

#rem X-10Receiver.bas  2020 version for use with Radio Shack "plug'npower" hacked controller

X10Receiver.bas controls the pole lamp by light messages from the Emvironmental Sensor 

and sends on or off controls every time it gets a solar message.

The pole lamp can also be controlled manually from the 3-button transmitter.

John Saunders 4/19/2020  12/7/2020 Threshold from 4 to 6, add override

4/1/2021 Adaptions needed for extended length of solar message by 2 pad spaces.

#endrem


#picaxe 08M2


'Outputs

symbol ringPort = C.2

symbol tipPort = C.1


'Inputs

symbol IntPort = pinC.3

symbol MsgPort = C.4


'Variables

symbol Override      = bit0

symbol Temp          = b1        

symbol Chcksum        = b2

symbol ChckHex        = b3

symbol LenCode        = b4        'This is used to determine the bytes to include in the checksum

symbol Current             = b5

symbol Rcvr_Val            = b6        'The key code after 14L1776

symbol DuskCount    = b7             'provides a gradual transition from night to day & vice-versa

symbol Indx          = b0

symbol Msg_Len     = b8

'

'Constants:

symbol DayLight       = 8           'maximum value of DuskCount

symbol Threshold     = 6          'Equal or above increments DuskCount, less decremenys

symbol PulseLength      = 250          'Of the relay. note m8

Init and Main

init:

setfreq m8

LOW ringPort

LOW tipPort

LET DuskCount = Threshold

LET Override = 0

SETINT %00001000,%00001000    'Re-enable the receiver interrupts again


main:

PAUSE 50

goto main

Interrupt

interrupt:

LET Rcvr_Val = ">"

LET LenCode  = "x"

LET temp = 0        

DO WHILE IntPort = 1

    LET temp = temp + 1    'Twice as fast as INC Usual count is 15

LOOP

IF temp < 10 THEN End_Interrupt    'Minimises the time to recover from a noise interrupt

LET bptr = 28

's message:                            Key Code|comma|LenCode|  comma|      temperature          | comma  |       humidity           | comma  |    solar current         | comma  |     batt volts           | comma  |    padding      |  hex checksum   |  CR    |   LF

SERIN [40],MsgPort,N2400_8,("14L1776"),Rcvr_Val,temp ,LenCode,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptr

SELECT Rcvr_Val

    CASE = "i"                     'Manual ON control overrides

        LET DuskCount = 0

        LET Override = 1

    CASE "k"                  

        LET DuskCount = DayLight

        LET Override = 0

    CASE  "s" 

        IF Rcvr_Val <> "s" THEN End_Interrupt    'Else check solar message

        LET bptr = 28

        LET Chcksum = 0

        LET Current = 0

        LET Msg_Len = LenCode - 32            'Should be "M" = 77 dec

        FOR Indx = 29 TO Msg_Len            '45, end of first pad space

            PEEK Indx, temp

            LET Chcksum = Chcksum + temp

            LET temp = temp - "0"

            SELECT Indx

                CASE 37

                    LET Current = 100 * temp 

                CASE 38

                    LET Current = 10 * temp + Current

                CASE 39

                    LET Current = Current + temp

            ENDSELECT

        NEXT

        LET ChckHex = ChckSum / 16

        IF ChckHex < 10 THEN

            LET ChckHex = ChckHex+ "0"

        ELSE

            LET ChckHex = ChckHex + "7"

        ENDIF

        LET bptr = Msg_Len + 2

        LET temp = @bptr

        INC bptr

        IF ChckHex <> temp THEN End_Interrupt

        LET ChckHex = ChckSum & $F

        IF ChckHex < 10 THEN

            LET ChckHex = ChckHex + "0"

        ELSE

            LET ChckHex = ChckHex + "7"

        ENDIF

        IF ChckHex <> @bptr THEN End_Interrupt

        

        IF Current >= Threshold AND DuskCount < DayLight THEN

            INC DuskCount

        ENDIF

        IF Current < Threshold AND DuskCount > 0 THEN

            DEC DuskCount

        ENDIF

    ELSE

        GOTO End_Interrupt

ENDSELECT

IF DuskCount = 0 OR Override = 1 THEN    'Turn on Pole Lamp

    HIGH RingPort

    PAUSE Pulselength

    LOW RingPort

ENDIF

IF DuskCount = DayLight AND Override = 0 THEN  'Turn off Pole Lamp

    HIGH TipPort

    PAUSE Pulselength

    LOW TipPort

ENDIF

'sertxd ("Override=",#Override,"Current=",#Current,",DuskCount=",#DuskCount,13,10)

 End_Interrupt:

SETINT %00001000,%00001000    'Re-enable the receiver interrupts again

RETURN