You are on page 1of 8

Switch with Arduino

Learning outcomes:

● What is an Electrical switch?

● Understanding the working of switch using Arduino

● Upload the code in Arduino IDE software

● Understanding of Voltage, Current and Resistance in circuit

● Applications for switch

1. Introduction:
Remember the switch we have done in electronics we are going to use the
same switches but this time we are going to use the switch with arduino.
A switch is an electrical component that can make or break an electrical circuit
automatically or manually. The switch mainly works with ON (open) and OFF
(closed) mechanisms. Numerous circuits hold switches that control how the
circuit works or actuate different circuit characteristics. The classification of
switches depends on the connection they make.
4. Required components for to complete circuit
• 1 Breadboard
• 1 LED
• 1 Resistor
• 1 Arduino
• 1 push button switch

5. Push button switch


• A push button switch is a type of switch that is typically used to control
electrical circuits. It consists of a button that, when pressed, makes or
breaks the electrical contact between two terminals.
• Push button switches can be momentary or latching, meaning they can
either make contact only while the button is being pressed, or they can
maintain the contact even after the button is released.

Push button switches can be used in a variety of applications, such as


controlling lights, motors, and other electronic devices. They are often used in
conjunction with microcontrollers, such as Arduino, to provide user input for a
project. In an Arduino project, a push button switch can be connected to a
digital pin and read using the digitalRead() function to detect when the button is
pressed or released.

Push button switches can come in a variety of sizes, shapes, and styles. They
can be mounted on a panel, printed circuit board, or soldered directly to a wire.
Some push-button switches may have additional features, such as a built-in
LED indicator or a protective cover. Overall, push-button switches are versatile
and commonly used components in electronics and electrical circuits.

6. Understanding of Voltage, Current, and Resistance in a circuit


In a circuit with three blinking LEDs, voltage, current, and resistance are key
concepts to understand how the circuit works.

● Current: The current in a switch circuit is determined by the voltage


supplied to the circuit and the resistance of the components. For example, if
you have an LED connected to a switch and a resistor, the current flowing
through the LED will be determined by the voltage supplied by the Arduino
and the resistance of the resistor. Too much current can damage the LED or
other components in the circuit, so it's important to calculate the
appropriate resistor value to limit the current.

● Voltage: The voltage in a switch circuit is the potential difference between


two points in the circuit. For example, if you have a voltage divider circuit
connected to a switch, you can measure the voltage across the resistor using
the analogRead () function in Arduino. The voltage can be used to control
other components in the circuit, such as turning on or off an LED.

● Resistance: The resistance in a switch circuit is the opposition to the flow


of current in a circuit. For example, if you have a resistor connected to a
switch and an LED, the resistance of the resistor will limit the current
flowing through the LED. The value of the resistor can be calculated using
Ohm's law (R = V/I) or by using the colour code on the resistor.
Overall, understanding current, voltage, and resistance is essential for designing
and building switch circuits using Arduino. By using these concepts, you can
ensure that your circuit operates safely and effectively.

Connecting the components:-


Step 1:-
1. Find all the components
2. Connect the led and switch
3. Connect the wires with arduino
4. Connect the supply.

3. Upload the code in Arduino IDE software


● Define use the preprocessor directive to define the LED pin (13) and the
switch pin (7) as constants.
● The line declares an integer variable called val and initializes it to 0.

● The setup () function is called once at the beginning of the program. In


this function, the LED pin is set as an output pin and the switch pin is set
as an input pin.
● The loop () function is called repeatedly while the program is running. In
this function, the value of the switch pin is read using the digitalRead ()
function and stored in the val variable. If the switch is pressed (val is
HIGH), the LED pin is set to LOW (turning the LED off), and if the
switch is not pressed (val is LOW), the LED pin is set to HIGH (turning
the LED on).
Overall, this code allows you to turn an LED on and off using a push button
switch. When the switch is pressed, the LED turns off, and when the switch is
released, the LED turns on again.

6.2. Final Code:


The LED should start blinking once the program is uploaded.
7. Applications for switch
Push button switches have a wide range of applications in electronic circuits and
devices. Here are some common applications for push button switches:
1. User input: Push button switches are commonly used as a user input
device in electronic projects. They can be used to trigger an action, select
an option, or enter data.

2. Circuit control: Push-button switches can be used to turn circuits on or


off or to control the direction of current flow in a circuit.

3. Safety switches: Push-button switches can be used as safety switches to


prevent accidents or damage to equipment. For example, a machine may
be equipped with an emergency stop button that shuts off power to the
machine in case of an emergency.

4. Reset buttons: Push-button switches can be used as reset buttons in


electronic devices. They allow the device to be reset to its default state or
to clear any errors or malfunctions.

5. Test buttons: Push-button switches can be used as test buttons to check


the functionality of electronic circuits or devices.

6. Doorbells and alarms: Push-button switches can be used in doorbells and


alarms to trigger an alert or signal.

7. Gaming controllers: Push button switches are commonly used as the main
input device in gaming controllers.
Overall, push-button switches are versatile and commonly used components in
electronic circuits and devices. They come in a variety of shapes and sizes and
can be customized to meet specific application requirements.

Summary:

⮚ Push button switches can be momentary or latching, meaning they can


either make contact only while the button is being pressed, or they can
maintain the contact even after the button is released.

⮚ The current in a switch circuit is determined by the voltage supplied to the


circuit and the resistance of the components.

You might also like