Friday, August 10, 2018


For an index to all of my stories click here

At my work I drink lots of  tea. I start with 2 cups when I arrive, and then during the day I drink at least 8 cups. That is more then 10 cups of tea a day. The problem is that I often put the tea bag in the hot water and forget about it. The result then often is a cup that is too strong or even bitter.

The tea bags tell me the tea has to soak 2 to 3 minutes. Now how am I going to keep track of the time when I am busy at work. I could set a timer on my computer screen but that is too much hassle and not sexy at all. More sexy would be a timer with several leds that faded in or out. But what if the time ran out and I am not at my desk.

So I decided to build a tea timer.

The picture is taken in my hobby room, not at my work. And yes I need to reorganise as I have many projects cluttering up my desk.

My tea timer is a part electronics and part mechanical solution.
A microcontroller is attached to a servo. The servo drops the tea-bag into the cup and gets it out after a set time. This has been done a few times by using an Attiny85 with a servo and a pot-meter to set the time. That is a perfect acceptable solution. However I decided to do things different.

A tea-timer with a website

We are living in the IOT era so let's give the tea-timer a website. The idea is to take a NodeMcu (or Wemos d1 mini) attach a servo to it and do the rest in software. This is a bit more expensive as using an Attiny85 with a potmeter but has the advantage that it has power management on board. So I can feed it direct from an USB power source like a phone charger or power bank. Next to that I can control it from my phone or computer which is cool !!

The hardware

The hardware is straight-forward.

This could be done with an ESP-01 but I used a NodeMCU as it can be powered through USB which gives me an opportunity to use a powerbank as a powersupply when no computer is near. Next to that it supplies 5 volts to power the servo. The servo is attached to d7.

The software

Again I did this project in my favorite rapid devellopment environment: ESPBASIC. Well the software is so easy it speaks for itself.

The slider is used to set the number of minutes the teabag needs to soak. And there are 4 buttons. When the time is set with the slider and Start button is pressed the teabag will slowly be lowered into the tea. I lower it slowly on purpose as you do not want to be splashed by hot water. After the set time the teabag is lifted out of the cup slowly again.

The Up and Down buttons will rise and lower the teabag manually. This function is disabled when the start button is pushed.

The Off button also rises the teabag out of the cup but then ends the program.

timer 500,[set]

wprint |<body style="background-color:SaddleBrown ;">|
wprint |<span style="color: SpringGreen;">|
wprint |<h1 style="text-align:center;">Luc Volders</br>Tea Timer</br>|
wprint "<br/>"
wprint |<span style="color: White;">|

for i=1 to 45
servoval =i
delay 20
next i

slider minutes, 0, 8
wprint "<br>"
wprint "Minutes :  "
minut2 = minutes / 2
textbox minut2
wprint "<br/><br/>"
button "<h2>Start<h2>", [Start]
wprint "<br><br>"
button "<h2>UP<h2>", [Up]
button "<h2>Down<h2>",[Down]
wprint "<br><br>"
button "<h2>Off</h2>", [Off]
wprint "<br/>"

minut2 = minutes / 2

if servoval <> 45 then
for i=0 to 45
servoval =i
delay 20
next i

if servoval <>0 then
for i=45 to 0 step -1
delay 20
next i
servoval = 0

for i=45 to 0 step -1
delay 20
next i
delay minut2 * 60 * 1000
for i=1 to 45
servoval =i
delay 20
next i
servoval = 45

if servoval <> 45 then
for i=0 to 45
servoval =i
delay 20
next i

Some remarks concerning the program.

- The chosen time is tracked by the servoval variable.
- The SET function stes the minutes by 30 seconds
- The delay in the for loop determines how fast the bag will rise or be lowered
- The servo value 0 is down and 45 is up.
- Adjust the number 45 to your own needs, just keep the Pythagorean theorem in mind
- The delay in the Start function: delay minut2 * 60 * 1000 soaks the teabag for the choosen time.

To use this program start with installing ESP-Basic on the Nodemcu board. Open a new file and paste the above code in. Run the code and you are set to go. If you want to know how to do this look at my ESP-Basic introduction page which can be found here:

The frame

The frame is made by experimenting. I made mine 24 cm high and 18 cm wide. First set the servo in the down position ( 0 degrees) and attach the arm so it rests horizontal. Attach a teabag and hold the servo at such a height that the teabag is on the bottom of a cup

Next position the arm so it is sticking as wide as possible out of the frame. In my case I positioned the servo at a hight of 18 cm and 11 cm from the left. This last part could be done better like 13 or 14 cm to the left. That way the cup is positioned a bit farther from the frame which is better when the arm is lifted.

I designed and 3D printed an arm and some feet for the frame. The feet have a gap which is 2mm wide which fits the carton I used for the frame. If you use a thinner carton just make the frame a bit longer and fold the carton at the bottom and press it in the feet. I did not print the frame itself. The feet took me about 2 hour to print so I was not patient enough to print the frame. If you want the STL files just send me an e-mail requesting them.

Thats it for this episode.
Have fun

Luc Volders

Friday, August 3, 2018

Motion detection with RCWL-0516 Radar

The most well-known motion detecting module is the PIR of which I described the basics in this story and with which I made a simple alarm in this story

However lately there is a lot of  fuss about a new module by the name RCWL-0516. So let's see what the difference with a PIR is.

A PIR makes a kind of infra red map of its location. After a while it makes a new infra red map and compares the two. When there is a change in the map that means there is motion and the PIR the makes its output high.
As this description suggests the PIR depends on a change of location of a heat source.

The RCWL-0516 is a magnetron / radar module. The module sends out pulses and measures the return time. If a change in the return time is detected that indicates that something in the path of the pulses has changed position. So the RCWL-0516 is not heat dependend but detects any movement. In real life that almost boils down to the same as most movements will mostly be made by people or animals which are also heat sources.

The connections

Do not let the size of this picture deceive you. The module is only 1.7 x 4 cm !!!

As you can see on the right side the module has 5 connections.

- 3.3 Volt

I found no official papers on this module on the internet. However there are some hobbyists who have done some research and their findings is what I am using to work with.

As long as CDS is high the module functions. So it is the chip-select line. In the beginning I used the module with CDS unattached and it worked. Best results are gained when CDS is attached to +3.3 Volts.  Test what works best for you.

According to the literature I found on the internet the 3.3 Volts pin is an OUTPUT pin. So you should not use it to power the module. Power should be connected to VIN. Again according to the documentation found on the web anything from 4 to 28 Volt will work. I just attached it to the VIN from my NodeMCU unit and that works flawlessly.

First test

I did not find a Fritzing part for the RCWL-0516. I presume that that is because the module is so new.  I tried to make a simple alternative for it.

This first setup is very simple. In fact it almost looks like the first PIR setup.
Just attach a 5 volt source (I used an USB power bank) to GND and VIN and connect OUT to a led with a delimiting 220 Ohm resistor.

When I powered this setup for the first time I thought the module was not working or that I connected it wrongly. The LED was ON all the time. This will happen to you also if you use this setup. But do not worry. The module is not faulty and you did not do anything wrong. The module is just so sensitive that it notices any movement direct and therefore the LED will always be on.

So I sat totally still and the led went out.
When I as much as lifted a finger or nodded my head the LED went on again. This module is very sensitive.

The LED will stay on for about 2 seconds and then goes OFF if no movement is detected.

We have a long corridor in our house and I put this setup on one end and I stood on the other side and the module easily detected my movements. The distance was 6 meter !!!!

Attach it to an ESP8266

The next step was to connect the RCWL-0516 to an ESP8266. I used a NodeMCU for this as it supllies 5 Volts and 3.3 Volts and is easily powered over USB.

As you can see I powered it with 5 Volts from the NodeMCU and attached CDS to 3.3 Volts on the NodeMCU. I attached the led to D5 (through a 220 ohm delimiting resistor) and the RCWL-0516 OUT pin to D6 on the NodeMCU.


For a quick result I wrote a program in ESP-Basic

timer 1000, [test]

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

sensor = io(pi,d6)
if sensor = 0 then
value = sensor


First pin D5 is set as output (this is where the led is connected) and D6 is defined as input (where the RCWL-0516 output) is connected.
Next step is to set variable A to 0 so we can make an endless loop.
Then the program tests wether D6 is LOW. If that is the case the led stays off and the program jumps to subroutine green that sets the led on the web-page also off.
When D6 is HIGH (movement detected) the program sets the led on and jumps to subroutine red which sets the led on the webpage in the color red.

I put this setup in my room and aimed it at the door. Next I went outside my room and closed the door. I opened my webbrowser on my phone and look at what was happening.
The RCWL-0516 detected movement at a distance of 4 meter through a closed door !!!

This means that we can put this module INSIDE an enclosure and makes it more hide-able in case of an alarm system.


- The RCWL-0516 is a very cheap and yet sensitive motion sensor.
- It can be powered with anything from 3.3 to 28 volts
- The RCWL-0516 measures movement easily on a distance of 6 meter
- The RCWL-0516 measures movement from a distance of 4 meter through a closed door !!!
- The module just uses 1 data pin so can be used with an ESP-01 or even an Attiny85
- As the module can be powered with 3.3 or 5 volts and has a 3.3 signal pin it can be used with a Raspberry Pi

So you can build an enclosure for your project and put the RCWL-0516 inside and it will still work. Testing is recommended though.

Till next time.
Have fun

Luc Volders

Friday, July 27, 2018

ESP power reduction with deepsleep

We all now that the ESP8266 draws a lot of power. So what when you want to run it on a battery. That gives you a problem. Luckily we do have power-banks nowadays. They have a large capacity and will run the ESP8266 for a longer time. But even that can sometimes not be enough.

Suppose you have a project in which the ESP8266 is outside your home. Or it is in a place where no power outlet is available. Or you want to hide it. Etc. Etc. Etc. In these cases a battery or a power bank will not last long enough. What to do.


The ESP8266 has a function that is called 'sleep' which is supported in most languages. If the ESP8266 gets into Deepsleep most functions are put on hold until the ESP wakes again.

There are several versions of sleep called Modem-sleep, Light-sleep and Deep-sleep.

As you can see from the table Deep-sleep is the most efficient and will reduce power use to a minimum. So that is what we want to use.

There are two methods of waking from Deep-sleep. Which one do you use ???

The automatic wake up version.

In this version GPIO16 (D0) is connected to the RST (Reset) pin of the ESP8266. The Reset pin is normally HIGH (even when not connected). When the RST pin is connected to GND it restarts the microcontroller.

Fortunately the build-in Deep-sleep function sends a LOW signal to GPIO16 (D0) when the ESP8266 wakes up from it's Deepsleep. This is done automatically.

It works like this:
We tell the ESP8266 to go into Deep-sleep. The only thing that is running inside is the RTC (Real Time Clock) and when the set time has expired the Clock sends a LOW signal to GPIO16 (D0).
We connect a wire between GPIO16 (D0) and RST. This makes sure that when the ESP8266 wakes GPIO16 (D0) sets RST to LOW and the ESP resets and wakes.

This sounds ok but there is a setback. The ESP is a 32 bit processor and therefore the largest unsigned integer value it can handle is 0xffffffff being 4294967295, or 71 minutes. So when this method is used the ESP will wake about every 71 minutes. This is still less than 24 times a day so you will get an enormous power saving.

The manual wake up version.

There is also an infinite Deep-sleep method. If we use this version the ESP will stay in Deep-sleep until we manually give it a push. That is easily done. You just manually send a LOW signal to the RST pin.
You can do that with pressing a button or closing a reed-switch controlled by a magnet or any other mechanical switch that connects RST to GND.

When to use manual or automatic.

This depends on the situation and the project at hand.

Suppose you want the ESP to send the temperature or any other sensor reading every half an hour to Dweet, Thingspeak or your Domotics system you can use the automatic wakeup version.

Now if you want the ESP to send a signal when a button is pressed, or the fridge door is opened, or a window is opened you use the manual version. Just connect the switch or reed contact to GND and RST and you are done.

The different ESP versions.


Unfortunately the ESP-01 has no GPIO16 pin on the connector. So we can not use the automatic wake up function. You can only use the manual wake up function


The NodeMCU has all the needed pins available. GPIO16 (D0) is available on the top left side. It is even called WAKE in the pin layout. RST can be found on the 3d pin from below on the left side.

Please be aware that this will not work on NodeMCU version 0.95 and lower. It only works on V1.0 and up. Well at least my version V0.95 did not work your mileage may vary but be carefull and test.

Wemos D1 mini

The Wemos D1 has GPIO16 (D0) as the 3d pin from the top on the left side. And RST is even the first pin. Tested and verified. Automatic wake up works on the Wemos D1.

Software commands.

Deepsleep is supported is most languages.

In Arduino (C++) you can use:

ESP.deepSleep(20e6);   // 20e6 is 20 microseconds

ESP.deepSleep(0); // infinite for manual wake-up

In ESP-Basic you can use:

Sleep 60   ‘60 seconds

Sleep 0    'sleep infinite for manual wake-up

In LUA (NodeMCU) you can use:


where 60000000 = 60 seconds = 60 x 1000 x 1000

Arduino example

I used a Wemos D1 mini for this and programmed it with the Arduino IDE. This is the infinite Deep-Sleep version which you have to wake-up manually. I did that with the loose-end wire that is connected to RST. Just plug it into GND to wake the ESP.

void setup()
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);
  delay (1000);
  digitalWrite(5, LOW);

void loop()
digitalWrite(0, LOW);

The program sets the LED connected to GPIO5 (D1) ON, waits for a second and then sets the LED OFF and goes into Deep-Sleep.
The LED goes ON again when you connect RST to GND.

Basic example.

This is the schematic for automatic wake up. As you can see D0 is connected to RST.

wprint "<h1>Deepsleep Test</h11>"
wprint "<br><br>"
button "testsleep", [sleeptest]

sleep (60)

The program is straightforward. Save it under the name 'default.bas' It sets a button on the screen and sets the LED ON. When the button is pressed the program jumps to the routine [sleeptest]. In [sleeptest] the LED is put OFF and the ESP is set to sleep for 60 seconds.

Before you run the program go to the SETTINGS page and make sure that 'run default.bas at startup' is checked. Otherwise the program will wake the ESP8266 but it will not restart the program automatically.

Just be aware that the ESP8266 will need about 30 seconds to start your Basic program after it is woken. The Arduino version is bloody fast.

This schematic is the version you will need for manual wake-up. When you want to use manual wake-up just alter the sleep command in:


Real World usage

Let's see how it functions in real life.

The above reading is the current consumed when the ESP is working that is 0.07 Amps being 70 Ma.

And this is the reading when the ESP is in Deep-sleep.

Official figures from Espressif say that the actual current drawn in Deep-sleep is 300ua that is 0.3ma !!!

In the past I have published several projects on this weblog that could benefit from this technique.  for example the rain-sensor: and the Thermometer:

I bet you can find projects that can benefit from this technique. I have one in my mind already.

Till next time
Have fun

Luc Volders

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]

print "it moved"
delay 500

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:
I just wanted to make it a bit more fancy.


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:

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

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/>"

value = io(ai)
if (value < 600) and (io(laststat,d7) = 1) then
   keypr = "ready for use"
   print wget("")

if io(laststat,d1) = 0 then 
   keypr = "running"


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:

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.


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]


for i = 0 to 3
  io(po, i, 1)  
  delay 1000
  io(po, i, 0)  
next i

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]


io(po, 0, 1)

io(po, 1, 1)

io(po, 2, 1)

io(po, 3, 1)
for i = 0 to 3
  io(po, i, 0)  
next i

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 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:
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/>"

sensor =  io(ai)

value = sensor


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.


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.


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.


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