You are on page 1of 3

MPI LAB

LAB 9
Handling Arduino

Name : Burhan Ahmed Satti


Enrollment No. : 01-134172-065
Class : BSCS 4-A
Subject : MPI Lab
Lab Assistant : Muhammad Atif

Objectives
•Introduction to Arduino
•Introduction to basic architecture of Arduino
•Learning the use of Arduino IDE.

Tools Used
•Arduino IDE
BSCS 4-A Burhan Ahmed Satti 01-134172-065

Task No. 9.1


Write a program to measure analog voltage analog data from channel A0 and display the digi-
tized values on the serial monitor. Use the value as time delay to blink/toggle of led.
Solution
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue; // variable to store the value coming from the sensor

void setup() {
// start serial communication
Serial.begin(9600);
}

void loop() {
// read the value from the sensor:

sensorValue = analogRead(sensorPin);

//Print the converted result to arduino terminal

Serial.println(sensorValue);

analogWrite(13, sensorValue);

delay(sensorValue);
}

Result

Conclusion
Task is done.

MPI Lab Page 2 of 3


BSCS 4-A Burhan Ahmed Satti 01-134172-065

Task No. 9.2


Connect potentiometer to the analog channels A5 and write a program which reads & displays
Voltage (V). If V goes below a threshold, on board LED should light up.
Solution
int sensorPin = A5; // select the input pin for the potentiometer
float sensorValue; // variable to store the value coming from the sensor
float VoltageValue;

void setup() {
// start serial communication
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
// read the value from the sensor:

sensorValue = analogRead(sensorPin);

//Print the converted result to arduino terminal

VoltageValue = (sensorValue/1023)*5;

Serial.println(VoltageValue);

if(VoltageValue < 2.5)


digitalWrite(LED_BUILTIN, LOW);
else
digitalWrite(LED_BUILTIN, HIGH);

delay(1000);
}

Result

Conclusion
Task is done.

MPI Lab Page 3 of 3

You might also like