0% found this document useful (0 votes)
14 views4 pages

Precsion Lab 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

Lab Report 03

Objective:

Create a dimmer switch by adding a potentiometer to control the brightness of LED, more over
attach a push button on the bread board for controlling the LED (on or off)

Theory:

Components Required:
 Arduino board
 Breadboard.
 LED – any color.
 220 Ohm resistor.
 Potentiometer.
 A bunch of wires (male to female).

LED Connection: Connect the LED to the Arduino with a current-limiting resistor to prevent
excessive current flow and potential damage to the LED.

Potentiometer Setup: Establish connections for the potentiometer, allowing for variable
resistance control. By adjusting the potentiometer, the voltage supplied to the LED will change,
altering its brightness.

Push Button Configuration: Integrate a push button into the circuit to control the LED's on/off
state. When pressed, it will change the LED's state from on to off or vice versa.

Arduino Code: Develop code to read the potentiometer's analog values and adjust the LED's
brightness accordingly. Additionally, incorporate logic to detect the state of the push button to
control the LED's on/off functionality.

Procedure:
1. LED Connection:

1|Page
 Connect the longer leg (anode) of the LED to digital pin 9 on the Arduino through
a 220 Ohm resistor.
 Connect the shorter leg (cathode) of the LED to the ground (GND) pin on the
Arduino.
2. Potentiometer Connection:
 Connect one pin of the potentiometer to the 5V pin on the Arduino.
 Connect the second pin of the potentiometer to the analog pin A0 on the Arduino.
 Connect the third pin (center pin) of the potentiometer to the analog pin A1 on the
Arduino.
3. Push Button Connection:
 Connect one leg of the push button to digital pin 7 on the Arduino.
 Connect the other leg of the push button to the ground (GND) pin on the Arduino.

Arduino Code:
//define LED_PIN 11

//define POTENTIOMETER_PIN A1

void setup()

pinMode(LED_PIN, OUTPUT);

void loop()

int potentiometerValue = analogRead(POTENTIOMETER_PIN);

int brightness = potentiometerValue / 4;

2|Page
analogWrite(LED_PIN, brightness);

Result:

Conclusion:
Upon uploading this code to the Arduino board and ensuring the correct connections:
 The LED brightness will be controlled by rotating the potentiometer.
 Pressing the push button will turn the LED on or off based on its current state.
This setup allows you to adjust the brightness of the LED using the potentiometer and control the
LED's state (on/off) using the push button. Adjusting the potentiometer changes the analog value
sent to the LED, thus altering its brightness. Pressing the button toggles the LED between on and
off states.

3|Page
4|Page

You might also like