Saturday, May 26, 2018

Vibration detection

For an index of all of my stories click this text

I found this neat vibration detector called SW-18010P which just costs a few cents.



As you can see it is a very small sensor almost the height of a paperclip.
This makes it possible to build in secretly in all kinds of objects.

What does it do. Well exactly what the name indicates: it detects vibration. And it is very sensitive. Let's have a look at the inside.


As you can see the interior is very simple. It is a wire that as a matter of speak floats in a coil. So as soon as there is some vibration the wire will touch the coil and current can flow.

When I first received these sensors I thought they were broken. I tried to measure the contacts with a multimeter. However the vibration has such a short timespan that the multimeter is to slow to react on it.

So I decided to set up a test with a Wemos ESP8266 on a breadboard.



As far as I know there is no Fritzing part for this sensor so I used a reed-contact part for the schematics. As you can see the setup is simple.

The sw18010p is connected with a pull-up resistor to pin D2 of the Wemos.


Next I wrote a short program in ESP-Basic to test it.
It is very simple and straightforward and could easily be ported to Arduino code or Lua or whatever your favorite devellopment language is.

interrupt d2, [vibrated]
wait

[vibrated]
print "it moved"
delay 500
wait

Testing the IO port for a change from 1 to 0 could work. I intentionally say could as the vibration can easily be missed as it has a short timespan. Therefore an interrupt works best.


You can easily adapt this for use with an Arduino, Attiny or Raspberry PI or any other microcontroller of your liking.

I have a really good idea for a project with this, so keep coming back. In the mean time here are some ideas for which you could use this sensor:

- a box that reacts on knockin on it
- is the drawer being opened
- is the door being opened
- has my bike moved
- is somebody trying to steal my cookies

I am sure you can think of a few projects yourself. Basically anything that moves can be spied upon.

Till next time
Have fun

Luc Volders

Saturday, May 12, 2018

Washing Machine monitor

For an index off all my stories click this text.

Like most people we have a washing machine. No problem. There is however one annoying thing.

The washing machine is on the ground floor. And my girlfriend (who operates it, how bout that division of tasks) who is a painter has her work-place on the second floor of our house.
Now the washing machine will just shut down when it has finished its task. However when she is in her work-room she can't see that. So she has no other indication wether the machine has finished its task, as to leave her work every now and then and go downstairs to have a look. Waste of time and annoying. Surely there has to be an easier way, and there is.

Washing procedures.

The first thing to do to find an easier way to check if the washing machine has finished it's job is to look how it operates. Well that is fairly simple.



When the machine is put to work the led display and all kinds of indicators are on.



When the machine finishes it shuts itself down putting all indicators off. This offers possibilities.

It is about the same as checking wether the refridgerator door is open or closed like I did in this story:
https://lucstechblog.blogspot.nl/2017/03/cheapskate.html
I just wanted to make it a bit more fancy.

Overvieuw.

The ESP8266 is what I am going to build this with. I could not use the ESP-01 as I needed an analog input for the LDR, next to more I/O pins. So I used a NodeMcu. I am going to check the display of the washing machine with an LDR. Next to that I am going to attach a pushbutton to start the monitoring and a led that indicates that monitoring has indeed started. That is all we need for the hardware.
When the washing machine has finished I want it to send a signal to my girlfriends mobile phone. I am going to program the NodeMCU in ESP-Basic and use the Maker Channel from IFTTT for sending notice to the mobile phone.

For detailed information on installing ESP-Basic and use check this page:
https://lucstechblog.blogspot.nl/2017/03/back-to-basic-basic-language-on-esp8266.html

The hardware

Not much to it. Here is a list of what you'll need:

- NodeMCU
- USB Power supply (or powerbank)
- 1 led (I choose a green one)
- 1 220 ohm delimiting resistor for the led
- 1 Push-button
- 1 10K pull-up resistor for the button
- 1 LDR
- 1 10K pull-down resistor for the LDR



So for testing purposes I put everything on a breadboard.


 And here is how the prototype looks in real-life.

The software


io(po,d7,0)
timer 1000,[test]
interrupt d1, [change]
wprint |<body style="background-color:LightSkyBlue ;">|
wprint |<span style="color: red;">|
wprint |<h1 style="text-align:center;">Luc Volders</br>Washmachine</br>Monitor</br>|
wprint "<br/>"
wprint |<span style="color: black;">|
wprint "LDR measures "
textbox value
wprint "<br/>"
wprint "keypress "
textbox keypr
wprint "<br/><br/>"
button "<h2>Off</h2>", [Off]
wprint "<br/>"
wait

[test]
value = io(ai)
if (value < 600) and (io(laststat,d7) = 1) then
   keypr = "ready for use"
   print wget("maker.ifttt.com/trigger/wash-finished/with/key/YOUR-PERSONAL-KEY")
   io(po,d7,0)
endif
wait

[change]
if io(laststat,d1) = 0 then 
   keypr = "running"
   io(po,d7,1)
endif
wait

[Off]
end

First a timer is set that will jump to the [test] routine which checks the LDR value every second. And an interrupt is defined that checks wether the button has been pushed.

Then the software starts with building a webpage which you can look at on your computer, phone or tablet. This is not necessary however convenient for testing and debugging. You can find the webpage by looking in your router at the IP-adress of the ESP and then pointing your web-browser to that IP adress like discussed here:
https://lucstechblog.blogspot.nl/2017/03/back-to-basic-basic-language-on-esp8266.html

The [test] routine then checks every second the value of the LDR.
The if statements tests wether the LDR measurement is below a certain value AND the LED is ON. If that is the case the washmachine has finished and the monitor program is working. The alert is send to IFTTT. The LED is then set OFF so that if the test is run again, no alert is send unless the LED has been set on again by pushing the button.

Replace YOUR-PERSONAL-KEY with your own personal IFTTT key, and if you like replace wash-finished with any other name you like as a trigger. Just make sure you use the same name in the next steps where you will create the IFTTT applet.

The [change] routine tests the state of the button and if that is 0 (button pressed) the LED is set ON.

That is all.

Testing.

Start with commenting-out the IFTTT trigger in the ESP-Basic program. Otherwise you will get notifications on your phone with each test you perform. You can do that by setting a ' in front of the line you do not want to run. In this case in front of the print wget( etc etc etc line.

For testing purposes I taped the LDR to the washing machine with some dark painters tape. I carefully looked at the values that appeared on the webpage when the lights of the washing machine where on and off. I tested with different environment lightning like open and closed curtains and on and off ceiling lights.Then values are shown on the ESP's webpage which will look as follows:


That gave me the right values that the LDR would register and I put those in the Basic program at the following line:

if (value < 600) and (io(laststat,d7) = 1) then

Replace the figure 600 with the value you will find.

Now uncomment the wget line by removing the '

Create an IFTTT applet

First make sure you have an IFTTT account and are connected to the Maker Channel. If everything went well you will have your personal IFTTT key. Fill that key in at the right place in the ESP-Basic program.

Start with choosing to make a new applet.



Click on the blue +this

Now choose a service. You are presented with many possibillities bus just type in web and then webhooks will emerge.

 Now choose a trigger. Not many choices at this moment but sufficient for our purpose. Click on "Receive a web request"



Complete the trigger fields. I typed Wasmachine monitor but replaced with wash-finished. Use exactly the same name as is filled in in the ESP-Basic program. Otherwise the IFTTT part will not work.




Now click on the blue +that

The IF part is done now we need to make the THAT part. Choose an action presents you again with many possibillities however type in no at the search functions and Notifications will emerge. Click on that.


Again not many choices so use the "Send a notification" action.

Fill in any text you want to be shown on your phone when the washmachine has finished. I chose the utterly original "The wasmachine has finished"


The final check

And you're done.

Autostarting the program.

Go back to the ESP-Basic editor and rename the program in default.bas and save it.

Now go to the SETTINGS page



Make sure you check, at the bottom, that default.bas is run at startup.

Real-life use.

You will have to have IFTTT installed on your phone/tablet and running

Plug the USB-Power plug in the wall and wait about a minute. The NodeMCU will by then have booted and the default.bas program will be running.

Set the washing machine ON and press the button on the breadboard.
The LED on the breadboard will go ON.

Just wait till the washmachine has finished, or shut the power down manually.

The LED on the breadboard will go OFF and you will get (when activated) an audible alert and maybe a blinking led on the phone/tablet.


On the start-screen of your phone you will see the IFTTT logo on the left upper part.


And this is what the notification screen on your phone will look like.


If you would open your webbrowser and point it to the ESP you will also find a notification on the webpage.

Additional benefit

Girlfriend Happy !!
And that is the best part.

Now I only have to put the hardware on a stripboard and then design and print a nice casing.

Till next time.
Have fun and keep your partner happy.

Luc Volders

Thursday, April 26, 2018

More I/O pins for your ESP-01


For some time something was nagging me.
I have always learned that the ESP-01 has only 2 I/O pins being GPIO-0 and GPIO-2.

The module has some more pins but they have dedicated functions. There is the Reset pin, the VCC and Ground pins and the CH-PD pin which has to be connected to VCC to let the chip function. Next to that there is the RX and TX pins but they are used for programming the chip.

Ehh are they ???

Well yes they are, but only in certain circumstances.

Lately I have been playing with ESP-Basic which is really great. It is a very usefull programming environment for the ESP8266 with loads of features and it gets the devellopment job done in a real short time. Really worth checking out.

Now ESP-Basic has one very convenient feature: it programs the ESP-8266 over the air (OTA). That means that when you have uploaded ESP-Basic to the ESP chip no more attachment is needed to your computer to get your Basic program into the chip. You only have to power it and then you can program it over wifi from your computer, notebook, tablet or even your phone. So there is no need anymore to carry around a notebook with a programming environment. The Basic interpreter is in the chip and your web-browser is your programming screen.



My usual devellopping setup is a Node-MCU which has many I/O pins. And I read on the ESP-Basic forum that it is possible to use the TX and RX lines as I/O lines. There: you might have learned something new here. They can be used as D9 and D10 and labeled GPIO-1 and GPIO-3.



Hey wait a minute.
The ESP-01 also has a TX and RX line. So would it be possible to use those as I/O lines.

The answer is YES but with some restrictions.

Above is the ESP-01 pin-out. You can see GPIO-0 and GPIO-2 and the TX and RX lines.

So let's make a simple setup on a breadboard.


The leds are connected through a 220 ohm resistor for delimiting power consumption.
GPIO-0 (yellow wire) is connected to the first led.
GPIO-1 (white wire) is the TX line connected to the second led
GPIO-2 (brown wire) is connected to the third led
GPIO-3 (green wire) is the RX line and connected to the fourth led.

It does not work !!!

Off course it did not work !!
The GND line is connected to the leds and supplies a minimal charge to the GPIO's. Therefore the ESP will not boot anymore when powered up. Remember when GPIO-0 is put to ground at start-up the ESP goes into programming mode. And we definitely do not want that. So we need the following setup.



As you can see the GND is interrupted by a switch. So we set the switch in the off-position at power-up time and after that switch it to the GND position.



And hell yeah everything works as expected.


 
I even tested it running on batteries.



timer 1000, [blink]
button "off", [gooff]
wait

[gooff]
end

[blink]
for i = 0 to 3
  io(po, i, 1)  
  delay 1000
  io(po, i, 0)  
next i
wait

To test this setup for yourself use the above small basic program.
The program is straightforward. Every second it calls the blink routine which blinks GPIO-0 to GPIO-3 by using a for-next loop. 




It has been running on my desk for many hours without crashing. So it definitely works.

Another test


button "0" , [pin0]
button "1" , [pin1]
button "2" , [pin2]
button "3" , [pin3]
button "alles off", [alloff]
button "off", [gooff]
wait

[gooff]
end

[pin0]
io(po, 0, 1)
wait

[pin1]
io(po, 1, 1)
wait

[pin2]
io(po, 2, 1)
wait

[pin3]
io(po, 3, 1)
[alloff]
for i = 0 to 3
  io(po, i, 0)  
next i
wait

Just to make sure that using the TX and RX lines as an output line would not interfere with normal Wifi operation of the ESP I wrote a simple Basic program that makes a web-page with buttons on it.


Pressing one of the buttons turns on the accompaning led. 


And this also worked flawlessly. As you can see. The picture shows that I turned on GPIO-1 and GPIO-3 over wifi. So the wifi communication does not interfere with the GPIO lines.

Any restrictions.

Well actually yes.
You can not use the extra pins as I/O pins. You can only use them as OUTPUT pins.
I tried using them as an input and they would just crash the ESP.

That is actually predictable as the ESP will look at the TX and RX lines for incoming communication and you will still need them when re-flashing the ESP for C, Lua, Python or other languages.

Not only Restrictions but Advantages

You can use GPIO-0 and GPIO-2 as input and GPIO-1 and GPIO-3 as output. This setup just gives you the possibility to have 2 inputs AND 2 outputs or 4 outputs on this tiny chip.

Summerising the setup:
- It will only work when programming OTA (over then air)
- GPIO-1 and GPIO-3 are only outputs
- Make sure there is no GND connection at booting

There are still some things to check:
- will this work with Python or Forth
- will this work when programmed with an FTDI (programming board) and then detached and operating as a stand-alone setup

So again something new to experiment with.

Till next time
have fun

Luc Volders

Friday, April 20, 2018

Flex and Pressure sensors.

For a complete index off all my stories click this text

Up to now I have used all kinds of sensors for observing my environment like a rainsensor, soil humidity sensor, light sensor (ldr) etc. There is one sort of sensors I never had the chance to play with and these are the flexible and pressure sensors. Oh it is easy to just order some from Ali-express. However I think they are far to expensive just to play with, as I have no real purpose for them yet.

Then I noticed that my favorite Dutch electronics supplier (Kiwi Electronics) was stocking Velostat. As I had been searching for this for a long time I decided to get some to play with.

Velostat




Velostat and its alternative (competition) Linqstat is a special sheet of thin plastic. Industrially it is sold in large rolls. And what is special about it is that it is conductive.


This feature makes it an ideal packaging material for electronic prints and components that are sensitive to static electricity. This also makes it usable for us hobbyists.

The interesting part is that if you bend it or put pressure on it, it's resistance alters. And an altering resistance can be measured.

Therefore we can make flexible sensors and pressure sensors from this material at a relative low cost.

Where to get it.

As stated it can be bought in the Netherlands from Kiwi Electronics, SOSSolutions and Floris.CC.  When you are not living in the Netherlands best choice is looking at your local Adafruit dealer or order it direct from Adafruit.

You may be able to obtain it for free though. If you have a computer or electronics dealer nearby ask them to save the black plastic bags in which electronics are shipped. Good chance there are some Velostat bags amongst those.

How does it work

Velostat is a thin piece of plastic that is as said is conductive. In the normal state the molecules are at a certain distance from eachother.

 As soon as there is pressure exercised by bending it or by just pushing on it the molecules are pressed together and therefore make more contact mutually which lowers the resistance. This can off course easily be measured by a multimeter.

How to make a flex sensor.
 


What you will need is shown in the above picture. A small strip of Velostat, some tape and two strands of uninsulated wire.



I started with cutting a small strip of velostat from my large sheet. Next I took some copperwire which I pressed onto some tape.






I put the velostat on top of that and added on top another piece of copper wire pressed onto some tape. Just make sure that the wires do not touch eachother.



And above you can some of the multimeter readings which are significant different when the velostat is stretched or bent. I found maximum reading of 2400 ohm and a minimum reading (when bend) of 300 ohm. Very promising.

There is room for improvement. There is little contact between a narrow copper wire and the wide velostat. So I guessed I could get better results with a wider replacement for the copper wire.


DIY shops sell aluminum tape which is cheap and conductive. I had some lying around and decided to use that instead of the copper wire.

The results were impressive. When stretched I had a maximum resistance of 6000 ohm. When bend I met a minimum resistance of 200 ohm. And these are just the max and minimum values. There is a scale. Meaning that the more you bend the velostat the less the resistance will be.

Somewhere on the internet I read a story on how someone used two strips of Velostat on top of eachother to get a better result. I had to try that also.



I started by cutting 2 Velostat strips and 2 smaller strips Aluminum tape.


The first strip Aluminum was put on some tape in such a way that the aluminum would be pressed to the Velostat.



The first strip of Velostsat was put on top.


Then the next strip of Velostat was put on top of the first and the second strip of Aluminum was again put on top.


Then a strip of tape covered the whole sandwhich to keep everything together.


The excess tape was removed and measurements were taken.

In stretched form I measured a resistance of about 2 K and in bend position I measured a minimum resistance of about 115 Ohm. So strangely two strips of Velostat pressed together gave a lower resistance as 1 strip did.

I therefore decided to stay with the single strip for the rest of my experiments.

Time for a real test.

As usual I take the easy way. I use a ESP8266, to be exact the Wemos D1 variety, and program it in Basic. This is the most easiest way to get fast results.


If you do not want to work in ESP-Basic you can easily adapt this test using an Arduino and putting the flex sensor on an analog pin.
 

Measuring resistance is best done by measuring the difference between the VCC, which is fed into one side of the resistor and the GND. To attach the resistor to the ground a pull-down resistor is used. Normally a pull down resistor of 10K is used however there is a formula that can be used for giving a better value for the pull-down resistor. That formula is the Axell-Benz formula and you can find a complete story on this here: http://lucstechblog.blogspot.nl/2017/12/analog-pull-down-resistor.html
Using this formula you will get a much wider spectrum in values with your measurements.

The setup.



Above is the breadboard setup. The Axell-Benz formula prescribed a pull-up resistor of 1100 ohm. This is connected together with one end of the flex resistor to the analog imput of the ESP-8266. The other side of the flex-sensor is connected to the 3.3 Volt connection of the ESP-8266.

The Basic program


timer 100,[test]

wprint |<h1 style="text-align:center;">Luc Volders</br>Flex sensor</br>|
wprint "<br/>"
textbox value
wprint "<br/><br/>"
button "<h2>Off</h2>", [Off]
wprint "<br/>"
wait

[test]
sensor =  io(ai)


value = sensor
wait

[Off]
end

As you can see it is pretty straightforward.
I start with a timer that every 100 miliseconds calls a routine that reads the analog port and puts the result in the variable called value.
The main part has some fancy HTML code that makes sure everything looks great on the webpage and puts the variable in a textfield which is updated every time the test routine is called and that is every 100 miliseconds.




In stretched form the analog input reads a minimum value of 340


When bend to the max the value of the input is at maximum 900

The readings make perfect sense as they are the reverse of the multimeter readings. The ESP reads the voltage on its analog port and as the sensor is bended more the resistance is lower and therefore more voltage will be read which gives a higher value on the analog port.

All kinds off readings were seen by the in between steps. So the more the sensor is bend the higher the reading will be. This is exact the thing I was looking for.

Beware. The values of the measurements alter not only when bending the sensor but also when putting pressure on it. So make sure you do not touch the part of the sensor where the Velostat is when bending, but just bend it by the ends.

Pressure

As just stated the resistance not only alters by bending the Velostat but also by putting pressure on it.
So next to making a flex sensor I wanted to test it as a pressure sensor.


I started by cutting a piece of Velostat of 7 x 7 cm.


Just as with the flex sensor I put some Aluminum tape on both sides and glued it together with some painters tape.


Again make sure that the pieces aluminum tape on both sides do not touch eachother and touch only the Velostat.

Time for some testing.

I did some readings with my multimeter and measured a maximumj resistance of 1200 ohm in the normal condition and a minimum resistance of 20 ohm when I put an enormous pressure on the pad.

 
The Axell-Benz formula tells me to use a pull-down resistor of 220 Ohm to get the best readings on the ESP's analog port.

And indeed the readings were great.


About 190 in normal condition.


About 800 when under pressure.

So I had an idea.

Could I use this as a scale for measuring weights ???


I did some testing with various weights in a bowl. The results were indeed varying with the weight. However they were not consequent. When I moved the weight a bit on the presure pad the readings were differnt at the same weight. When I put a bowl with 400 gram sugar on the pad it sometimes would give me a reading of 616 and the next time 580. So the readings were not consequent with the same weight.
Therefore this is not usable as a scale.

However.


An empty pack of milk would give me a reading of 100 to 190.
When filled with 100 ML water I would get a reading of about 400.

This means that for pressure testing this works flawlessly.

Applications.

What is it good for.

Well I am not going to tell you that I made a sensor that I put in my fridge to tell me that I was running out of milk. That would be as stupid as the April fools joke that told me that the light of the fridge was actually out when I closed the door (and believe me people thought it was indeed a serious project).
Although I do know that some fridge maunufacturers are indeed experimenting with pressure pads that tell you that you are running out of eggs, milk etc etc etc.

So let's look at some real, practical solutions.
- A pressure pad can tell wether a water tank (be it for irrigation or whatever) is running low.
- A pressure pad put into your shoe can be made into a step counter


- A pressure pad can be positioned under a mat to detect a person entering a room
- A pressure pad can be put in the bottom of a bag/box detecting if it's being lifted
- A flex sensor put on your finger can control the movement of a servo for controlling a robot finger.
- A flex sensor on your finger could control the volume of an audio installatiuon
- A flex sensor on your finger could control an IR remote

Keep in mind that you can not solder the aluminum tape. So this is only usefull for testing purposes, or if your project is not that critical and you can use alligator clips. If you want a more permanent solution use copper tape. I bet it will be even more conductive and you can solder it for a permanent project.

That's it for now.
Have fun

Luc Volders