You are on page 1of 3

Bachelor of Technology

Information and Communication Technology


Basics of Electronics Engineering (01EC0101)

Activity 4: Interface Potentiometer and Turn on


the LED if the value is beyond thresold

Name:Rajnikant hirapara
Enroll No: 92200133013

 Show the application of if else statement for the following example.


Consider a potentiometer connected on A0 pin of arduino uno
board. Read the values from the potentiometer. If the value obtained
are beyond set thresold level, turn on the built in led, otherwise keep
it in off mode.

 Circuit diagram
Bachelor of Technology
Information and Communication Technology
Basics of Electronics Engineering (01EC0101)

Code
const int analogPin = A0;
const int ledPin = 3;
const int threshold = 400;

void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop()
{
int analogValue = analogRead (analogPin);
if (analogValue > threshold)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
Bachelor of Technology
Information and Communication Technology
Basics of Electronics Engineering (01EC0101)

}
Serial.println(analogValue);
delay(10);
}

You might also like