Most electronic devices use a toggle switch or push button
to turn ON and OFF. But what if you could do this with just one button?
That’s exactly what this circuit achieves using the CD4017 Decade Counter IC.
It’s simple, efficient, and a great project for hobbyists and makers.
How It Works
The CD4017 is a decade counter/divider IC with 10
decoded outputs (Q0–Q9). Each time it receives a clock pulse, it advances to
the next output pin.
When
you press the button, the IC receives a clock pulse.
The
first press activates Q0 → ON state.
The
second press activates Q1 → OFF state.
The
cycle continues, but by wiring only two outputs (Q0 and Q1), we can create
a neat ON/OFF toggle.
Circuit Components
CD4017
Decade Counter IC
Push
Button (momentary switch)
Resistors
(for pull-down/pull-up configuration, Current limiting resistor for Output
LED)
Capacitor
(for debounce filtering)
LED
(to demonstrate ON/OFF switching)
Power
Supply (5Vdc)
One Button On/Off Circuit
Circuit Explanation
Clock
Input (Pin 14): A switch (S1) is connected between U1 Pin 14 and VCC.
Each press sends a pulse.
One
resistor R1, 470 Ohm pull down resistor, is connected between Pin-14 and
GND.
Reset
(Pin 15): Ensures the IC starts from Q0 when powered ON. Pin-15 is
connected to Pin-4.So that on the
next press, it will reset the Output, and LED, LD1, will be OFF.
Outputs
(Q0 & Q1):
Q0
→ Connected to the load, LED LD1, through R2 Resistor.
Q1
→ Connected to reset or directly used to turn OFF the load.
Debouncing:
A small capacitor C1, 100nF, across the button ensures clean pulses
without multiple triggers.
Applications
DIY
gadgets with a single ON/OFF button
Lamp
or fan control circuits
Embedded
projects where minimal switches are desired
Learning
tool for digital electronics and counters
Advantages
Reduces
switch count (only one button needed)
Easy
to build and understand
Low-cost
components
Can
be extended for more functions using other outputs of CD4017
Conclusion
This one-button ON/OFF circuit using CD4017 is a
perfect example of how digital ICs can simplify everyday electronics. With just
a push button and a counter IC, you can toggle devices ON and OFF elegantly.
It’s a great beginner-friendly project that also teaches the fundamentals of
counters and sequential logic.
If you’ve ever wanted to display numbers in your Arduino
projects — whether it’s a clock, a counter, or sensor readings — the TM1637
4-digit 7-segment LED display is one of the easiest and most affordable
solutions. It uses only two data pins, thanks to the onboard TM1637 driver IC,
which simplifies wiring and coding compared to traditional 7-segment displays.
In this blog, we’ll walk through:
Understanding
the TM1637 module
Pinout
and wiring with Arduino Uno
Installing
the required library
Example
codes (basic display, scrolling, countdown, sensor integration)
Practical
applications and project ideas
Troubleshooting
and tips
Understanding the TM1637 Module
The TM1637 module is widely available in electronics shops
and online marketplaces. Here’s what makes it special:
4-digit
7-segment LED display: Each digit can show numbers 0–9 and some
letters.
Colon
separator: Useful for clocks and timers.
TM1637
driver IC: Handles multiplexing and communication, reducing pin usage.
Two-wire
interface: Only requires CLK and DIO pins, plus VCC and GND.
Pinout
VCC
→ 5V
GND
→ Ground
DIO
→ Data I/O
CLK
→ Clock
Wiring TM1637 with Arduino Uno
Here’s the wiring diagram:
TM1637 Pin
Arduino Uno Pin
VCC
5V
GND
GND
DIO
Digital Pin 2
CLK
Digital Pin 3
You can change the DIO and CLK pins in your code if needed.
Installing the TM1637 Library
Open
Arduino IDE.
Go
to Sketch → Include Library → Manage Libraries.
Search
for TM1637Display.
Install
the library by Avishay Orpaz (commonly used).
Example Codes
1. Basic Number Display
#include <TM1637Display.h>
#define CLK 3
#define DIO 2
TM1637Display
display(CLK, DIO);
void setup() {
display.setBrightness(0x0f); // Max brightness
}
void loop() {
display.showNumberDec(1234); // Display 1234
delay(2000);
}
2. Countdown Timer
#include <TM1637Display.h>
#define CLK 3
#define DIO 2
TM1637Display
display(CLK, DIO);
void setup() {
display.setBrightness(0x0f);
}
void loop() {
for (int i = 30; i
>= 0; i--) {
display.showNumberDec(i, true); // Show with leading zeros
If you connect a temperature sensor like DHT11, you
can display readings:
#include <TM1637Display.h>
#include <DHT.h>
#define CLK 3
#define DIO 2
#define DHTPIN 4
#define DHTTYPE DHT11
TM1637Display display(CLK, DIO);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
display.setBrightness(0x0f);
dht.begin();
}
void loop() {
int temp =
dht.readTemperature();
display.showNumberDec(temp);
delay(2000);
}
Applications
Digital
Clock: Combine with RTC module (DS3231).
Stopwatch/Timer:
Great for labs, cooking, or sports.
Scoreboard:
Display scores in games.
Sensor
Readouts: Show temperature, distance, or voltage.
Counter
Projects: People counter, product counter, etc.
Troubleshooting
No
display? Check wiring and ensure VCC is 5V.
Dim
display? Adjust brightness with setBrightness().
Wrong
numbers? Verify DIO and CLK pin assignments in code.
Library
errors? Ensure you installed the correct TM1637Display library.
Conclusion
The TM1637 4-digit 7-segment LED display is a
powerful yet simple module for Arduino projects. With just two pins, you can
build clocks, timers, counters, and sensor displays. Its versatility makes it
perfect for beginners and advanced makers alike.
A Seven Segment Display (SSD) is one of the simplest
and most widely used electronic display devices. It is primarily used to
represent decimal numbers (0–9) and a limited set of characters. From digital
clocks and calculators to microwave ovens and measuring instruments, SSDs remain
a cost-effective and reliable solution for numeric display needs.
Structure of a Seven Segment Display
An SSD consists of seven LEDs (segments) arranged in
the shape of the number "8". Each segment is labelled from a to g,
and by selectively powering these segments, different numbers and characters
can be displayed.
Segments: a, b, c, d, e, f, g
Optional
Dot (DP): Used for decimal points in numerical displays
Total
Pins: Usually 10 pins (7 for segments, 1 for DP, and 2 for common
connections)
Types of Seven Segment Displays
There are two main types of SSDs based on how the LEDs are
connected:
Type
Description
Example
Common Cathode
(CC)
All cathodes of
LEDs are tied together to ground. Segments glow when a HIGH signal is
applied.
Used in
microcontroller circuits
Common Anode
(CA)
All anodes are tied
together to Vcc. Segments glow when a LOW signal is applied.
Often used in
multiplexed displays
Working Principle
The working of an SSD is based on forward biasing LEDs:
Digit
Formation:
To
display "0", segments a, b, c, d, e, f are ON, while g is OFF.
To
display "1", only segments b and c are ON.
To
display "8", all segments are ON.
Control
Signals:
Each
segment is controlled by a digital signal (from a microcontroller,
decoder, or driver IC).
By
combining signals, different digits are formed.
Multiplexing:
In
multi-digit displays, segments are shared across digits.
Microcontrollers
rapidly switch between digits to give the illusion of continuous display.
Applications
Seven Segment Displays are widely used in:
Digital
clocks and watches
Calculators
Microwave
ovens and washing machines
Measuring
instruments (voltmeters, ammeters)
Scoreboards
and counters
Advantages
Simple
design and easy interfacing
Low
cost compared to LCDs or dot-matrix displays
Readable
even in bright light (LED-based SSDs)
Limitations
Limited
to numbers and a few characters
Not
suitable for complex text or graphics
Consumes
more power compared to LCDs
Common Cathode vs Common Anode Seven Segment Displays
1. Common Cathode (CC) Display
Structure:
All the cathodes (negative terminals) of the seven LEDs are internally
connected to a single pin.
Operation:
The
common cathode pin is connected to ground (0V).
To
light up a segment, you apply a HIGH (logic 1) signal to its
corresponding pin.
Example:
To
display digit "1", apply HIGH to segment pins b and c
while keeping others LOW.
Usage:
Often
used with microcontrollers because they can easily source current to the
segments.
2. Common Anode (CA) Display
Structure:
All the anodes (positive terminals) of the seven LEDs are internally
connected to a single pin.
Operation:
The
common anode pin is connected to Vcc (+5V).
To
light up a segment, you apply a LOW (logic 0) signal to its
corresponding pin.
Example:
To
display digit "1", apply LOW to segment pins b and c
while keeping others HIGH.
Usage:
Preferred
in multiplexed displays, since microcontrollers can easily sink current.
Comparison Table
Feature
Common Cathode
(CC)
Common Anode
(CA)
Common Pin
Connection
Ground (0V)
Vcc (+5V)
Segment Activation
Apply HIGH (1)
Apply LOW (0)
Current Flow
From segment pin →
cathode
From anode →
segment pin
Ease of Use
Easier with
sourcing drivers
Easier with sinking
drivers
Typical Application
Simple
microcontroller circuits
Multiplexed
multi-digit displays
Practical Note
Microcontrollers:
Some microcontrollers are better at sinking current than sourcing it. In
such cases, Common Anode displays are more efficient.
Driver
ICs: ICs like 7447 (BCD to 7-segment decoder) are designed
specifically for Common Anode displays, while 7448 works
with Common Cathode.
Conclusion
The Seven Segment Display remains a cornerstone of
electronic display technology. Despite the rise of LCDs and OLEDs, SSDs are
still preferred in many applications due to their simplicity, durability, and
cost-effectiveness. For beginners in electronics, understanding SSDs is an
essential step toward mastering digital display systems.
Both Common Cathode and Common Anode SSDs
serve the same purpose—displaying digits and characters—but the choice depends
on the circuit design and driver compatibility. Understanding the difference is
crucial when interfacing SSDs with microcontrollers, decoders, or driver ICs.
Definition:
An LDR, also called a photoresistor, is a passive electronic component
whose resistance decreases as the intensity of incident light increases.
Core
Principle: It works on photoconductivity—the property of
certain materials to conduct electricity better when exposed to light.
Working Principle of LDR
Dark
Condition: In absence of light, the resistance of an LDR is very high
(in megaohms).
Bright
Condition: When exposed to light, photons excite electrons in the
semiconductor material, reducing resistance drastically (to a few hundred
ohms).
Equation:
Resistance R is inversely proportional to light intensityI.
R∝1/I
Construction of LDR
Material:
Made from cadmium sulfide (CdS) or cadmium selenide (CdSe).
Design:
Zig-zag track of semiconductor material deposited on a ceramic base, with
two leads for connection.
Encapsulation:
Transparent cover allows light to fall directly on the surface.
Types of LDR
Intrinsic
LDRs
Made
from pure semiconductors.
Less
sensitive, used in basic applications.
Extrinsic
LDRs
Doped
semiconductors for higher sensitivity.
Suitable
for precise light measurement.
Characteristics of LDR
Response
Time: Slow compared to photodiodes or phototransistors.
Spectral
Response: Sensitive to visible light (400–700 nm).
Cost:
Very inexpensive, making them popular in hobby projects.
Resistance Values of LDR
An LDR’s resistance varies
drastically depending on the amount of light falling on it. Here’s a typical
range:
Condition
Light Intensity
Approx. Resistance
Complete Darkness
0 lux
1 MΩ – 10 MΩ (very high)
Dim Light
10–100 lux (like twilight or a
dim room)
100 kΩ – 500 kΩ
Normal Indoor Light
300–500 lux
10 kΩ – 50 kΩ
Bright Daylight
10,000 lux or more
200 Ω – 1 kΩ (very low)
In
No Light (Darkness): The LDR behaves almost like an insulator, with
resistance in the megaohm range.
In
Bright Light: Resistance drops sharply, sometimes to just a few
hundred ohms, allowing current to flow easily.
Applications of LDR
1. Automatic Street Lighting
LDRs
detect ambient light.
At
dusk, resistance drops, triggering lights ON.
At
dawn, resistance rises, turning lights OFF.
Example: Smart city streetlamps
in India use LDR-based circuits to save energy.
2. Solar Garden Lamps
LDRs
ensure lamps glow only at night.
Integrated
with rechargeable batteries and solar panels.
3. Camera Exposure Control
LDRs
measure light intensity to adjust shutter speed and aperture.
Ensures
optimal photo brightness.
4. Burglar Alarms
LDRs
detect interruption of light beams.
If
someone crosses the beam, resistance changes, triggering alarm.
5. Industrial Automation
Used
in conveyor belts to detect product presence.
LDR
sensors identify light reflection from objects.
Practical Examples
Example 1: Automatic Night Lamp
Circuit:
LDR + transistor + relay + bulb.
Working:
Daytime:
High resistance → transistor OFF → bulb OFF.
Nighttime:
Low resistance → transistor ON → bulb ON.
Benefit:
Saves electricity, widely used in homes.
Example 2: Line Follower Robot
Circuit:
LDRs placed at bottom of robot.
Working:
White
surface reflects more light → low resistance.
Circuit:
Two LDRs placed on either side of a panel.
Working:
If
one LDR receives more light, motor adjusts panel until both LDRs sense
equal light.
Benefit:
Maximizes solar energy capture.
Advantages of LDR
Low
cost and easy availability.
Simple
design and easy to integrate.
Wide
range of applications in automation and sensing.
Limitations of LDR
Slow
response compared to photodiodes.
Temperature
dependent—performance varies with heat.
Not
suitable for precise scientific measurements.
DIY Project Idea: Smart Curtain System
Concept:
Curtains open automatically when sunlight intensity crosses a threshold.
Components:
LDR, Arduino, servo motor.
Working:
Arduino reads LDR values and controls servo to open/close curtains.
Benefit:
Energy-efficient and convenient.
Conclusion
LDRs are versatile, cost-effective, and beginner-friendly
sensors that play a crucial role in light detection and automation. From streetlights
to robots, their applications span across industries and daily life.
While they have limitations in precision, their simplicity makes them
indispensable for educational projects, prototypes, and practical automation
systems.
Quadrilaterals are polygons with four sides. They
come in different types — square, rectangle, parallelogram, rhombus, trapezium
(trapezoid), and kite. Each has unique formulas for area and perimeter.
In this tutorial, we’ll:
Review
the formulas for each quadrilateral.
Write
Python functions to calculate area and perimeter.
Test
our functions with examples.
Step 1: Understanding the Formulas
Here’s a quick reference table:
Step 2: Writing Python Functions
We’ll create modular functions — one for each
quadrilateral.
Arduino Uno is one of the most popular microcontrollers for
beginners and hobbyists. Its simplicity, versatility, and strong community
support make it an ideal platform to learn electronics and programming. One of
the most fundamental tasks you can perform with Arduino is reading analog
input values. Analog inputs allow you to measure continuously varying
signals, such as light intensity, temperature, or the position of a knob.
In this blog post, we’ll walk through how to read analog
input using a 10K potentiometer connected to the A0 pin of an
Arduino Uno. We’ll use a breadboard for easy wiring and display the values on
the Serial Monitor. Along the way, we’ll explore what analog values
mean, how they are represented in Arduino, and why they are significant in
real-world applications.
What is an Analog Input?
Before diving into the wiring and code, let’s clarify what
an analog input is.
Analog
signals are continuous signals that can take any value within a range.
For example, the voltage from a potentiometer can vary smoothly between 0V
and 5V.
Digital
signals, on the other hand, are binary: either HIGH (1) or LOW (0).
Arduino Uno has a built-in Analog-to-Digital Converter
(ADC) that converts analog voltages into digital values. The Uno’s ADC is 10-bit,
meaning it maps input voltages between 0V and 5V into integer values between 0
and 1023.
0
corresponds to 0V.
1023
corresponds to 5V.
Any
voltage in between is mapped proportionally.
This conversion allows Arduino to “understand” analog
signals and use them in programs.
Components Required
To follow along, you’ll need:
Arduino
Uno board
USB
cable for programming and power
Breadboard
10K
potentiometer
Jumper
wires
Circuit Setup
We’ll connect the potentiometer to the Arduino Uno using a
breadboard. A potentiometer is essentially a variable resistor with three pins:
Potentiometers
and joysticks: Allow user input with variable control.
By converting these analog signals into digital values,
Arduino can process them, make decisions, and control outputs like LEDs,
motors, or displays.
Practical Applications
Using a potentiometer as an analog input is just the
beginning. Once you understand how analog values work, you can build projects
such as:
Volume
control: Adjust audio output using a potentiometer.
Light
dimmer: Control LED brightness based on analog input.
Servo
control: Map potentiometer values to servo angles.
Sensor-based
automation: Use analog sensors to trigger actions.
Tips for Beginners
Always
double-check wiring before powering your Arduino.
Use
the Serial Monitor frequently—it’s your window into what Arduino is
“thinking.”
Experiment
with mapping analog values to other ranges using the map() function in
Arduino. For example, mapping 0–1023 to 0–255 for PWM control.
Try
combining multiple analog inputs for more complex projects.
Conclusion
Reading analog input with Arduino Uno is a foundational
skill that opens the door to countless projects. By connecting a 10K
potentiometer to pin A0 and printing values on the Serial Monitor, you’ve
learned how Arduino converts continuous signals into digital values.
Understanding analog values is significant because it
bridges the gap between the physical world and digital electronics. Whether
you’re measuring light, temperature, or sound, analog inputs allow your Arduino
to sense and respond to its environment.
This simple experiment with a potentiometer is more than
just turning a knob—it’s your first step into the world of interactive
electronics. From here, you can explore sensors, automation, and creative
projects that bring analog signals to life.
One of the most fascinating features of Arduino is its
ability to simulate analog signals using Pulse Width Modulation (PWM).
Although the Arduino Uno (and most microcontrollers) doesn’t have true analog
output pins, PWM allows us to control devices as if we had analog voltages
available.
In this post, we’ll explore how Pin 11 on Arduino Uno
works as a PWM pin, how to use it to control the brightness of a Red LED with a
330 Ω resistor, and dive into the theory and functions of PWM in detail.
By the end, you’ll understand not just how to wire and code, but also the inner
workings of PWM signals and why they’re so powerful in embedded systems.
This simple circuit ensures the LED is protected from excess
current while allowing us to control its brightness.
Arduino Code
// PWM LED Brightness Control on Pin 11
#define outputAnalog 11
#define delay1 1000
void setup(){
pinMode(outputAnalog, OUTPUT);
analogWrite(outputAnalog, 0);
}
void loop(){
analogWrite(outputAnalog, 0);
delay(delay1);
analogWrite(outputAnalog, 50);
delay(delay1);
analogWrite(outputAnalog, 100);
delay(delay1);
analogWrite(outputAnalog, 150);
delay(delay1);
analogWrite(outputAnalog, 200);
delay(delay1);
analogWrite(outputAnalog, 255);
delay(delay1);
}
How Pin 11 Works as PWM
On Arduino Uno, Pin 11 is one of the six PWM-capable
pins (3, 5, 6, 9, 10, 11). These pins are marked with a tilde (~) symbol.
Internally, Pin 11 uses Timer2 to generate PWM
signals at a frequency of ~490 Hz. When you call analogWrite(11, value), the
Arduino sets the duty cycle of the PWM signal:
value
= 0 → always LOW (LED OFF)
value
= 255 → always HIGH (LED fully ON)
Any
value in between → LED brightness proportional to duty cycle
Thus, Pin 11 acts like an analog output pin even
though it’s digital, thanks to PWM.
PWM in Detail
1. What is PWM?
PWM stands for Pulse Width Modulation. It’s a
technique where a digital pin rapidly switches between HIGH and LOW states. By
adjusting the width of the HIGH pulse (duty cycle), we control the average
voltage delivered to a device.
For example:
At
25% duty cycle, the pin is HIGH for 25% of the time and LOW for 75%. The
average voltage is ~1.25V (on a 5V system).
At
75% duty cycle, the average voltage is ~3.75V.
This average voltage is what devices like LEDs or motors
respond to, so it feels like a smooth analog output.
2. Duty Cycle
The duty cycle is the percentage of time the signal
stays HIGH in one cycle.
PWM signals also have a frequency, which is how fast
the pin switches between HIGH and LOW.
On Arduino Uno:
Pins
3, 9, 10, 11 → ~490 Hz
Pins
5, 6 → ~980 Hz
This frequency is high enough that the human eye cannot
detect flicker, so LEDs appear to glow steadily.
4. Resolution
Arduino Uno uses 8-bit resolution for PWM. That means
duty cycle values range from 0 to 255.
analogWrite(pin,
0) → 0% duty cycle
analogWrite(pin,
127) → ~50% duty cycle
analogWrite(pin,
255) → 100% duty cycle
This gives 256 possible brightness levels for an LED.
5. Why PWM Works as Analog Output
Even though PWM is digital, devices like LEDs and motors
respond to the average power delivered.
LEDs
integrate the rapid ON/OFF switching into perceived brightness.
Motors
integrate the pulses into torque and speed.
Audio
circuits can even use PWM to approximate analog waveforms.
Thus, PWM is a clever way to simulate analog output without
needing a true DAC (Digital-to-Analog Converter).
Applications of PWM
PWM is everywhere in embedded systems. Some common uses
include:
LED
Dimming → Smooth brightness control.
Motor
Speed Control → Adjusting duty cycle changes motor speed.
Servo
Control → Special PWM signals control servo position.
Audio
Generation → PWM can approximate sound waves.
Power
Regulation → Used in switching power supplies.
Advanced PWM Functions in Arduino
Arduino provides the simple analogWrite() function, but PWM
can be customized further:
Changing
Frequency → By reprogramming timers, you can adjust PWM frequency for
specific applications (e.g., motor control needs higher frequency).
Phase-Correct
PWM → Ensures symmetrical pulses, useful in motor drivers.
Fast
PWM Mode → Provides higher resolution and faster updates.
Timer
Interrupts → Allow precise control over PWM timing.
For most beginners, analogWrite() is sufficient, but
advanced users can dive into timer registers for fine-grained control.
Example: Breathing LED Effect
The code above creates a breathing LED effect. This
is achieved by gradually increasing and decreasing the duty cycle. The LED
appears to fade in and out smoothly, demonstrating how PWM simulates analog
brightness.
Key Notes
Always
use a current-limiting resistor (330 Ω is ideal for a Red LED).
Pin
11 uses Timer2, so changing timer settings can affect PWM behaviour.
PWM
is not true analog, but for LEDs, motors, and many sensors, it works
perfectly.
Other
PWM pins on Arduino Uno: 3, 5, 6, 9, 10, 11.
Conclusion
PWM is one of the most versatile tools in embedded systems.
By using Pin 11 on Arduino Uno, we can control the brightness of a Red
LED with just a few lines of code. More importantly, understanding how PWM
works — duty cycle, frequency, resolution, and average voltage — gives us the
foundation to control a wide range of devices.
From LED dimming to motor control, audio generation to power
regulation, PWM is the bridge between digital microcontrollers and the analog
world.
So next time you call analogWrite(11, value), remember:
you’re not just turning a pin ON or OFF — you’re simulating analog output with
precision and elegance.