Post about your Basic project here

Moderator: Mmiscool

User avatar
By Electroguard
#67487 Image
As is, this project provides a simple activity sensor using a radar module (or PIR... and notice that the Wemos D1 mini has a useful 5v pin for powering such 5v sensors).

More usefully, a second unit can be used as a networked remote monitor for the first unit.

Image

I have purposely kept the script generic to offer easy networking without need for individual network configurations... so the same script runs both the Sensor and Monitor units (assuming the gpio's are not different).

Image
If both units had sensors they could act as remote monitors for each other.

Multiple remote monitors could be used with a sender if wished.

Multiple senders could also be used, but you'd probably prefer to include facility to send and receive individual unique IDs, which means modifying the code to send and receive your specific ID info. That's easily enough done by appending your own info to the end of
udpwrite udpaddr, udpport, "RemoteAlert" & "Your data here"
in the [TRIGGERED] subroutine, and obviously you then need to extract it in [UDPMSG] and respond as required, so that's down to you.

The project is intended as a useful 'starting point' to be taken further as wished, so hopefully the code should be fairly easy to follow and modify as needed.

Despite the project being based around a Radar module, the minimal hardware for the standalone unit is just any sort of sensor or switch or button for input to trigger alerts, and an LED indicator for showing local alerts.
Be aware that, unlike a PIR, a Radar sensor may detect activity outside of its line of sight, ie: behind walls or other obstacles.

The minmal hardware for a Sender is just a sensor or switch to trigger alerts.

The minimal hardware for a Monitor is just an LED indicator for showing remote alerts.
So it doesn't get much simpler than this, and offers much potential for adding your own knobs and whistles.

The Radar modules default inactivity timeout of 2 secs could be altered by changing one tiny SMD cap... good luck with that!
I would prefer to do it in software: Esp-Basic hardware interrupts are generated when their pin goes Hi or Lo, so basically it's a matter of not declaring a Clear immediately when the Alert pin becomes inactive in [TRIGGERED], but what you do and how you do it (eg: whether using a timer or blocking delay, and whether ignoring subsequent alerts during the extended timeout, etc) is up to you.

Note that interrupt sensorpin, [TRIGGERED] is not declared until the end of [BLINKIP] to ignore any sensor triggers until after the blink IP initialisation has completed.

The blink IP facility allows you to save the same generic script to all units, configure all their SETTINGS the same with appropriate SSID and password and set them all to Autorun, then power them online one by one (even out in the field), watching for their last IP address byte to be blinked out about 30 secs later (after wifi connection). It is assumed you already know your routers subnet address, therefore you just need to know what DHCP node address (the last address byte) it has been allocated so you can connect to it with your browser if needed.

Note that a zero is denoted by 10 LED blinks because none would have been very misleading!


EDIT
A dual-action button-press plug-in has been added at the bottom if anyone wants it.



Code: Select all'Activity Monitor - developed on Esp-Basic V3 A69
'Uses radar module to monitor activity
'One unit can be used by itself for stand-alone use.
'Two units can be networked without mods as a sensor Sender and receiver Monitor pair.
'In which case they need configuring with suitable wifi router SSID and password in SETTINGS
' plus configure for autorun (tick "Run default.bas at startup:" box in SETTINGS)
'Watch for the last IP address byte to be blinked on the local led after reconnection
' or use a serial port monitor at bootup to view their assigned IP address
'Repeated triggering extends Alert time, Clear is sent after the modules default 2 sec inactivity timeout

memclear
nodeIP = mid(ip(),instrrev(ip(),".")+1)
print ip()
buttonpin = 0 'Optional "Clear Alerts" button - needs a pullup resistor
buttonoff = 1 'Default button OFF state if using the optional hardware button
interrupt buttonpin, [PRESSED]
sensorpin = 5 ' From Radar or PIR module OUTput
sensoroff = 0 'Default sensor OFF state
'interrupt sensorpin, [TRIGGERED] has been moved to the bottom of [BLINKIP]
locLEDpin = 2 'Local activity alert indicator led or relay
locLEDoff = 1  'Default local alert pin OFF state (if is active high or low)
if locLEDoff = 1 then io(po,locLEDpin,1) else io(po,locLEDpin,0) 'initialise local led to OFF
remLEDpin = 4 'Remote activity alert indicator led or relay (optional Remote Monitor)
remLEDoff = 1  'Default remote alert pin OFF state (if is active high or low)
if remLEDoff = 1 then io(po,remLEDpin,1) else io(po,remLEDpin,0) 'initialise remote led to OFF
udpport = 1010  'Change port if wished, but don't forget to also change any other units
udpaddr = "255.255.255.255" 'Change to your own subnet if you don't want to broadcast to all
udpbegin udpport
udpbranch [UDPMSG]
localerts = 0
remalerts = 0
status = "Ready"
html "<BR><BR>"
textbox localerts
html "Local Alerts"
html "<BR><BR>"
textbox remalerts
html "Remote Alerts"
html "<BR><BR>"
textbox status
html "Last Status Msg"
html "<BR><BR>"
button "Clear", [CLEAR]
html "<BR><BR>"
button "Exit", [EXIT]
html "<BR><BR>"
timer 1000, [BLINKIP]
wait

[TRIGGERED]
if io(laststat,sensorpin) = sensoroff then
 status = "Local Clear"
 if locLEDoff = 1 then io(po,locLEDpin,1) else io(po,locLEDpin,0)
 udpwrite udpaddr, udpport, "RemoteClear"
else
 status = "Local Alert"
 localerts = localerts + 1
 if locLEDoff = 0 then io(po,locLEDpin,1) else io(po,locLEDpin,0)
 udpwrite udpaddr, udpport, "RemoteAlert"
endif
wait

[UDPMSG]
msg = udpread()
if instr(msg,"RemoteAlert") >0 then
 status = "Remote Alert"
 remalerts = remalerts + 1
 if remLEDoff = 1 then io(po,remLEDpin,0) else io(po,remLEDpin,1)
endif
if instr(msg,"RemoteClear") >0 then
 status = "Remote Clear"
 if remLEDoff = 1 then io(po,remLEDpin,1) else io(po,remLEDpin,0)
endif
return

[CLEAR]
status = "Reset"
localerts = 0
remalerts = 0
if locLEDoff = 1 then io(po,locLEDpin,1) else io(po,locLEDpin,0)
if remLEDoff = 1 then io(po,remLEDpin,1) else io(po,remLEDpin,0)
wait

[PRESSED]
if io(laststat,buttonpin) <> buttonoff then
 status = "Button Pressed"
 goto [CLEAR]
endif
wait

[EXIT]
status = "Halted"
end
wait

[BLINKIP]
'Blinks the last IP address byte, 0 is represented by 10 blinks
timer 0
blinkon = 200
blinkoff = 400
blinkpause = 1000
if locLEDoff = 0 then io(po,locLEDpin,0) else io(po,locLEDpin,1) ' turn led off
for pos = 1 to len(nodeIP)
 digitchr = mid(nodeIP,pos,1)
 if digitchr = "0" then digit = val("10") else digit = val(digitchr)
 for count = 1 to digit
  if locLEDoff = 0 then io(po,locLEDpin,1) else io(po,locLEDpin,0)
  delay blinkon
  if locLEDoff = 0 then io(po,locLEDpin,0) else io(po,locLEDpin,1)
  delay blinkoff
 next count
 delay blinkpause
next pos
delay 1000
interrupt sensorpin, [TRIGGERED]
wait
'----- End of script -----


Dual-Action Button-Press
Just copy the following code over the top of the existing [PRESSED] subroutine in the above code to provide alternative Short (<1sec) or Long (>1sec) button press actions - in this case a Short press 'simulates' a local Alert trigger whereas a Long press Clears accumulated alerts.

Code: Select all[PRESSED]
'Allows different actions for short and long button presses
stop = 0
if io(laststat,buttonpin) <> buttonoff then start = millis() else stop = millis()
if stop > start then
 if stop-start < 1000 then goto [SHORTPRESS] else goto [LONGPRESS]
endif
wait

[SHORTPRESS]
'Place to put users short-press button goto
goto [TRIGGERED]
wait

[LONGPRESS]
'Place to put users long-press button goto
goto [CLEAR]
wait
User avatar
By forlotto
#68484 How well does this work over all is there sensitivity adjustment for instance if I have a lot of birds in my yard will it spot all the birds all the time ?

Nice thinking on the 10 blinks for zero yes it could be very misleading good simple way to handle that one.

I have often thought of PIR or break beams to know if someone to show up at my house would be pretty cool only issue is to find low powered break beams it seems fairly difficult that stretch any decent distance most of them require some good power.

Good Project though got the wheels turning a bit my next project is going to be a bluetooth boombox for work using some old speakers I have laying around the house should be interesting to see how this goes heh first venture doing so but I scored an amp with bluetooth integrated for fairly cheap well see how it all turns out.
User avatar
By Electroguard
#68503 Hello forlotto,
The radar modules I've used are 1 quid each 'throwaway' pcbs which happen to match their 10m advertised range, unlike others, which have had various dissapointing shortcomings.

There is no onboard 'user adjustment' as such, other than changing the value of an smd component to reduce sensitivity.

These radar modules normally have an excellent 8m to 10m full-width detection spread, which can be reduced to a spotlight beam by placing inside a tin can, or increased forwards to about 15m by using a metal reflecter, or incresed to a 40m long by 2m wide beam by using a parabolic dish reflector (eg: an old satellite dish or metalised spotlight/headlamp/torch reflector).

The radar can 'see' through most thin non-metal materials, so it is simply a matter of restricting its sensitivity and/or field of view using eg: metal can or tin-plate for sheilding.
Conversely, you can mount it on a metal parabolic dish to get a longer tighter focused radar beam which could be a better equivalent to a beam-break detector - which are either double-ended (transmitter at one end and receiver at the other) or reflective bounce-back (which halves their range and sensitivity).
Another shortcoming of beam-breaks is they usually have such a tight beam that it is usually possible to either step over or crawl under without triggering, which wouldn't be possible with a focused 2m wide radar beam.

One of the great things about these radar modules is that they are so cheap (£1, free postage) that you can afford to experiment with human proximity detection add-ons for automatic internal lighting and sleep timers etc, so I don't think an inventive person like yourself would be stuck finding applications for them.
For instance... how about a 'magic table' using radar detectors mounted in tin can 'blinkers' underneath the table for sensing your hand movements above, so you could operate the TV or switch different lighting using table-top gestures! You could use the table as a mini menu system, using your left hand to select a left-hand device/function and your right hand to control the selected device. Just some food for thought.
User avatar
By forlotto
#68537 Interesting thoughts indeed.

Flip it around facing into a soup can you get less sensitivity and shorter distance with a more focused beam if I am understanding this right.

Heh as far and inventive it all depends on the day sometimes I have a million ideas and others I am blank I feel this is the normal modus operandi for many of us from my observing of others.

I just spotted the other thread though I am still curious if a yard full of birds would be setting this thing off left and right I would guess it would as birds have signatures on normal radar the type of bird is a small barn swallow we have lots of them so maybe maybe not.

I remember an older thread when you talked of purchasing these things will have to read some more. I'll have to see where you got them from. EDIT FOUND THEM: http://www.ebay.com/itm/122432080819 Whew 10m is quite the spread but if I angle it just right it should kill the neighbors motion from triggering it got to love living right in front of a farm lol lots of motion tractors farm animals farm equipment but the beauty is there is always someone here is the probability of someone trying to break in is small but still would be nice to have often I don't hear the door and we don't have a doorbell either it was a stick on wireless and the sucker blew off in one of the bad storms dunno where it went. I'd say the driveway is about 3 meters wide give or take so if I put it at a forward facing angle on my mailbox I may just have something that would be as good as a break beam or even better as you say.

Thanks for sharing this with our community this is excellent!