This page contains projects submitted by our beta tester Hamish Steiner. Simple project for a motion activated light using RCWL-0516 https://www.elecrow.com/rcwl-0516-microwave-radar-sensor-switch-module-body-induction-module-4-28v-100ma.html using a wemos d1 and 5 ws2812b leds (as I have lots of these around) The RCWL-0516 has variable documentation available on the web. The setup in the pictures worked well for me. The VIN on the board needs to be over 4 V so connecting to the 5V on the wemos d1 mini worked well. The output seems to work well connected as in the diagram with no resistors needed.
On my network all the esp's are connected in the range 10.0.0.0 to 10.0.0.254 So once this code is running I can open the annexbasic toolbox, select UDP from the tabs then set remote ip address to 10.0.0.255 as this will broadcast to all connections from 10.0.0.0 to 10.0.0.254 set port to 60123message to send is whoisthere no spaces or quotes then click sendall button and I get back 10.0.0.102:60123 MotionLight 10.0.0.102 which lets me play with the code by typing 10.0.0.102 into webbrowser . If you set the program to autorun using the config settings , then its starts automatically when power is connected. CODE: radar.bas 'Motion Light 'Set up UDP port 60123 to I can find this module later udp.begin 60123 onudp udpreceive c = 0 ' use this as a counter light = 255 ' use this for light intensity D0=16:D1=5:D2=4:D3=0:D4=2:D5=14:D6=12:D7=13:D8=15:D9=3:D10=1 ' set up pin variables for ease of reading 'set up 5 neopixels to D3 neo.setup D3,5 'loop forever do radar = pin(D1) 'read radar z = light 'get the current value for the light output neo.strip 0,5,z,z,z 'set the lights to this value. This will be white light as R,G,B all = z 'If the radar detected movement then if radar = 1 then c = c +1 'increment counter else c = 0 'if no movement counter goes to 0 end if if c > 17 then 'if counter is > 17 then we have prolonged movement, so turn lights on but setting light to 255 (Maximum brightness) 'if you want the lights to turn on faster change this to if c > 1 then but they may turn on for any small movement light = 255 else ' if no motion then start dimming the lights light = light -5 if light <0 then light = 0 end if end if pause 150 loop until 1=2 wait end udpreceive: myname$= "MotionLight" udpr$ = udp.read$ if instr(udpr$,"whoisthere") <>0 then udp.reply " "+myname$+" "+ WORD$(IP$,1) ' return my name and the IP Address. end if return |