Menu

Example of use of TX WL102 and RX WL101 modules for PIR sensors

Romtek
16 hours ago
9 hours ago
  • Romtek

    Romtek - 16 hours ago

    I'd like to post my working example of a WL102 module sending a string using a PIR sensor and an Attiny85.
    I look forward to your reply. Thank you.

     
    • Anobium

      Anobium - 14 hours ago

      Sounds a great solution. Do share and l will include in the Demonstrations!

       
  • Romtek

    Romtek - 13 hours ago
    /**************************************************************
    RomTEK 
    Nome: pir-attiny85-2
    Micro: ATTINY85
    Date: 08/17/2025
    Version: 00.01
    Description: It goes into sleep mode and as soon as the PIR triggers, it transmits characters to the WL102-341 module.
    Links and references
    rev.:        data:        note:
    *************************************************************/
    //!fase funzionante
    #chip tiny85,8
    #option explicit
    
    ' ----- Def
    #define En_tx portb.0        //port enable tx  pin 5
    #define tx    portb.1
    #define led1  portb.4
    dir tx out
    
    ' ----- Var global
    dim bd as word
    dim ix as byte
    dim ch as byte
    dim bit_index as byte
    dim mask(8) as byte
    dim msg(12) as byte     //! enter the number of characters used
    dim ii as byte
    dim trigger as bit
    dim prev_state as bit
    dim zz as byte      //convenience variable for message repetition
    dim conta as byte
    zz=0
    
    dir En_tx out       //out for enable tx
    dir led1 out
    dir portb.2 in      //input pir
    
    ' ----- Inizialize
    set tx on              ' Line active
    bd = 3333                //default 833  boud
    /*speed ask/ook
    Baud   Rate Bit Duration (µs)   Note
    300    3333                     
    600    1666 
    1200    833                     usage old modem
    2400    416                     
    4800    208                     
    9600    104                     Standard TTL 
    */
    // ----- table bitmask
    mask(0) = 1
    mask(1) = 2
    mask(2) = 4
    mask(3) = 8
    mask(4) = 16
    mask(5) = 32
    mask(6) = 64
    mask(7) = 128
    
    // ----- Loading ASCII message
    msg(0) = asc("D")
    msg(1) = asc("R")
    msg(2) = asc("T")
    msg(3) = asc("e")
    msg(4) = asc("k")
    msg(5) = asc("T")
    msg(6) = asc("x")
    msg(7) = asc("1")
    msg(8) = asc("=")
    msg(9) = asc("1")
    msg(10) = 13           ' CR
    msg(11) = 10           ' LF
    
    //--------------------setup ------------------------------------------------------------------------------------------------
      wait 100 ms
            ' ----- blink for start
            for ii = 1 to 10
                set led1 on
                wait 10 ms
                set led1 off
                wait 100 ms
            next ii
    dir led1 in       ' Energy saving
    // ----- Disable unnecessary peripherals
    PRR = 0b00001111   ' off ADC, Timer0, Timer1, USI
    ADCSRA = 0         ' Disable ADC
    
    // ----- Config interrupt  PB2 (PCINT2)
    GIMSK = GIMSK or 0b00100000   // enable PCIE
    PCMSK = PCMSK or 0b00000100   // enable PCINT2
    SREG.7 = 1                    // enable interrupt global
    
    On Interrupt PinChange0 Call risveglio      //call the wake-up routine
    
    prev_state = portb.2   ' Initial pin state
    //-----------------------end setup ----------------------------------------------------------------------------------------------
    
    ' ----- Main loop
    do
        MCUCR = MCUCR or 0b00110000   ' SM1:SM0 = 01 (Power-down)
        MCUCR = MCUCR or 0b00100000   ' SE = 1
        asm sleep                      //he goes to sleep    
    
        if trigger = 1 then
            trigger = 0
            dir led1 out                //put led as output
            set led1 on
            set EN_tx on               //enable tx        
            for ix = 0 to 2            //! ix It must be how many characters are to be sent 
                ch = msg(ix)            //
                gosub sb               
                wait 50 ms             //!don't change the time
            next  
            for zz=0 to 3 //repeats the message 3 times
                for ix = 0 to 11            //! ix It must be how many characters are to be sent
                    ch = msg(ix)
                    gosub sb         
                    wait 10 ms
                next
                wait 10 ms
            next zz 
            set EN_tx off        //disable tx        
            set led1 off
            dir led1 in              //put LED as input for low consumption
        end if
    
    loop
    //---------------- Routines and functions-------------------------------------------------------------------------------------------------
    //----- Routine to send a byte via ASK/OOKsb:
        // Bit  start
        set tx off
        wait bd us
    
        // 8 bit (LSB first)
        for bit_index = 0 to 7
            if (ch and mask(bit_index)) <> 0 then
                set tx on
            else
                set tx off
            end if
            wait bd us
        next
    
        //Bit di stop
        set tx on
        wait bd us
    return
    //-----------------------------------------------------------------------------------------
    sub risveglio     //wake-up routine
        if prev_state = 0 and portb.2 = 1 then
            trigger = 1
        end if
        prev_state = portb.2
    end sub
    //------------ end of program --------------------------------------------------------------------------------------------------------------------
    
     
  • Romtek

    Romtek - 13 hours ago

    This is the GCB code for the WL102 transmitter. I managed to put it into sleep mode and use the PIR sensor to send an alarm. I looked for an example but couldn't find it. I couldn't put it into deep sleep mode with Arduino... but I did manage to do it with GCB. I hope this helps. If you're interested, I have the receiver part for the WL101, but it's written for Arduino Nano.

     
  • Romtek

    Romtek - 13 hours ago

    Lo schematic

     
  • Anobium

    Anobium - 11 hours ago

    Thank you. I have taken your code and hopefully I have helped by documenting the program.

    Please have a look thru and hopefully these are documentation changes only, and, focused on the use of English.

    If this ok. Then, I will put into GitHub.


    Post the receiver part for the WL101. We should publish the completed solution.

    Evan

     
    👍
    1
  • Romtek

    Romtek - 9 hours ago

    Sorry for my English, but I noticed a mistake in the diagram: the PIR is powered by 5 volts, but it needs to be powered by 3 volts due to communication levels. JP1 is not used at the moment. Sorry again.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.