Wednesday, March 15, 2017

Micro:bit introduction


While surfing the net looking at my favorite technology sites I stumbled upon a small microcontroller board called the Micro:bit. I never really dug into that as it was not easily onbtainable in the Netherlands. And then suddenly my favorite (non-china based) reseller Kiwi-Electronics (I am not related to them in any way) was stocking them. So it drew my attention and I decided to buy one of these.

A bit of background.

In England the Micro:Bit was free of charge distributed amongst all 7th graders in schools all over the UK. It was a initiative of the BBC and some large names are involved like Microsoft, The British Council, Lancaster university etc. etc. The purpose is (like many years ago with the legendary BBC computer) to get kids coding.

Because the impact of distributing the Micro:bit for free amongst kids (1.000.000 pieces were given away) is so big there has to be a lot of assistance and there is.

There are several programming languages available amongst whom are Python, Blocks, Java, Microsofts Touch, Fuze Basic and Forth. ARM Mbed even has an on-line IDE for C/C++ development available at http://developer.mbed.org.
You can find many examples, projects and interactive programming on the official website: http://microbit.org

So what's the fuzz all about.




Well first Micro:bit has a great programming environment. At the microbit.org website just choose Let's code and you can choose from several languages which all have a web-ide. This makes programming a piece of cake. Many languages even have an onboard web-simulator so you can test your code before transferring tit (through USB) to the Micro:bit itself.

Next to that you can program it from an Android device by pairing it with it's build in Bluetooth. And naturally you can program it from my second favorite devellopment machine: the Raspberry Pi.

The hardware.

Besides having a great software backup the hardware is impressive.


The Micro:bit can use a USB connection (think powerbank) or batteries as a power source.
There are two buttons available for interaction with programs.
It has an array of 5 x 5 leds on which you can scroll texts or have simple graphics. The individual leds brightness can be controlled.

It's got 3 large I/O connections to be used as a digital input or output but also as an analog input.
And onboard there is a compass, thermometer and an accelerometer.
And last but not least the Micro:bit has build in Bluetooth LE so it can be paired with your smart-phone, tablet, Raspberry Pi or even another Micro:bit.

The first project.

So when I first laid my hands on a Micro:bit I started with scrolling some text on its array of leds. I downloaded a few examples and played a bit with it getting familiar with the programming environment.

Next step was a small project to test the analog input and the capability of controlling a servo. And that is what I am going to demonstrate here.

To test the analog input I used a flex sensor. Flex sensors are resistors who's value alter when you bend them. A variation on this are the pressure sensors who's resistance vary when you put pressure on them. Both kinds are rather expenisive. So you can substitute the flex-sensor by a regular potmeter.

However you can also make your own flex-sensors for next to nothing with some velostat. You can read how to build your own flex-sensors in an upcoming story. So stay tuned.

The hardware setup.



As you can see in the schematic above the setup is simple.
The flex sensor is connected with a pull-up resistor to pin 0 of the Micro:bit and the servo is connected to pin 1
I powered the servo and the Micro:bit seperately as I was afraid that the Micro:bit was not able to deliver sufficient power. In the end I was wrong. The Micro:bit is capable of powering the servo by itself, however that is pushing the limit of its onboard power regulator.



The picture above shows you my real-life setup.
At the bottom on the right side connected with the alligator clips is my home made flex-sensor in strecthed shape.

Reading analog

For programming I chose Microsoft PXT which is a block-based editor (like Scratch or App-Inventor) which translates the blocks into Javascript.


So the blocks shown here read the analog pin, then show the read number on the led matrix and pause 500 miliseconds before taking another reading. The Forever blocks makes thism program run infinit.


And this is the Javascript code it automatically translates into.

Adding the servo

Next step was to translate the reading of the flex sensor into a servo movement. This means that the more you bend the flex-sensor the farther the arm of the servo will turn.


The block code is really simple again.
I read the analog input and limit it on the upperside to 100 and on the lower side to 40.
The difference between the minimum of 40 and maximum of 100 gives me a range of 60 which can easily be translated into servo steps. A servo can move in 180 degrees. So each of my 60 steps represent 3 degrees of the servo.
So the program displays the angle on the led matrix and puts the servo in that position.
Done in essentially 13 lines of code.


And here is the translated Javascript code.

Fun

The Micro:bit is fun to play with. The PXT block editor is easy to use and gives results very fast. And the results can be tested by the build in emulator which makes it even easier to test your projects. I surely can see that this is a great tool to get children interested in programming and electronics. And for adults it is a fast way to learn the basics of Python and get immediate results.

Limitations and expansion


For what it is intended to do the Micro:bit is really great. However when you need to do some real world projects the 3 standard I/O ports are a bit limited and as the Micro:bit has no wifi it is really restircted in its communication.


For the adventurous amongst us there is a break-out board with headers. So attaching the Micro:bit with Dupont wires to a breadboard is possible and you will get a load of I/O ports on the way.


The picture above shows you all the available I/O ports when using the break-out board. You can find a full description of the pins on the Micro:bit website in this link https://www.microbit.co.uk/device/pins

These I/O ports will make the Micro:bit much more usable for projects. However it will then be more competing with the Arduino series of boards as there is still the lack of wifi communication.

The competitions answer.

In the educational world there is a big competitor for the Micro:bit being the Raspberry. Well the Raspberry is much more advanced as it is a complete linux machine with HDMI output to a TV screen or monitor. However the big barrier for the Raspberry for kids is its price-tag. The Raspberry Pi 3 costs about 39 euro which is a lot of money for kids. Do not get me wrong, the Raspberry foundation does a tremendous job in teaching kids programming with the Raspberry but loads of projects made with the Raspberry are real-world projects because it is a full fledged computer and a fast one to !!!



In comes the Raspberry Pi Zero. This will be a game-changer as it is a full Raspberry Pi (be it a slower version, it is a bit faster as the Pi 1) and has the incredible price-tag of 5.50 Euro. That's right a full fledged linux machine with USB and HDMI for less as 6 euro. And just released is the Pi Zero W which has on board Wifi and Blue-Tooth for just 11 Euro. Now that is amazing !!
This is a price-tag which is affordable for kids but also makes it a real competitor for Arduino and ESP projects.


Let's compare the prices of both; Remember that the Micro:bit was free distributed amongst kids in the Uk but if you want to buy one extra for your products it is at the moment that I am writing this about 14 Euro. So the Raspberry Pi Zero is about at one third of that price and even the Pi Zero W with Wifi and Bluetooth is cheaper.

There will be more stories coming up on the Micro:bit and on the amazing Raspberry Pi Zero. So watch this space.

Till then, have fun.

Luc Volders

Wednesday, March 1, 2017

Back to Basic - Basic language on the ESP8266


When I was a young guy of about 17 years old (we are talking 1976) I bought my first computer which was basically a bag of chips with a calculator keyboard and a calculator-like display. It was based on a RCA 1802 microprocessor and could only be programmed in machine language (thats even lower as assembly).



Later I moved on to the Commodore PET which was the predecessor of the Commodore 64. Just look at that beauty. At that time computers still looked like computers !! The Pet (personal Electronic Transactor) could be programmed in Basic which was a huge leap forward. I did marvels in Basic. I wrote a simulator for an assembly language that was ported to a Burroughs Mainframe and was used at the HTS in Eindhoven for study purposes. I wrote a database program (Elektronische Kaartenbak), a spreadsheet program (Volderscalc) and a complete accounting package (VOLAD) in Basic and all this on my faithfull PET with only 32K of memory.

And now in the age of Arduino and ESP-8266 I had to learn a whole bunch of new languages: C++, Lua, Python and HTML.

Basic as a language is nowadays looked upon as inferior by many programmers. The reason for this is that Basic has Goto statements. This makes it possible to jump from one part of the program to another part at any instance. To many programmers this kills structured programming and makes it possible to code like spaghetti.

So I was totally pleased when suddenly there was a Basic for the ESP-8266. And if I may say so not an ordinary Basic but a real splendid one. ESP8266-Basic has so many features build in that it is possible to read a thermometer sensor and display the values on a webpage in just 2 lines of code: amazing.

So lets do it: lets program in Basic on the famous ESP8266.

Installing ESP8266-Basic.

Before we can start programming in Basic we need to install the language on the ESP-8266 itself. Well that's a piece of cake. First download the ESP Flasher from this page:
https://www.esp8266basic.com/download.html

Put the Flasher in a sub-directory on your computer and start it.
The Flasher indicates the Com-Port on which it found the ESP8266 and you will have to tell it the amount of memory the ESP8266 has. For the ESP8266-01 choose 512K or 1M. For the NodeMCU and its varieties types use 4M.


Next choose Flash Firmware and the led on the ESP8266 will start to blink.





On screen you will see the flashing progres and after a while flashing is ready and the info on your screen will look as the picture above.

Wireles Station or stand-alone.

When Basic has been flashed into the ESP we can start using it.
At first ESP8266-Basic is not connected to your router because (off course) it does not know your routers nae and password to get access.

So ESP8266-Basic has to be connected to as an Access Point.

Start Wifi on your phone or tablet and look for the accesspoints. One will be called ESP followed by some number (which is actually the MAC adress of your ESP8266). Activate this accesspoint on your device and make sure it is connected to your phone or tablet.

For properly using ESP-8266 Basic you will need to use Firefox or Chrome as browser on your Android device.


Now start the browser and surf to 192.168.4.1 and you will see the start screen of ESP-8266 Basic.

As you can see I am using ESP8266-Basic 3.0 Alpha 51.
Now I am experiencing a small problem with this version and that is that not all menu items are directly available. So I found a way around this. Just follow the steps below and you're all safe.

First choose the menu item EDIT.

Edit starts with a program called default.bas which is not available in the ESP-8266. So we will make our first program. In the program area just type the first program line:

print "hello"

Next step is to click on Save. and that's it. You wrote your first program. Which is at the same time the workaround. All Menu items are available now.


Now if you click on Run Basic will run the program which just prints the word hello on your screen.

That's it.

The other menu functions

As you have seen there are several menu items available.

VARS
will give you a list of used variables and all the ESP pin states !!

EDIT
is used to edit programs like we just did above

RUN
will start the last Edited and saved program

DEBUG
is used to help you debug any faults in your program with a pause function, showing you which line is executed and at the same time showing a list of variables.






FILE MANAGER
is just what it suggests. You can browse your computer or Android device for files and upload them to the ESP. And you can choose in the file list the program you want to Edit, Delete or Rename. When choosing a program and choosing Edit you will be directed to the Edit screen.
The Filemanager menu was only available after I wrote and saved my default.bas program





SETTINGS
Settings is an important item. In settings you can put the name of your Access point and Password so you can access ESP8266-Basic from any device (computer, laptop or Android device) in your network. As I find my phones screen to small for daily programming I program ESP8266-Basic from my computer.
The Settings menu was only accessible after I wrote and saved my default.bas program.


Another important setting is wether ESP-Basic has to start the default.bas program directly at starting up. With this setting your program will automatically run each time the ESP is powered up.

Access from within your network.




After filling in your Accesspoints name and password in the SETTINGS page ESP-Basic will come up in your router as a new device.



Look in your router for the IP adress for the ESP and start a new window with the IP-adress as URL. So now we are ready to go.

Now why would I program the ESP from my desktop machine. Well it makes it easy to open multiple windows, search for Basic programs copy them and paste them in the ESP8266-BASIC EDIT window. Makes programming very easy.

Dallas 18b20




The Dallas 18b20 is the ideal thermometer. It has a wide range of measurement from -55 degress Celsius to +125 degrees Celsius. Its accuracy is 0.5 degrees Celsius and it is waterproof. So theoretically you can put it in aboiling kettle and measure the temperature. I have seen tinkerers putting one in a freezer to check the temperature. As it is waterproof you can use it for measuring outside temperature.

It uses a specific communiaction protocol and communicates over just 1 wire. There is a lot to tell about this wonder-thermometer but I'll save that for a rainy day.

Most important is that it easily communicates with ESP8266-Basic.

Measuring temperature with the Dallas 18b20

There is a ton on information about the Dallas 18b20 on the internet. And we do not need it at all for using it with ESP8266-Basic. You just have to remember one thing and that is that the Dallas 18b20 dataline NEEDS to be attached to D4 (GPIO2) on the NodeMCU board.


[EDIT] Oops !!! Just saw a mistake on the breadboard layout down here. I forgot to attach the 5 volt lead from the NodeMCU to the breadboard.So put a small lead from Vin (bottom right) to the VCC line.




Now that is done we need to write our Basic program. And here comes the neat part. We only need two lines of code:



So let us look at the program:

temnow = temp(0)
wprint temnow


First we read the Dallas thermometer with the command temp(0) and put it in the variable temnow
the second line puts the variable on the screen.

That's it.



The above picture is the result when we run this program.
The temperature with an accuracy of 4 decimals in just 2 lines of code.

Now this accuracy is fine but I want just 1 decimal for better readaility. Well here we go:



temnow = temp(0)
temnow = int(temnow*10)/10
wprint temnow


Save the program and run it.




The second line in our program multiplies the temnow variable with 10 and makes an integer from it. Next it is divided by 10 again and there we have our value with just 1 decimal.

A nice looking webpage

Now look at the next picture of a webpage.



It is the same temperature reading but now in a nice web-page with a background color, a header for the page info. The temperature reading in a contrasting color and a bar that indicates wether the temperature is lowering or rising. And 2 buttons of which one takes another reading and the other one stops this program.

Man, this must be complicated to program......... NOT

 memclear  
 cls  
 temnow = temp(0)  
 temnow = int(temnow * 10)  
 temnow = temnow / 10  
 wprint "<!DOCTYPE html>"   
 wprint "<html> <body>"  
 wprint |<body style="background-color:powderblue;">|  
 wprint |<H1><span style="color: red;">|  
 wprint "Thermometer"  
 wprint "</H1>"  
 wprint "</span>"  
 wprint |<H2><span style="color: blue;">|  
 wprint "Temperature = "  
 wprint temnow  
 wprint "</span>"  
 wprint "</H2>"  
 meter temnow, 0, 40  
 wprint "<br>"  
 wprint "<br>"  
 button "Again", [again]  
 wprint "............"  
 button "Stop", [quit]  
 timer 1000, [refresh]  
 wait  
 [refresh]  
 temnow = temp(0)  
 Wait  
 [again]  
 timer 0  
 run  
 wait  
 [quit]  
 end  


Just look at this source code. Most of it is HTML commands for formatting the page layout.
Putting a button on your web-page is done by the command:

button "Again", [again]

and the program just jumps to the label [again] if you press that button.

I think you can figure out the rest of the program for yourselves as it is dead-easy.

Neopixels

Remember the Neopixels. Those charming RGB leds for which you need just 1 dataline to control hundreds of them. Well programming them in ESP8266-Basic is a piece of cake.

But before you start using the Neopixels with ESP8266-Basic I urge you to read the story I wrote about the neopixels. You can switch to that story in a new tab by clicking here.
http://lucstechblog.blogspot.nl/2015/10/neopixels-ws2812-intro.html

 



First set up your breadboard like the above picture and connect the Neopixel data line to the NodeMCU D8 line. ESP8266-Basic uses this pin as its default pin for accessing the neopixels. You can alter this with the neo.setup() command. If you want to connect the neopixels to D7 for example you start the ptogram with the next line:

neo.setup(d7)

In the example below I used 7 Neopixels.

Now type in the editor the next program and save it:




neo.cls()

for x=0 to 6
neo(x,0,0,255,0)
delay 1000
next x

The Neopixel command neo() uses the following syntax:
the first parameter (x in this case) is the number of the neopixel in the chain starting at 0
The next 3 figures (0,0,255) represent the RGB code which is in this case blue
The last figure 0 in this case tells Basic to immediately change the color.

At first the Neopixels will be off. Then one by one they will light up in blue until they all display blue and the program stops.

Anybody who is familiar with programming will appreciate how easy it is to do amazing things with ESP-Basic.

IFTTT

A lot of automation can be done with IFTTT (If This Then That). IFTTT is much used by ESP-8266 enthousiasts as it easily can be used to trigger all kinds of events for IOT (Internet of Things) projects. One of the upcoming stories is how to use IFTTT to send a Twitter message if it rains using my rain-detector described in the story you can read by clicking here.

Adressing IFTTT can be a real pain in some of the programming languages.

In ESP8266-Basic it is just a few lines of code:

iftttkey = "XXXYYYZZZXXXAA"
trig = "maker.ifttt.com/trigger/givenotice/with/key/" & iftttkey
print wget(trig)

And that really is all !!!!



Making an API call has never been easier in any programming language (as far as I know).


Final Words

ESP8266-Basic is really easy to work with and well documented.


Essentially it is Basic with loads of built in libraries. This makes sure that we can focus on the actual programming and not on putting all kinds of code together for just getting some sensors to work.....

The above shown examples are just a very small part of what ESP8266-Basic is capable off. I haven't discussed Telnet, Serial communications, Timers, File I/O, using the ESP I/O pins, Oled-LCD and TFT screen drivers, web-interface commands, email, web-graphics, mathematic and string functions, i2c, SPI, UDP and even Infrared control.

I sincerely thank the maker MMISCOOL for bringing such a great product to the ESP8266. And I am certainly going to use ESP8266-Basic in my future projects.

You can find the official ESP8266-Basic website here: https://www.esp8266basic.com/
The official webpage also contains examples and the complete manual :  https://www.esp8266basic.com/language-reference.html
And you can find a ton of information, projects and examples  on the ESP8266-Basic Forum: http://www.esp8266.com/viewforum.php?f=38

So till next time
Have fun

Luc Volders

Saturday, February 18, 2017

Burglars invited

I am playing around with Thingspeak. Its a real nice IOT platform with loads of possibillities. I will delve in the setup and use in a future story but something urged me to publish this first.





Thingspeak is an IOT service to which you can send information from an ESP-8266 for example and have it published on a website that is publically accessible. For me it is ideal for testing purposes. The service takes the data I send to it, and puts it on a chart. This makes it possible for me to examine information from my home systems even when I am at work or abroad.

I made a simple thermometer setup using an ESP and a Dallas DS18B20 which sends my man-cave temperature to Thingspeak.




So I was monitoring the temperature in my work-room when I suddenly noticed something. Look at the graph above and try to see what I saw.



As you can see the temperature was dropping overnight until between 10.10 and 10.30 when the temperature had sharp risen.



At 11.40 hour the temperature started falling again.


And as you can see at around 16.40 the temperature started rising again. Neat huh ???

There goes the privacy

So when I got home from work and we sat at dinner I said to my girlfriend: 
" Hey you woke up late today. And I saw that you went out at about half past twelve and came back at around half past five."

First she was flabbergasted and then mad. It was a serious breach of her privacy.

But how did I know ??

Well easy. My girlfriend is kind of ECO aware. So at night she turns down the heating. When she wakes she turns it on and when she leaves the house turns it off again and naturally turns it on again when she gets back.

Well the temperature chart told me when she woke, left the house and entered it again.

Actually no harm done. And I promised her I would dismantle the system.

But it got me thinking.

So I looked again at the settings of Thingspeak. Next to your data you can display a chart with the location of the measurements !!!


So I made this test and indeed it displayed the location I filled in next to my temperature chart. Wow.

And rest assured I am not living below sea-level I deliberately gave false coordinates.

A bit of searching on Thingspeak showed me several channels where people actually displayed data publically next to their location like the picture above shows.





Look at the chart above. It is an actual public channel I found on Thingspeak.
I guess the guy leaves it home at about 7 o'clock (that's when the temperature starts dropping) and returns at around 20.00 hour because at that time temperature start rising again.

And be aware of this: the displayed map is a Google map so you can zoom in until you are at street level !!!


Naturally the displayed data is just data from a bit more as 24 hour. However someone with false intentions might come back everyday to have a look at the chart and see a pattern..........
 

Burglars invited !!!

So please be carefull on what information you make PUBLICALLY available on IOT platforms. If it is private information make sure you checked the private checkbox in Thingspeak. And do not blame Thingspeak for any privacy breaches the users have inflicted on theirselves.

In a future story I will delve deeper into Thingspeak as the service is easy to use, full of possibillities and very usefull.

Till next time
Be carefull but have fun

Luc Volders

Wednesday, February 1, 2017

Urban Farming and Technology


On saturday 18 february there will be a festival in Rotterdam. The festival is called Ergroeit. Roughly translated as "There grows"

This is the 5th time this anual festival is organised around Urban Farming in Rotterdam the Netherlands.





And it is organised by "Eetbaar Rotterdam" which means as much as Edible Rotterdam.

Part of the festival is a cross-over section. Where technology meets farming. The intention is to show how technology can be used by hobbyist and aid in Urban Farming.

And that is where I come in.
I have been asked to give a lecture/demonstration on how to build sensors that can aid in Urban Gardening.






I start with a bit of history about computers and how it evolved to the ESP-8266 chip that we as hobbyist can use to make all kind of sensors that can send information over wifi to your phone so you can monitor processes from where ever you are.

The sensors I am going to demonstrate are:
- Rain sensor
- Temperature sensor
- Moisture sensor that activates a waterpump.

Here is a link to the website where you will find the complete festival program and a list of all lectures (mine is on the 6th place).
http://www.eetbaarrotterdam.nl/ergroeit-2017-workshopoverzicht-programma/

So no high-tech project this time.
But next time.....
Till then
Have fun.

Luc Volders

Sunday, January 15, 2017

PIR Basics - Movement detection


A PIR is what we normally call a movement detection sensor. You can find it in all kinds of security devices but also in the lamp that switches automatically on when you approach it. The official name is Passive Infra-Red sensor.

I ordered some PIR's from a chinese supplier just for testing purposes and maybe some fun projects. And I have this vague idea to incorporate it in my domotics system.

So before I start serious work with it I needed to test it to see how a PIR functions.










The above picture shows you first the actual sensor. But this is not how we see it. The sensor is incapsulated in a plastic lens. A so called fresnel lens. This is the familiar white bulb you can see in the first picture in this story. This plastic white bulb has, as you can see, several sections. These are designed in such a way that the sensor will get information from a very wide angle and range.

In reality there are 2 infra-red detectors (within the same sensor) placed next to each other. Placed in front of it is the lens. The two infra red sensors get the same information but when something in a room moves one sensor gets different information than the other one and that triggers the PIR.

The PIR has 3 connections Ground, VCC and Signal. It is recommended that tthe power supply does not exceed 6 volts. Your specifications might vary however. If there is no information available I suggest to hold on to this golden rule.

The PIR operates at 5 Volts. This is fine for Arduino projects but makes it a bit more difficult in ESP8266 projects. Naturally I tried to operate the PIR at 3 volts and you can really forget it. It just will not work.

First tests.

First lets look on how the PIR will be connected.

Well actually there are a few models PIR out in the wild and it seems that they have different connections.




If you look at the image above you can see that in my particular case the VCC is on the left connection, the SIGNAL in the middle (I isolated it with some tape) and the GND on the right connection. But please examine your PIR closely to see if your connections are likewise.

I have seen designs on which VCC and GND were exchanged and I even have seen a version on which the SIGNAL lead was on the left connection (seems to be the Parallax brand version). So please check your PIR closely.

Fortunately the PIR has a safety diode which prevents harmfull connections. Off course: CHECK yours might be different.

And there is an extra option for the really adventurous amongst us.





The PIR has an on-board voltage regulator of 3 volts.
So any of you feeling lucky you may surpass that controller and feed it with 3 Volts. This will make experimenting with an ESP8266 easier, however I am not advocating this and will not go into details about this. Do this on your own risk.

Take it slowly.

My first impression was that the PIR was not working. I could not get a meaningfull read-out.

What I did was to attach te PIR to a battery setup and used my Multimeter to read the signal. And all I got was gibberish.

Well in the end it occurred to me that the PIR has to settle first before you will get meaningfull results. And that settling takes with my version about a minute.
So when you Power up your PIR you'll have to wait a minute before you will get meaningfull results.

Sensitivity

Next step is to set the sensitivity.

The PIR has 2 potentiometers which you need to tweak for finding your optimum settings.

Looking at the top side of the PIR the right potmeter adjusts sensitivity, and the left potmeter duration. Again: this might be different with your version so test it.



Look at my settings. The right potmeter is turned to it atmost left position. This gives the highest sensitivity. This means that the PIR will detect movenment from a few centimeters away to a few meters.

You will have to determine that exact maximum distance in you particular case as it may vary. The specs I have found on the internet stated that the maximum distance can be as much as 6 meter. However do not take my word for it and experiment.

The left potmeter determines how long the SIGNAL line will be in the HIGH state when movement has been detected and how long it will be off.

As you can see I have turned it to the atmost right position.
When movement is detected the Signal will go HIGH for about 6 seconds, and then it will turn off again for about 6 seconds and then looks for movement again.
If the person in the room keeps moving the SIGNAL will remain HIGH and only gets LOW when no movement is detected again.

Simple setup.

In it's most simple form a setup for testing can be as the next breadboard setup and schematics show you.










Unfortunately I have not found a Fritzing part for just 3xAA batteries so I had to use the 4xAA version. But as you can see from my setup I just used 3AA batteries which supply about 4.5 Volts which is enough for the PIR to work.

As you can see I printed my own battery case. The connectors were made from paperclips just as described in this story (click here).

Those that want to print their own battery case can find the STL files in my Github repositry by clicking here.

So what happens is as follows.
As soon as the PIR notice some movement the led lights up ans stays on for about 6 seconds. After that, if no mevement is detected, the led goes out and satys out for another 6 seconds after which it will look for movement again.
If movement is detected and the person keeps moving the led stays on.

What can we do with it.

The easiest step is to attach a relay to the PIR and connect a lamp. This way the lamp will go on as soon as movement is detected. A very easy setup that can be bought in many DIY stores as a burglar alarm or just a device to make it easy to find your keyhole in the dark.

Another example is attaching the PIR to a photocam. Place the setup at a bird (fill in: deer, wild boar etc) feeding place to make pictures at the right moment.
Attach a PIR with a relay to your garden sprinkler installation to scare the shit out off cats/kids/mailmen trespassing your garden.

And by attaching the PIR to an ESP82566 a whole lot of projects come to mind. For example a burglar alarm which sends notice to your phone, or a mailbox alarm which notifies you if you got mail. And off course the obvious domotics application that turns on the lights in a room but only when it is dark AND a peron is in the room.

Just use your imagination.

In a follow up story I will be discussing the attachment of a PIR to an ESP8266.

Till then: Have fun

Luc Volders