Coil Winding machine counter with Atmega8 and Reed relay

Ovidiu asked me to build a digital counter for his new project, a coil winding machine. Here is what I came up with:

Variant 1 : Atmega8 + Nokia 5110 LCD + 3V power supply

I am using an Atmega8-8PU (configured for 8MHz with external crystal), a Nokia 5110 lcd, and a transistor to handle the pulses from a reed relay. A 3.3V regulator provides the voltage for the entire circuit.
reed digital counter atmega2

Everything has been mounted on a test board, including the headers for: ISP programmer (USBAsp), the 5110 Nokia LCD, the power supply (5V in, fed to the 3.3V regulator), the Reed relay connector, the reset button connector and another 2 pins connector, used to read the polarity of coil winding machine’s motor, so we know we either increment or decrement the counter.
reed_counter_atmega_1 reed_counter_atmega_2 reed_counter_atmega_3 reed_counter_atmega_4
There are a few connectors:
J1: is for the power supply. The circuit takes 5V, that get into the L7833 for 3.3V output used by the atmega8 uC and the LCD.
J2: is the LCD connector, going to the Nokia 5110LCD.
J3: goes to the reed relay. This is the place we generate pulses for the microcontroller to count.
J4: is the polarity connector. It must be connected in parallel on the coil winding machine’s motor. It was designed for a 12V motor (but this can be changed by adjusting the voltage dividers formed by R3-R4 and R5-R6, so they take in the motor voltage, and output not more than 5V). If the motor is connected in normal polarity, we will read PD0 high, if the motor is in inverse polarity, we’ll have PD1 high. This info is used in the code to either increment or decrement the counter.
J5: is just a simple momentary switch. When pressed, will reset the counter to zero.
ISP connector: is a 10 pin connector used with the USBAsp AVR programmer.

Circuit diagram:
digital counter reed switch circuit diagram

Fuse bits:
External 8MHz crystal. The settings are:

avrdude -p atmega8 -c usbasp -U lfuse:w:0xff:m 	-U hfuse:w:0xc9:m 	

Source code:
You can download and use the source code, under the Apache license, here.

Variant 2 : Atmega8 + 2×16 HD44780 Character LCD + 5V power supply

Some of my readers asked for a custom variant, that uses a 2×16 HD44780 LCD (or a 1×16 smaller variant). These displays require a 5V voltage supply, so here is variant 2 of the digital counter, modified to support these requirements.

2×16 LCD Circuit Diagram:
digital counter reed switch circuit diagram with 2x16LCD HD44780_1_16_connector

Hex file, SCH and source code:
Can be downloaded here: atmega reed digital counter 2x16LCD

This article has 26 Comments

  1. I am trying to understand something, you used a atmega8 that only has 28 pins and in your schematic it shows 32 pins. Ok I am not getting this, pin numbering you got going on here can you please email me with the needed info and how to change it to english.
    Thank you
    Email me at with coil counter in subject line thank you

  2. That is because I included the SMD version of the Atmega8 in the SCH. So just use the 28 pins DIP Version instead.

  3. OK, Thank you. Now can it be changed to English? It’s a great design by the way been working on something like this for a few months now, and seen this, it’s a great example thank you for sharing this.

  4. The source code has been provided at the bottom of the article, you simply need to change the texts and recompile the code. But if you need help, I can do it for you and simply post the .hex file here. What do you think?

  5. i need the winding method with its assembly cod and interfacing ,please sent me through email

  6. Radu,
    Sorry that I haven’t gotten back with you on your answer been very busy . If you could please help me with this that would be great. I have built my coil winding machine using stepper motors, I have done what you said to do by changing the text and recompiling and something is just not right.
    Thank you

  7. Radu,

    How could one go about purchasing one of these units (if available)? Alternatively if not available for sale, is there a complete parts list available so I could build it? My experience in electronics is very limited.


    Please respond to:

  8. Hi there,
    Very nice project, one thing (two actually), what schematic/pcb package is the 2x16LCD- version pcb designed and second could you please post the .hex- code for the controller? (…or if not too much trouble email it to me.)
    Thank you kindly.

  9. Radule am construit si eu numaratorul cu atmega 8 si lcd-ul nokia inca nu l-am folosit ca mai trebuie plantat sursa de 3.3v si nu am avut timp sa o comand
    Am incercat sa modific intrare impuls de numarare , in loc de reed sa adaptez optic si nu m-ia iesit nu stiu sa lucrez cu microcontrolere , cred ca am depasit valorile
    Multam pentru munca ta ….o zi buna …Dan

  10. Apropo revin____sa stii ca montajul tau a fost construit de multi electronisti amatori dar problema este cu releul reed la viteze mai mari este cam “”mototol”___beleaua este ca noi cei mai batrini nu ne pricepem la programari , cu chiu si vai debia am invatat sa folosesc programatorul IC2

  11. hello is freat project,
    have any body try to make this in arduino?
    i will like to find in arduino nano this can anybody makeit?

  12. Dintr-o calculatrice de la dolarama, se poate face numararea spirelor cu afisare.
    Dar este mai putin plictisitor with Atmega8 and Reed relay.
    Have a nice day!

  13. M-am englezit , m-am frantzuzit… . Imi pare rau ca am fost superficial. Traiesc in Montreal si aici sunt magazine numite “Dollarama”, iar majoritatea marfurilor costa 1$ si ceva, sau mai mult. Cand am spus “calculatrice”, ma refeream la o socotitoare electronica care costa 1$ si care se poate folosi (cu o minima modificare) pentru afisarea numarului de spire in timpul bobinarii. Nu vreau sa intru in detalii, pentru ca imi pare penibil sa expun un asemenea proiect in prezenta unui proiect cu greutate, cum este acesta :
    “Coil Winding machine counter with Atmega8 and Reed relay”.
    Cred ca mai degraba ar fi mers la
    Am incercat sa o dreg , dar am senzatia ca nu am prea reusit.
    Oricum ar fi , tin sa precizez ca am o deosebita stima si consideratie pentru munca lui Radu Motisan.
    Iti doresc succes !

  14. Salut Marin, am inteles acum , ai dreptate, se pot folosi acele socotitori si pur si simplu folosesti semnalul ca sa incrementezi +1 suma de pe ecran.
    Daca ajungi sa faci o pagina pe instructables cu asta, pot sa adaug linkul la acest articol, pentru a oferi mai multe optiuni celor interesati.

  15. Hi Ed, yes it is possible. There are certain changes required. Unfortunately I am caught with other projects and don’t have the time for such modifications. You can either use the LCD I have indicated (it’s no big deal, it is cheap and available), or you can make the changes yourself.

  16. Hi Radhu,
    I’m very much impressed with your digital counter for coil winding machine circuit using Nokia 5110 lcd module. But I’m little bit confused to where I have to connect the other end of the 332 – 10 USBAisp connector. I’ll be much grateful to you if I receive the details in my mail id

  17. Hi Radhu,
    I was just wondering what are the advantages and disadvantages of this digital counter?

  18. Domnule Motisan,
    As vrea sa construiesc “Coil Winding machine counter with Atmega8”, varianta cu display de Nokia 5110.
    Acest tahometru este bun, multzumim pentru fisierul .hex, insa eu as dori sa-l adaptez la o masina de bobinat manuala.
    Dezavantajul ar fi ca in acest caz sensul contorizarii nu mai poate fi stabilit de polaritatea motorului electric. Mai mult, chiar daca as simula sensul cu un comutator se pune o alta problema:
    Atunci cand magnetul este in dreptul contactului magnetic si penduleaza mai mult de 10 gr. inainte sau inapoi, softul contorizeaza ca si cand masina ar efectua o rotatie completa.
    Lucrul acesta este des intalnit la masinile de bobinat manuale.
    Eu doresc sa adaptez un ansamblu de 2 senzori optici opturati de o “cruce de malta”, secventa de numarare fiind: 00, 10, 11,01 s.a.m.d, repetata de 4 ori pe parcursul unei rotatii complete.
    Problema este ca nu prea stapanesc programarea acestui tip de microcontroller ca sa rezolv programul de la zero. Ati avea amabilitatea sa-mi trimiteti sursa programului? Astfel as modifica doar rutina de numarare. Va asigur ca nu voi folosi proiectul pentru beneficii materiale si va voi returna sursa programului modificat cu multzumirile de rigoare.
    Cu stima!

  19. Buna seara Dle. Sandu. Codul sursa e deja oferit celor interesati, sub licenta Apache, mai sus in articol. M-as bucura sa reusit sa faceti modificarile care vi le-ati propus. In masura in care va pot ajuta, nu ezitati sa-mi scrieti daca aveti neclaritati.

Leave a Reply