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

Sunday, January 1, 2017

Happy 2017



The card says: A Good Year 2017
And so I hope it will be for all of us: Happy new Year.

This is my girlfriend and my new years card we send to all our friends and relatives. I will briefly tell you how I made it.



First I searched a suitable image of a bottle on the internet. I manipulated it in The Gimp (GNU Image Manipulation Program) to make sure that the background was uniformly white and that the bottle outline was totally black.

Next I converted it to an SVG image using this link: http://image.online-convert.com/convert-to-svg



When I had the SVG image ready I imported it into 123D

Now I had the basic 3D object I scaled it to the right dimensions and made it 1mm thick.


I saved it as an STL file, imported that in my Repetier printer software, sliced it and then printed many copies.


All in all just a few hours work from which printing in different colors took the most time.
And we had a real unique New years Card.

Till next time
have fun

Luc Volders

Thursday, December 15, 2016

Making custom keys / switches

My girlfriends son visits us regularly. We enjoy the visits and what makes it even more fun is that he is a tinkerer just like me. We really had some great fun playing with Oobleck and we made an infinity mirror in a table for his home.

This time he told me he was looking at making a Midi-controller. As we discussed the project talking about the hardware (Arduino) he told me that he was looking for special keys for the controller. He did not want the normal hard keys. He wanted the kind of soft keys most remote controls have. And he wanted keys in different shapes. As he had searched the internet he had not yet found anything to his liking.

My proposal was to make custom keys with Oogoo. Oogoo is a mix of silicon caulk and corn startch like I described in the story you can read by clicking here.

He thought it was a great idea because Oogoo had the right feel for the keys he was looking for. But how to make custom keys with it. Well we would need to make a kind of mold. Easy said. And yes indeed equally easily done. This is a perfect job for a 3D printer.



So I started designing a simple square key in 123D-Design.

123D-Design is just like Tinkercad another great free program from Autodesk. Tinkercad is web-based. 123D-Design is a program you download in your computer. All the designs you make with it can be stored on your computer or (like Tinkercad) on the web. 123D-Design has several advantages over Tinkercad. It is faster, as it is not internet dependend, and it has some really nice features that Tinkercad misses. 123D-Design has a bit more steep learning curve for first time users. Therefore I advise to start with Tinkercad until you know all the basics of 3D designing and then switch over to 123D-Design.

When I had finished the prototype key and downloaded the STL-files I set my Beagle 3D printer to work,In the mean time I started to work at the contra-part for the mold. I enlarged the key part a bit and left the base for what it was. I enlarged the key with 2 mm on all four sides. That way they actual key would get walls which would be 2mm thick.





Then drew a solid box. I rotated the key 180 degrees and put it on top of the box but so that the key was positioned in the box and the base on top. Then I subtracted they key from the box and that's all there is to it. The counter part for my mold was ready.






So in about an hour time I had designed AND printed my first prototype.

We mixed up some silicon-caulk and corn-starch until we had a nice thick paste and put it in the molds counterpart and then we pushed the keypart in.



If you look at it it looks like something edible, but believe me it is not !!!!
As it was a nice day, one of the first warm spring days, we took our girlfriends out for a walk and let the Oogoo set.

We were just afraid that we would not get the Oogoo key out of the mold. Maybe it would stick to it and tear apart if we were going to get it out.

But everything went even better as expected. The Oogoo key came niceley loose from the mold without any effort.





And the result is perfect. It is not yet the perfect key we were looking for but it is an ideal prototype. We know we are on the right path.






It even gets better as the Oogoo is transparant. Therefore it not only possible to put a switch beneath it but we can also put a led beneath it. That way we can give the key an extra dimension. All colours give the key that nice extra finishing touch.





A few days after his visit I started experimenting further. And indeed it is possible to make all kinds of shapes for the keys. As the example demonstrates I can make round keys.




I even filled a box with Oogoo to see if that would work and yes I got a nice bar out of it.

What does this demonstrate.

It is obvious that Oogoo is a versatile material and suitable to make keys with for all kinds of projects. But this also demonstrates that it is really easy to design molds, print them in PLA and use them and re-use them. The Oogoo comes out of the mold easily and without damages.

I bet I even can make stamps and badges with Oogoo and someone suggested making anti vibration feet for a 3D printer. So go on, make your own christmass decorations or use your imagination and make ........

Have fun
Till next time

Luc Volders

Thursday, December 1, 2016

Check Check and Doublecheck !!!

One of my projects was nicely coming along. In reality it was just a stupid project being a portable thermometer using an ESP8266 that displays the temperature on a web-page. So nothing special. The breadboard version worked like a charm to I transferred it to some stripboard. And then disaster struck.

It just did not work. The dreaded blue smoke materialised and my ESP was fried !!! Damn what happened ???

So I checked my stripboard soldering over and over and I just couldn't find a fault. There was only one thing left to do: check the power supply.


 
My intention was getting power from a USB power source be it from a computer or a power bank.
For that reason I use cheap USB power cables from the dollar store. I cut the cable and strip the wires.




The wires are colored just like they need to be: Black for ground, Red for VCC Green and White for the USB data channels.




I hooked up a mulimeter and it looked allright. 4.9 volts is great. But hey look at that closely. It does not say 4.9 volt !!! It says - 4.9 volt.



So I took out my trusted polarity checker (find the sory on that by CLICKING HERE) and hooked it up. Black to Black and Red to Red. And then it was obvious. The red light was on. Polarity was reversed !!!!


And then I switched the power leads: Red on Black and Black on Red and there it was: the blue led went on: everyting. ok.

So there you have it: the color of the power leads from the USB cable were reversed. The GND was on the RED cable and the VCC on the black cable !!!! Some idiot in the factory switched the colors of the cable. Everything on the connector side was ok, just the colors of the cable had been switched.

So before you hook anything up:, NEVER TAKE ANYTHING FOR GRANTED and CHECK !!!! Check !!!! CHECK and DOUBLECHECK !!!

This is the first time I say in my web-log: this was no fun at all.

Till next time.

Luc Volders

P.S. Check and Doublecheck !!!

Sunday, November 13, 2016

Bubble level

At my job collegues use this bubble leveler. They had some spares and dropped them on my desk. They know I am a tinkerer and am always interested in all kinds of technical stuf.




This leveler is however small and I immediately had (as always) some wild (weird) ideas. For realising them I needed a larger leveler. So I started thinking on how I could make one myself. The general idea behind it is after all dead simple.






So my first stop (and only one) was at a DIY depot. There I found some clear plastic foodsafe tube. The outer diameter was 10mm and the inner diameter 8mm. So it was a thick tube with thin walls and therefore just what I needed.




I cut about 9 cm of the tube. Then I closed one side of the tube with my glue gun. Then I waited till the glue cooled down.


Next step was to fill the tube with water. I did not fill it totally as I obviously wanted a bubble. Then I  closed the other side with my glue gun.



And presto. It was done.

However the tube was not straight. As you can see it was bended. Now that is not really usefull for a bubble leveler.


To the rescue comes my faithfull Beagle 3D printer. So I printed a frame for it. Now it functioned it just like I wanted it to do.

So it works. But now what.

Well I have some ideas for projects for this. But to make it really usefull the contrast between the bubble and the water is not big enough. So I started experimenting with ink in stead of water. Well that was no success as the ink dried and I ended up with a tube with solid black walls.



So then I used syrup. A real dark syrup and that worked like a charm.

Just make sure that you test in a long term that the fluid you are using will not dry out and you'll have a cheap bubble-level.

Any of you have a clue on what I am going to make with this..........Hint: movement detection.

Till next time.
And have fun.

Luc



Tuesday, November 1, 2016

ESP8266 getting the right time with the LUA language

Sometimes you need the right time in your projects. For example when you need to registrate a sensor reading at the right time or date. Or you want to make a clock etc. etc. etc.

The easiest way is to put the time in your source code and then start your program. But that is not veryy efficient. Firstly you will get a delay by uploading the program to your ESP, second the build-in hardware times re surely going to deviate from the real time, and last but not least if there is a short power failure the program will start again with the time setting that is pre-programmed.

So I found a LUA program that gets the time on a weblog maintained by Peter Jennings. You can find the weblog here:

http://benlo.com/esp8266/esp8266Projects.html#googleTime

Now lets examine the code.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
-- retrieve the current time from Google
-- tested on NodeMCU 0.9.5 build 20150108

conn=net.createConnection(net.TCP, 0) 

conn:on("connection",function(conn, payload)
            conn:send("HEAD / HTTP/1.1\r\n".. 
                      "Host: google.com\r\n"..
                      "Accept: */*\r\n"..
                      "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
                      "\r\n\r\n") 
            end)
            
conn:on("receive", function(conn, payload)
    print('\nRetrieved in '..((tmr.now()-t)/1000)..' milliseconds.')
    print('Google says it is '..string.sub(payload,string.find(payload,"Date: ")
           +6,string.find(payload,"Date: ")+50000))
    conn:close()
    end) 
t = tmr.now()    
conn:connect(80,'google.com') 


Well the code is actually quite simple. It opens a web-connection to google.com then retrieves the information starting with Date: and there we have the time.

So when I loaded the program into my ESP I got the following result:



Anything wrong with that ??
Well yes. Actually I am living in the Netherlands. The program prints GMT time which is 1 hour off. Next there is no difference in summer- and winter- time so that puts the time another hour off. So for me the time is 2 hours off.

Now I could make an adjustment in the software for that but this would make things complicated. So I went looking for anonther solution.

This particular line:

    print('Google says it is '..string.sub(payload,string.find(payload,"Date: ")
           +6,string.find(payload,"Date: ")+35))


actually looks in the retrieved information for the word Date: and prints everything from Date: to the next 35 characters.
So lets expand this and see if we can find any thing interesting in then rest of the retrieved information. So I altered the code in:

    print('Google says it is '..string.sub(payload,string.find(payload,"Date: ")
           +6,string.find(payload,"Date: ")+5000))


And nothing happened. No extra information came up.

So I needed a different source.



I looked at the website time.is this site actually puts the right info on your screen. As the info on the site itself displays: Time.is displays exact, official atomic clock time for any time zone.

So let's see if we can adapt the code from Peter Jennings to our needs.





And there it is, right after the word Expires: the real time at my location.

So the adapted code is:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- retrieve the current time from Google

wifi.setmode(wifi.STATION)
wifi.sta.config("XXXXXXXXXXXXX","YYYYYYYYYYYYY")

print("Time Function")
conn=net.createConnection(net.TCP, 0) 

conn:on("connection",function(conn, payload)
 conn:send("HEAD / HTTP/1.1\r\n".. 
 "Host: time.is\r\n"..
 "Accept: */*\r\n"..
 "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
 "\r\n\r\n") 
 end)
 
conn:on("receive", function(conn, payload)
 print('Time.is says it is '..string.sub(payload,string.find(payload,"Date: ")
 +6,string.find(payload,"Date: ")+500))
 time = string.sub(payload,string.find(payload,"Expires: ")
 +9,string.find(payload,"Expires: ")+34)
 print("It is now ")
 print(time)
 print (" ")
a = string.sub(time,18,19)
b = string.sub(time,21,22)
print (a .. " hour")
print (b .. " minutes")

print(" ")
print(" ")
print("it is ".. a .. " hour " .. b .. " minutes")

 conn:close()
 end) 
t = tmr.now() 
conn:connect(80,'time.is') 

As you can see I made some small modifcations for your (and mine) convenience. The time is put in the variable called time (duh). I added 2 variables named a and b. They contain the hour and the minutes. This makes it easy to adapt to your own program needs. Next I printed the variables and printed a line in which they are used to display the right time.

Any flaws ???

Yes. Off course there is a pitfall.
The code gets the time from the internet by looking at your IP adress and getting info about this adress from your provider.  However it is possible that your provider is located in a different time-zone. Then you actually will get the time from the time-zone where the main acces-point of your provider is.
Here in the Netherlands that will not be a big problem as we are all in the same time-zone. However if you are living in the States or any other country that is divided in multiple time-zones you might run into a problem. That's worth checking before you use the modified code.

Till next time.
Have fun !!

Luc Volders

Saturday, October 1, 2016

Nuw: the resistor color code clock

I wanted to make a clock. Clocks can be cool. However the internet is filled with projects about making clocks, so I wanted to make something special. And that is how Nuw originated.

Nuw is an abbrevation of Nerds Ultimate Watch. It is ofcourse presumptuous to use such a name but hey I invented it so I can name it whatever I want.

I had this stupid idea about making a clock that displays the time not as usual in figures but in resistor colour codes. Let me explain.

Every maker/tinkerer knows about resistor codes. Resistors don't have figures printed on them that tell the value. No their value is expressed in colour codes. And these codes are an international standard. So let's look at the colours that represent the figures.




The real resistor colour chart is a bit more complicated as I needed. I just need the colors with the accompanying figures.

Now let us look at time.




We display the time as 2 figures for the hours, 2 figures for the minutes and 2 figures for the seconds.

Well that can easily be interpreted.
Looking at the table 12.30 would translate into Brown, Red, Orange and Black.

Lets take another example. 15.47 would translate in Brown, Green, Yellow and Purple.

Sounds easy.

To display hours, minutes and seconds I would need 6 RGB leds. As each led needs 3 pins for the colour this would add up to 18 pins on a processor. That would rule out an Arduino. I would need an Atmega2560 for controlling all these pins. And that would be a total overkill. So lets skip the seconds and keep it to the hours and minutes.

To achieve this I would need 4 RGB leds. As each led has 3 pins for choosing colour I would need 12 pins on a processor. I would also need at least 2 pins for attaching switches for setting the time. One switch for setting the minutes and another one for setting the hours. So that sums up to at least 14 pins. This means I should be using an Arduino. And I did not want to use an entire Arduino for just a clock. So I could take an Atmega 328, program it with an Arduino board and put it in a dedicated pcb. That should work but I did not like the idea.

I decided to take a different approach.

If I was to use Neopixels (WS2812 led's)  I just needed 1 datapin. Using two buttons for setting the time would add 2 datapins. That sums up to 3 pins on a processor. So I could use an Attiny85 !!! Now we're getting somewhere.

I herebye give you the schematics and the breadboard layout made with Fritzing
For clarity of the schematics I let the power lines to the neopixels out. They speak for themselves.





So I build a prototype on a breadboard and started coding.

Coding was actually easier as I expected.



I used the Adafruit Neopixel library and the Time library.

The code starts with initialising the libraries and then declares an array in which the colors that correspond with the figures are declared.

The function setresval() sets the resistor color code to the neopixels.
The first Neopixel should display the values 0,1 or 2
The second neopixel should display the values 0 to 9. These take care of the hours.
The third Neopixel should display the values 0,1,2,3,4 and 5
And the last neopixel should again display all the values from 0 to 9. These take care of the minutes.

The Time.h library takes care of the hard work. It automatically puts the hours forward if the minutes reach 59 and resets the clock to 00:00 if 24 hours have past.

At the bottom in the code is a function called keyhourl().
This code watches if a button (toets1 or toets2) is pressed. If that is the case it looks which button was pressed and accordingly add's 1 to the hours or 1 to the minutes. This ables us to set the time.
The neat part is that if you keep the button pressed the code will cycle through all values, so you do not have to push the button like a madman to get at for example 55 minutes.

The code works flawlessly.

The casing.

I first put the prototype on stripboard. That gave me an idea about how big the pcb would be. I soldered the switches on a separate pcb so I could arrange to have them at the side of my casing.

I would have loved to make a wristwatch however I do not own (or can buy easily) those nice Lipo batteries. So I had to use AAA batteries.

As the Attiny is not voltage critical, and neither are the Neopixels, I could use 3 AAA batteries giving me 4.5 volts which is sufficient.



Using Tinkercad I designed my casing.
You can find the design here:  https://www.tinkercad.com/things/6RO5IBVzPAn-nuwcase01
And the design for the lid here:  https://www.tinkercad.com/things/gOw2PweYORx-lid-for-nuwcase01

As at the time I was using my old Prusa I2 which is not as accurate as my new Beagle I designed the case without holes for the neopixels and switches. So I made the case solid and used a drill to make the holes.

The pictures below shows you how it is all put together.









It really works.

After getting used to it, it actually is quite easy to set the time.





I took the clock several times to my work and already have some collegues who yell at me: "Hey Luc it is already brown-green o'clock, time for a coffee break !!!"

The 3 AAA batteries supply enough current to let the clock work for about 8 hour.

A small flaw.

Well not exactly a flaw but a shortcoming. It is a bit difficult to distinguish brown, red and orange. This is due to the way colours are mixed in RGB-leds. If anyone has a better colour code for brown, red and orange please mail me the details.

Room for improvement ???

Yes there always is.

Small batteries so I could turn it into a real wristwatch would be nice.

Or I could attach a power supply to it. Should be easy. Any 5 volt supply (like a phone charger) could do the job.

Another Idea is to attach a RTC (Real Time Clock) so it would no longer be necessary to set the time.

When using a power-supply a blue-tooth connection with an Android Phone could easily be made for mail and sms alerts etc. It could even automatically set the time.

Replacing the Attiny with an ESP8266 is not a very big problem. However that would certainly need a power supply in stead of batteries. But then the ESP could fetch the right time automatically.

Oh and then this:

When you build this project and have it on your desk and people start complaining that it is to difficult to read the clock just tell them that this clock lets them contemplate on the concept of time.

This was a really fun project to figure out, design and build.

Now as usual the only thing that rests me is to give you the source code and the STL files so you can print one for yourself. You can find these on Github with the following link:


https://github.com/Lucvolders/NUW

Till next time.
Have fun

Luc Volders