Smart Button using PIC10F microcontroller

Smart Button

This is a button a little bit smarter. (Microcontrollers and coffee, who doesn’t like)

I i’m using it to fill my Coffeemaker  with water. This way its a little bit more fun and i always get the same amount of water.

Smart Button

Its a simple project, and it’s a good excuse to play with a PIC10F, one really small micro-controller. Code is written in C, a nice way to start with it.

It interfaces with the user blinking one led. so you can chose how much time the valve will open ( giving a good control on the amount of water). On the current firmware settings ( and with my valve) are for 1-2-3-4 cups of coffee ( i have a big cup, 300ml).

Just keep in mind that this button can be used for other uses.

The design (and problems that where solved) are on the next page, but if you just want to build this thing   go to the building instructions page and download the project files.

Arthur Benemann 2011 Brazil

Step 1

In the beginning…


This started as a weekend project, me and my girlfriend where making a coffee after lunch. Then a i had an idea, what about making a timed water valve so i can always make the same tasteful coffee, simple , a little useful, and easy to build.As always a good pile of junk it’s great for this, a big yellow button and a water valve from a washing machine ( both in the pictures below).

Things need to be as simple as possible so a small micro-controller would be perfect. Luckily i had some spare PIC10F206 on my parts box. A 100mA transformer and a 78L05 would do the power supply, and a relay to control the valve ( mains power).

All parts are set up, now the board…. ( next page)

Step 2

Schematic v1

Schematic Smart Button

I  think i would get this one at the first try, i was so simple… ( jump this if you are not interested in failures)

Ok, it was just a question of putting building blocks together.

Power supply – ->  Line – Trafo – Brige – Big Cap (100uF would do the job)- 78L05 – and done

Relay               –>    Resistor ( 1k will saturate the BC548)  – 5v relay – protection diode (1n4004)

PIC                  –>    Internal pull up for button – a simple LED  – connection to the relay block

OK that was easy.I should work nothing wrong until where. ( schematic below).

Draw the board, tone transfer, soldering  ( forwarding so we don’t blow the surprise)

Now just add some codding ( explained on the next pages), and programing with temporary wiring.

Turn it up !!!  And it doest work properly :(…

Next page for the solution…

Step 3

Board v1

It  fail “sometimes”…Man i hate when someones work is left like this. So lets investigate…

There is a picture below of the original prototype v1, it’s full of wiring  and solder  because of the testing…

I tried a lot of things, powering it up from a external source, changing the relay supply to before the 78l05 regulator, putting huge caps on some points of the circuit….

The i worked, i had put a direct wiring for the Microcontroller supply. Currents running to the relay was messing up with the PIC power ( one oscilloscope would be great by now ).

The picture has some highlights on this.

Problem solved, let go to v2.0.

Step 4

So what can be improved:

Filtering caps.
Star Grounding.
Relay power does’t need to be regulated.
MCU position could be more away from mains voltage ( relay).
Don’t use MRCL pin, just to be sure.

Just a question of redesigning the board ans schematic. Final result is below:

This solved the problems.

Step 5


I wrote a program to control the button, but it was not very friendly to the user ( i prefer not to comment it). Here i have to thak Jéssica for her idea for the program.

Button press is used to change between modes of operation,

n° press    |  Dose    |  LED
0 press      –  0 off     –  off
1 press      – 1 cup    –  slow blink
2 presses – 2 cups  –  blink
3 presses – 3 cups  –  fast blink
4 presses – 4 cups  – on
5 presses –> return to off position

There is a timeout in “cups mode”  if there isn’t a press for 2-3s it go to filling mode. And stays there until the filling timeout, that deepens on the mode.

I implemented this with a state machine, and a debouncing routine.

The on time of each mode is defined in the top of “main.c” file, this control how much water goes to the coffeemaker. Experimenting with the valve in place give me this results ( and they don’t seem to change too much because pressure is constant).

You must change this values to agree with your installation.

This is my first low end microcontroller project programed in C, i used to think that C would’t be as easy to code as assembler, and the code would be so big. I was wrong C is great,fast development and relative small code.Code was compiled with hi-tech C compiler lite (free).

For more detail: Smart Button using PIC10F microcontroller

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.