Introduction: NODEMCU LUA With CD4017 Decade Counter

The CD4017 is a decade counter / divider. This means that when it receives a pulse it counts it and sends an output to the appropriate pin. It is quite an easy IC to use and you can either build the circuit on a bread board or buy one from Ebay for about 99p from China. You do of course have to solder it all together.

Pin 3 is the output of the 555 timer and Pin 14 is the input of the CD4017.

Step 1: Circuits

If you were building the circuit on a breadboard you could leave out the 555 timer part and drive it with the ESP8266. You might be thinking, why buy the kit to drive it with an ESP8266. One good reason is that if you sourced all the components individually they would cost far more than 99p, another is that you can tinker with it.

If you drive the CD4017 circuit with the ESP8266 it will work on 3.3 volts. Remove the 555 timer from the DIL Socket and take a jumper wire from D1 (or whichever pin you are using) and poke it into pin 3 of the 555 DIL Socket.

Back to the ESP8266, there are a few different ways to produce a pulse on a pin

If you read the NodeMCU documentation it will give more examples of gpio.serout.

Either of these 2 lines of code will produce a pulse on pin D1 GPIO5.

This line produces a 5 millisecond pulse every second 100 times.

gpio.serout(1,gpio.HIGH,{5000,995000},100, 1)

This line produces a 5 millisecond pulse every half second 100 times, then prints Done.

gpio.serout(1,gpio.LOW,{5000,50000},100,function() print("Done") end)

Step 2: Code

You could use the code below to produce a pulse on pin D1 GPIO5. Changing the value (100) will give different pulse rates.

pulse = 0
pin = 1
gpio.mode(pin,gpio.OUTPUT)
tmr.alarm(1,100,1,function()
    if pulse == 0 then
        pulse = 1
        gpio.write(pin,gpio.HIGH)
    else
        pulse = 0
        gpio.write(pin,gpio.LOW)
    end
end)

Step 3: Producing a Pulse

Another way of producing a pulse is with a multi vibrator circuit. Again you can get these on Ebay for 99p or you can build one on a bread board. This is a very common circuit and there are many examples of it all over the Internet. Take an output form between Q1and D1 on the circuit diagram.

Yet another way to produce a pulse is to take a jumper wire from pin 3 of the 555 timer socket and momentarily touch the 3.3 volt supply.

Step 4: Conclusion

I have tried to show how to produce a pulse to drive another circuit by using different methods. Many electronic circuits are driven by pulses.

I have used the CD4017 as an example. The same could be applied to the CD4022 which has 8 outputs instead of 10.

For more information download the datasheet for the CD4017 which is widely available.

I am not an ESP8266 or electronics expert and the above are some of my findings over the years.

Comments

About This Instructable

416views

16favorites

License:

Bio: I like tinkering with electronics, PCs, ESP8266s and Arduinos. Would like to share what I have done as it may help others getting started or ... More »
More by JohnL142:NODEMCU LUA ESP8266 Get Weather for Your City (Updated)NODEMCU LUA With CD4017 Decade CounterNODEMCU LUA Driving a M5450B7 LED Display Driver IC
Add instructable to: