Document Details

EffusiveUkulele

Uploaded by EffusiveUkulele

Koneru Lakshmaiah University

Tags

arduino electronics potentiometer programming

Summary

This document details an experiment on interfacing a potentiometer with an Arduino. The experiment demonstrates how to read potentiometer data, and control the brightness of an LED using a potentiometer. The experiment involves connecting components, writing and uploading code to the Arduino, and experimenting with different configurations.

Full Transcript

FUNDAMENTALS OF IOT AND SENSORS - 24EC1101 Experiment No. 3 Experiment No 3 Student ID Date Student Name INTERFACING POTENTIOMETER WITH ARDUINO GENUINO UNO Aim/Objective: The main obj...

FUNDAMENTALS OF IOT AND SENSORS - 24EC1101 Experiment No. 3 Experiment No 3 Student ID Date Student Name INTERFACING POTENTIOMETER WITH ARDUINO GENUINO UNO Aim/Objective: The main objective of this experiment is, A. To read potentiometer data and print on the Serial Monitor B. To interface potentiometer with LED. Components required: Software Hardware Arduino UNO Board Tinkercad Arduino UNO Cable Arduino IDE (To be installed in Laptop) Potentiometer - 1 LED (Red-1, Green-1, Blue-1) Resistors – 2 (1KΩ each) Jumper wires Description:  The potentiometer is a device that is used to measure the voltage or electric potential. It provides a variable resistance when the shaft of the device is turned.  Here, we will measure the amount of resistance as an analog value produced by the potentiometer. We will connect the potentiometer to the Arduino UNO board and will measure the state of the potentiometer. The required code will be uploaded from our computer to the Arduino board.  The variable resistance measured by the potentiometer can be easily read as an analog value into the Arduino board.  The potentiometer is a three-terminal device. It has a rotating contact that acts as an adjustable voltage divider.  The potentiometer structure consists of a sliding contact (called wiper), a resistive element, electrical terminals, and housing.  The sliding contact moves along the resistive element, while the housing consists of the wiper and the element.  Working: The fixed input voltage is applied across the two ends terminal of a potentiometer, which further produces the adjustable output voltage at the wiper or slider.  As the slider moves from one end to another, the divider can vary the output voltage from maximum to Ground. Page | 2 The connection of potentiometer with Arduino board is shown below: Pre-Requisites:  Electronics fundamentals  Basic knowledge about Arduino Pins Pre-Lab: 1. What is the usage of potentiometer in interfacing Arduino? The potentiometer is a device that is used to measure the voltage or electric potential. It provides a variable resistance when the shaft of the device is turned. 2. How to control potentiometer with Arduino? The typical potentiometer will have 3 pins, two power supply pins (+5V and GND), and one pin that connects to an analog input pin on your Arduino to read the value output. 3. What is the limit of potentiometer in Arduino? The value can be read as an analog value, with the Arduino board. The value goes from 0 to 1023 depending on the rotation of the knob on the potentiometer. 4. What are the two main types of potentiometers? There are two main types of potentiometer, linear potentiometers and rotary potentiometers. 5. How to code potentiometer in Arduino? To code a potentiometer in Arduino, you need to first connect the potentiometer to the Arduino board. The potentiometer has three pins: the first one (usually on the left) connects to 5V, the second one (in the middle) connects to an analog input pin on the Arduino, and the third one (usually on the right) connects to ground (GND). In-Lab: Procedure:  First make sure that the Arduino is powered off.  Plug the potentiometer on the breadboard, with each leg on an independent line. Note: some potentiometers have a different layout, with 2 pins facing one side, and the middle pin facing the other side. In this case, plug the potentiometer in the middle of the breadboard so it will be easier to add wires to the circuit.  Connect one of the external leg of the potentiometer to the ground of the Arduino (GND).  Connect the other external leg to the power supply (5V).  Plug the middle leg to an analog pin of the Arduino, for example here A0. Page | 3 Program: A. Interface potentiometer with Arduino int potpin=A0; // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(potpin); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability } B. Control the brightness of LED with potentiometer. #define LED_PIN 13 #define POTENTIOMETER_PIN A0 void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { int potentiometerValue = analogRead(POTENTIOMETER_PIN); int brightness = potentiometerValue / 4; analogWrite(LED_PIN, brightness); } Page | 4 Connection Diagram: Program A: a. Interface potentiometer with Arduino Program B: b. Control the brightness of LED with potentiometer. Page | 5 Results: VIVA-VOCE Questions (In-Lab): 1. What is the purpose of potentiometer in Arduino?? A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your board, it is possible to measure the amount of resistance produced by a potentiometer (or pot for short) as an analog value. 2. What are the parts of potentiometer in Arduino? The typical potentiometer will have 3 pins, two power supply pins (+5V and GND), and one pin that connects to an analog input pin on your Arduino to read the value output. 3. Which potentiometer is best for Arduino? For use with the Arduino A/D inputs, a pot value in the range of 1K, 5K or 10K will give the best results. 4. What type of signal is a potentiometer? A digital potentiometer (often called digipot) is an electronic component that mimics the functions of analog potentiometers. Through digital input signals, the resistance between two terminals can be adjusted, just as in an analog potentiometer. Post-Lab: 1. Write a program to control RGB LED with a potentiometer. Page | 6 Experiment No 3 Student ID Date Student Name Program: // INPUT: Potentiometer should be connected to 5V and GND int potPin = A0; // Potentiometer output connected to analog pin 3 int potVal = 0; // Variable to store the input from the potentiometer // OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins // LED's cathodes should be connected to digital GND int redPin = 9; // Red LED, connected to digital pin 9 int grnPin = 10; // Green LED, connected to digital pin 10 int bluPin = 11; // Blue LED, connected to digital pin 11 // Program variables int redVal = 0; // Variables to store the values to send to the pins int grnVal = 0; int bluVal = 0; void setup() { pinMode(redPin, OUTPUT); // sets the pins as output pinMode(grnPin, OUTPUT); pinMode(bluPin, OUTPUT); } // Main program void loop() Page | 7 Experiment No 3 Student ID Date Student Name { potVal = analogRead(potPin); // read the potentiometer value at the input pin if (potVal < 341) // Lowest third of the potentiometer's range (0-340) { potVal = (potVal * 3) / 4; // Normalize to 0-255 redVal = 256 - potVal; // Red from full to off grnVal = potVal; // Green from off to full bluVal = 1; // Blue off } else if (potVal < 682) // Middle third of potentiometer's range (341-681) { potVal = ( (potVal-341) * 3) / 4; // Normalize to 0-255 redVal = 1; // Red off grnVal = 256 - potVal; // Green from full to off bluVal = potVal; // Blue from off to full } else // Upper third of potentiometer"s range (682-1023) { potVal = ( (potVal-683) * 3) / 4; // Normalize to 0-255 redVal = potVal; // Red from off to full grnVal = 1; // Green off bluVal = 256 - potVal; // Blue from full to off } analogWrite(redPin, redVal); // Write values to LED pins analogWrite(grnPin, grnVal); analogWrite(bluPin, bluVal); } Page | 8 Evaluator Remark (if Any): Marks Secured: out of 50 Signature of the Evaluator with Date Page | 9

Use Quizgecko on...
Browser
Browser