HC-12 433 mHz module + Ard + Kerui PIR

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Hello

In 2021 Jorgen raised the question about HC-12 as a garage door opener (By jgu1 » Sat Jun 19, 2021 post: HC12 Flowcode examples). No more posts found (by me) in relation to HC-12.

Has anybody used the AT commands to control HC-12? This HC-12 module can work with up to 100 sensors.

Ard + HC-12 + Keuri PIR

I will try to use the Chinese PIR sensor (433 mHz) Keuri brand (from Ali).
This sensor is designed to work with the dedicated Keuri controller.
I am not sure what frequency is used by this PIR sensor.
The band for it is: 433.4-473 mHz.

What UHF RF scanner can be used to get the PIR frequency?

Thanks
Last edited by viktor_au on Sat Sep 03, 2022 12:25 am, edited 1 time in total.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Keuri PIR

Post by chipfryer27 »

Hi

I don't have one of the HC boards nor any Kerui alarm equipment. However all Kerui components seem to be compatible with each other and from a K7 manual, specs state that the sensor frequency is 433.92MHz so my guess is that's your PIR frequency.

The HC-12 can run from 433.4MHz upwards in steps of 400KHz so you could have it step through a range looking for sensor response, with 433.8 being closest to what the manual states.

What format is the PIR sending data? I'm guessing as a finished product it will contain info such as sensor address, status, possibly battery status and who knows what too. Therefore you may need a logic analyser connected to the HC to "read" what is coming out of the PIR and code around that, or feed straight into a microcontroller for further processing.

Some equipment will encrypt their data so you might get meaningless results.

Do you have a link for the HC-12 AT command set?

Regards

User avatar
Bachman
Posts: 116
Joined: Sun Sep 07, 2014 11:37 am
Location: Hungary
Has thanked: 9 times
Been thanked: 53 times

Re: HC-12 433 mHz module + Ard + Keuri PIR

Post by Bachman »

What modulation is used by K7? Not the last point of view.

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Hello

Re: 433.92MHz
Thanks chipfryer27 for some help.
I checked this frequency with PIR on/off, on/off... No carrier.


PCB
I found on PCB the:
SCT1527 OTP Encoder
BISS0001-Micro Power PIR Motion Detector IC

Looks like the 433x.mHz rf amplifier is not on chip, but on transistors.

HC-12 AT

Attached.
I wrote some code but as I don't have the HC-12 module I cannot check it out.

Frequency
Kerui P819 manual: 315/433 mHz +/- 75kHz

Logic analyser connected to the HC
I was thinking to write the 'scanner' code for Nano+HC12

Hello Bachman
I think (can be wrong) the device uses ASK mode, some kind of Morse code with carrier modulation.
Attachments
Kerui_PIR_1.jpg
Kerui_PIR_1.jpg (58.23 KiB) Viewed 253710 times
PCB_view_2.jpg
PCB_view_2.jpg (142.11 KiB) Viewed 253710 times
HC-12_v2.3A.pdf
(281.46 KiB) Downloaded 350 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

I was pushed for time before leaving yesterday so couldn't look too much into things.

Thanks for the document. I don't think you will have much trouble at all in configuring the HC-12 using AT's especially as they give examples of usage. Wish other product did :)

I'm guessing you are hoping to have your PIR communicate directly with the HC-12? If so I think you may face problems. The Kerui does appear to use ASK but from what I see the HC-12 uses GFSK, a potential issue Bachman brought up in his post.

I could be wrong but it looks like the main purpose of the HC-12 is to create a transparent wireless link between two HC-12's rather than being a generic board. If you are looking to have wireless detectors, switches and other "home automation" gadgets then it's probably not the way to go. There are better options for that.

Not sure of the title, it was something like "Home Automation Using Raspberry Pi" and inside it documented creating a system using ISM components from PIRs to electric gates etc using off the shelf components. I think it used Lloytronics (??) or something like that. I could probably dig it out and get the component details if you want.

However if you have outbuildings some distance away, then the HC-12 could be a nice solution to provide a link for PIC / Arduino / etc.

Regards

EDIT.....

Easier than I thought to get details, it was on my Kindle.

"Home Automation and Security Projects Using Raspberry Pi" is the title. It uses a bog standard 433 MHz receiver module such as these

https://www.amazon.co.uk/DollaTek-Super ... 06&sr=8-53

These run at 433.92MHz (ASK) and should be compatible with a lot of other 433 kit out there. Examples included running with "Lloytron" PIR/ Doorbells etc
Last edited by chipfryer27 on Sat Sep 03, 2022 11:10 am, edited 1 time in total.
Reason: Additional Info

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Hello

Re: HC-12 AT commands
The HC-12 manual is not complete, for example they don't pay attention to CR, LF, etc AT syntax.
As I mentioned early I have prepared some code to test the HC-12. Will wait for the module to check it out.

Re: ASK vs GFSK
You are right. This is one of many problems

Re: Decoding the TTL RF signal

This is another problem.
I think I am moving in a wrong direction.
Encoder/decoder should be from the same 'family'.
SCT1527 OTP Encoder (Keuri PIR) will not (probably) work with HC-12 decoder (MCU STM8s).
I read that some people use the SDR receiver and analyse the code...

Conclusion
Looks like I was going into a wrong direction by trying to use the industrial 433mHz sensor with HC-12. As correctly pointed to me by chipfryer27 there are a lot of problems. I found on www that some guys solved the problems by decoding the code of industrial PIR detectors by using some different methods. A few ways to do it. But this is not what I want to do.
I have to check the wired PIR detectors.
I like HC-12 (as it can access 100 sensors).
Looks like I should create an: Ard+HC-12+PIR(wired) module.
Thank you for the help.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

My understanding of the HC-12, and I could be wrong, is that it can operate in any one of 100 channels in the ISM band, rather than having 100 independent channels.

If you set up a RF link such as "Many-to-One" where multiple transmitters all talk to the one receiver, they would all use the same RF channel (e.g. 433.92). However it is within the data they send that would identify which transmitter is talking. For example it may send a packet where the first x-bytes are the unique address or identifier with the remaining bytes being "data" etc. It would be down to your microcontroller to process the packets (i.e. only respond to certain addresses or such like).

Regards

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by jgu1 »

Hello Victor!

I have first seen your post now. Concerning AT commands is here: https://howtomechatronics.com/tutorials ... on-module/. a good explanation and how to change baudrate, frequency and power ect. I have testet them and they work.

Hope it is usefull :D

Br jorgen

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Hello
I have ordered two HC-12 modules.

Re: 100 channels
I am not sure, I hope Jorgen will correct me.
I think that HC-12 works only in one channel in one moment.
To change channel I have to use the AT command.
Question to Jorgen: Do you use HC-12 in one channel only or in multi-band operation?

Re: Frequency
I hope Jorgen will help.
What is the operating frequency of HC-12?

Manual says: Working frequency range (433.4-473.0MHz, with 100 communication channels, stepping of 400kHz)
Rx code example is attached.
https://www.allaboutcircuits.com/projec ... er-module/
Doesn't look like the code has address, etc.

Re: AT commands
Question to Jorgen: Do I have to use CR and LF before and after I send the AT command?
I understand that I have to use SET pin to change the mode from command to uart.

Thanks to chipfryer and Jorgen.
Attachments
Code_Rx_example_1.jpg
Code_Rx_example_1.jpg (101.72 KiB) Viewed 253649 times

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by jgu1 »

Hi Victor!

Of course I will help if I can Victor :D

Anyway I attack some more examble and video.

It is an easy module to use and config. The only thing you have to do for config is to pull down the AT pin when you config, an then you can send the AT command from serial monitor (Arduino IDE)
Read and see the video it´s easy to change frequency, Baudrate, ect. These module is very reliable and have a high output.

https://www.elecrow.com/download/HC-12.pdf

Video: https://www.youtube.com/watch?v=0PyHYLAKfnQ

https://www.youtube.com/watch?v=DGRPqeacJns

Hope this help a little?

Br jorgen

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Thank you Jorgen.
Will check the videos.

Re: Kerui PIR frequency.
chipfryer27 is correct.
Tx,Rx freq is 433.92 mHz.
Attachments
Kerui-2.jpg
Kerui-2.jpg (54.26 KiB) Viewed 253590 times

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Binary string to decimal problem

Post by viktor_au »

Binary string to decimal problem

Hello

PIR Kerui works on 433.9mHz. It has 1527 chip.
Coded 'word' has the address part (20bit) and the data part (4bit).
When I try to convert the binary 20 bit to decimal I have a problem.
If I use the 'word' up to 16 bit - all good.
Does FC8+Arduino Nano uses two 8 bit 'words' only?

Any help will be great.

Thanks.
Last edited by viktor_au on Tue Oct 11, 2022 12:46 am, edited 1 time in total.

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Binary to decimal problem

Post by viktor_au »

Found the solution

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Rx the TTL data from 433mHz sensor

Post by viktor_au »

Working on a code for 433mHz sensor data( rx only).

I used the IDE Arduino with RCSwitch library and looks like it works.
I can receive PIR information.
Now I need to make the FC8 program.

The TTL data format is:
protocol 1
pulselength = 350,
Sync bit = 1, 31
"0" bit = 1, 3
"1" bit = 3, 1
nvertedSignal = false
-----------------------------------
How to find the preamble

As I understood the code should flow (for Nano) as:
If Int0 (pin D2) has High
interrupt = 1
rx_state = 1
Start counter
Count 350uS,
If D2 value = 0
Stop counter
Get the microseconds and compare the result
Start counter
Count 350us 31 times (after sync bit pause)
Stop counter

As TTL data packet repeats several times, do it again.
Am I in the right direction?
Thanks

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

From the limited info I have on the 1527 it does look like a High has a ratio of 3:1 with a Low having 1:3 time periods. However I haven't found anything yet to suggest what these periods are. I suspect whatever is sending the data will be defining them.

The Preamble looks like a ratio of 1:31

So for example lets just say the time period was 250uS. It would take 4 x 250 = 1ms to send a bit ( 1 = high for 750us, low for 250uS or 0 =high for 250uS, low for 750uS ). Preamble would take 32 x 250uS = 8ms (high for 250uS then low for 7750uS).

If I had a scope I'd see what was coming out of the module and using the ratios establish the timing from there.

From that it should be relatively straight forward to get your chip to interpret.

I stress I haven't used the modules and I have limited info so I might be talking nonsense :) Hope not though....

Regards

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Thank you chipfryer27.

The last few days I was reading about some different protocols for 433.9mHz rf. There are a lot of articles on www, however most of them reapeat each other focusing on using some Arduino RF libraries without paying attention to protocols, pulse width, etc.
I have checked briefly the RadioHead library, tinyRf library,and VirtualWire library.
Later I spent some time with RSWitch library (worked well), Arduino IDE RCSwitch library worked on my Nano (even the rxb12 output is noisy). I could see the DeviceID and data state. However due to the fact that author of RCSwitch library used the struct function -- I stopped, as I had some problems converting the IDE code to FC8 (I think it is possible by removing the struct and creating variables for each protocol separately).
Later I paid more attention to the article "Decoding the Oregon Scientific Remote Weather Temperature Sensor".https://loune.net/. Author has bought an Oregon Scientific weather station and managed to save the outside wireless sensor data to db by writing the IDE code.
I tried his Rx code and it worked. However as author used the Manchester code and I used the PIR sensor CB61 with 1527 chip (couldn't find the type, looks like HS224spt with ocs Freq = 13.560) the resulted 01... string was wrong, but it worked.

Question
If I use Nano Timer2 to count 350uSecs, what would be the best way to do it?

I did the calculation, pls check it out for Timer2 (1:1)
----------------------------------------.
If count Timer2 to overflow: 256/62500 = 0.004096 or 4096uS.
I need to count to 350uS.
If count Timer2 to 178 and reset: 62500 / 350 = 178.5, 178/62500 = 350uS.
If I use variable as pulse_width (ULong):
Count Timer2 ticks to reach value of 178 (it should be 350uS)
pulse_width = pulse_width + 350, reset tick to zero, continue counting of flag this point(?).
Use pulse_width in program as the value for High pulse.
To get the length of Preamble:
Flag the High (end of 350uS) and wait for 31*350uS = 434000uS.
Will the next High show the beginning of DeviceID?
If not, is this a 24-bit Ev1527 protocol?
Repeat and recheck.
---------
Thank you.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

Not an expert on the Arduino family. The free libraries that are available make it a very popular choice though which eliminates a lot of behind the scene coding. The downside of that I suppose is that unless you are a programmer it is pretty much a dark secret as to exactly what is happening.

I'll have a look at some of the links you provided later as I'm just heading out now.

Regards

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

Only had a brief skim of the links.

Out of curiosity, how are you getting your figures? You mention that you are trying different libraries etc with limited success. How did you come to the figure of 350uS per pulse?

How does the output of the Oregon Scientific weather station relate to what I presume is your Kerui?

It may well be documented in the links, I just haven't found it yet :)

Regards

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Hi

About the pulse length...
RCSwitch library has file RCSwitch.cpp
Notice 1st value in string of values: 350uS for protocol 1 (24 bit)
-------------------------------------------------------------------------
Format for protocol definitions:
* {pulselength, Sync bit, "0" bit, "1" bit, invertedSignal}
----------------------------------------------------------

static const RCSwitch::Protocol PROGMEM proto[] = {
#endif
{ 350, { 1, 31 }, { 1, 3 }, { 3, 1 }, false }, // protocol 1
{ 650, { 1, 10 }, { 1, 2 }, { 2, 1 }, false }, // protocol 2
{ 100, { 30, 71 }, { 4, 11 }, { 9, 6 }, false }, // protocol 3
{ 380, { 1, 6 }, { 1, 3 }, { 3, 1 }, false }, // protocol 4
{ 500, { 6, 14 }, { 1, 2 }, { 2, 1 }, false }, // protocol 5
{ 450, { 23, 1 }, { 1, 2 }, { 2, 1 }, true }, // protocol 6 (HT6P20B)
{ 150, { 2, 62 }, { 1, 6 }, { 6, 1 }, false }, // protocol 7 (HS2303-PT, i. e. used in AUKEY Remote)
{ 200, { 3, 130}, { 7, 16 }, { 3, 16}, false}, // protocol 8 Conrad RS-200 RX
{ 200, { 130, 7 }, { 16, 7 }, { 16, 3 }, true}, // protocol 9 Conrad RS-200 TX
{ 365, { 18, 1 }, { 3, 1 }, { 1, 3 }, true }, // protocol 10 (1ByOne Doorbell)
{ 270, { 36, 1 }, { 1, 2 }, { 2, 1 }, true }, // protocol 11 (HT12E)
{ 320, { 36, 1 }, { 1, 2 }, { 2, 1 }, true } // protocol 12 (SM5212)
};

enum {
numProto = sizeof(proto) / sizeof(proto[0])
};

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

OK, understand now :)

Regards

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

Just a thought. I see 1527 decoders are available quite cheaply.These appear to pair with a transmitter and provide a 4-bit output, which I am assuming are the last four bits from the 24-bit signal (address+data). Maybe these could be used as they may simplify things (although if using multiple Tx then a method to identify each one would need to be implemented)

Nano should be able to decode the full 24-bit string though.

I'm assuming the 350uS pulse length is the length of a bit / 4, if I've not misunderstood.

1 = h,h,h,l = 1400uS
0 = h,l,l,l = 1400uS
Preamble = h,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l = 11200uS

Late at night rough (very) thoughts are

Identify preamble
Receive and store the next 24-bits (perhaps in an array)
If message is repeated "x" times then
Receive and store the next 24-bits in array #2
Repeat until message stream ends (array #x)

Perhaps compare the received messages and discard if all different, or proceed if say two out of three match? Maybe that doesn't matter and the Nano will respond to any matching address? Many options.

This link may assist, but confusingly it suggests preamble is a high for 350uS then low for 10mS (although I get a feeling that accuracy isn't the strong point of these modules)

https://www.microchip.com/forums/m1133876.aspx

Regards

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Hi

Nano should be able to decode the full 24-bit string though.
It does. I used RCSwitch library and it works. Nano does a job.

350uS pulse length is the length of a bit / 4...
I believe it is. If one bit = 4 clocks, the Preamble High pulse = 350uS+31 Low(350*31), the High bit pulse = 350*3=1050uS+ OneLow(350uS), the Low bit pulse = 350uS+3Lows.

Identify preamble
I thought
-----------------
to flag the preamble by using Timer2.
If D2 input = 1, start Timer2, count.
If D2 input = 0, stop Timer2 and save the value to variable pulse_high_duration.
Start the Timer2 again and count until the next High pulse will come. Save the value to variable pulse_low_duration.
---
Save both values to variable preamble duration.

Example:
Preamble High duration = 350uS, Preamble Low durat. = 350*31=10850.
Preamble duration = 10850+350 = 11200uS (as you calculated)
If this variable < 11400 >11000, flag the Preamble and
Work with 24 bits.

if D2=1. Start Timer2. Count. Save to variable pulse_high_duration. Stop Timer2.
If D2=0, Start Timer2. Count.
If D2=1, Stop Timer2. save the value to variable pulse_high_duration.
If variable pulse_high_duration > 300 < 370, AND
If variable pulse_low_duration > 1100 < 1000
->Save 0 to buffer,
Else
---
If variable pulse_high_duration > 1100 < 1000 AND
If variable pulse_low_duration > 300 < 370
->Save 1 to buffer

If bits count = 24:
Flag the end of the 24 bit, ignore the other packets and wait for the preamble again.
Be ready., or make a pause...
If device Tx the ttl data, get it again.
---------------------------------------------------------------------------------

About https://www.microchip.com/forums/m1133876.aspx
Preamble = 350uS mark time followed by a 10mS space time.
I think he is apprx. right as preamble LOW = 10850uS or 10.8mS.
-----------------------------------
Designer wrote in 2007
---------------------------------------------------
In main loop
*Wait for a "high pulse".(start edge of the preamble)
*wait until low.
* measure above pulse, If it is not around 350uS goto begin.
*wait until pin goes "high", (this will end the "low" pulse 10mS gap time of preamble)
*measure the "low" pulse, if it is around 10mS a valud preamble detected.
*from here measure the remaining 24 bits data bits.
-------------------------------------------------------------
Basically he's idea is:
Measure duration between 1st HIGH and LOW. If duration != 350, ignore.
If duration = 350, proceed to measure duration bettween 1st HIGH and 2nd HIGH.
If duration +/- = 10mS, mark/flag the preamble.
Proceed to work wit 24 bits part of the packet.
----------------------------------------
Need to read more https://www.microchip.com/forums/m1133876.aspx
Attachments
clock_1527_3.jpg
clock_1527_3.jpg (40.46 KiB) Viewed 252940 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

OK I seem to be on the same page as you with what is being captured.

You could certainly use timers to count pulse duration and if "near enough" then accept it as whatever. Alternatively you could sample in the middle of a time period and take this value. This helps to negate jitter/wander/length-of-pulse issues.

Using 350uS as time period and a bit length of 4 x 350uS = 1400uS

For detecting a "1" (h - h - h - l)
Detect high (beginning of pulse). Time = 0
Wait 1/2 time period and sample (Time = 175uS). Value = 1
Wait time period and sample (Time = 525uS). Value = 1
Wait time period and sample (Time = 875uS). Value = 1
Wait time period and sample (Time = 1225uS). Value = 0

For detecting a "0" (h - l - l - l)
Detect high (beginning of pulse). Time = 0
Wait 1/2 time period and sample (Time = 175uS). Value = 1
Wait time period and sample (Time = 525uS). Value = 0
Wait time period and sample (Time = 875uS). Value = 0
Wait time period and sample (Time = 1225uS). Value = 0

(Instead of actually waiting and counting Time every uS it would be better to perhaps sample as part of an interrupt being called every 350uS from middle of first pulse etc. I'm sure you get the idea)

Your code would possibly be less complicated and less subject to errors. If waiting for transition and timing the interval, any spurious transition would lead to incorrect readings. If sampling in the middle of a pulse then the glitch would need to occur exactly at that uS to be registered at all. You could add in various checks as you capture to ensure validity. For example both "one" and "zero" begin with a "high" so the first, fifth, ninth and thirteenth sample etc should be high too.

If you know that you will have preamble then 24-bits of data, with the data repeated three times then it would be easy enough to capture all the data just by continued sampling. As your code would only be busy sampling every 350uS it's got plenty of time to process what's been capture so far between samples (it's a "one", end of transmission, garbage etc).

Regards

viktor_au
Posts: 362
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 62 times
Contact:

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by viktor_au »

Hi

What to do?
One way -> use counter
2nd way (as you suggested) ->sample in the middle of a time period and take this value.
Last edited by viktor_au on Fri Nov 18, 2022 5:25 pm, edited 1 time in total.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 784
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 186 times
Been thanked: 205 times

Re: HC-12 433 mHz module + Ard + Kerui PIR

Post by chipfryer27 »

Hi

I'll have a look later as I'm just heading out.

A delay has the uC sitting doing nothing until elapsed, whereas sampling allows that time to be used elsewhere.

Regards

Post Reply