0% found this document useful (0 votes)
2 views

arduino file

The document outlines practical experiments using Arduino, including digital I/O, analog input/output with PWM, and timing with interrupts, providing detailed procedures and expected results for each experiment. It also describes the De Sauty’s Bridge method for determining unknown capacitance, including apparatus, theory, procedure, and precautions. Each section emphasizes hands-on learning and understanding of electronic principles through experimentation.

Uploaded by

Shashank Lodhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

arduino file

The document outlines practical experiments using Arduino, including digital I/O, analog input/output with PWM, and timing with interrupts, providing detailed procedures and expected results for each experiment. It also describes the De Sauty’s Bridge method for determining unknown capacitance, including apparatus, theory, procedure, and precautions. Each section emphasizes hands-on learning and understanding of electronic principles through experimentation.

Uploaded by

Shashank Lodhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Arduino Programming Practicals

Experiment 1: Introduction to Arduino and Digital I/O


Aim:
To get familiar with the Arduino microcontroller platform, the Arduino Integrated
Development Environment (IDE), and to perform basic digital input and output
operations while introducing serial communication.
Apparatus:
 Arduino board (e.g., Arduino Uno)
 USB cable
 LED
 220Ω resistor
 Pushbutton
 Breadboard
 Jumper wires
Theory:
The Arduino is an open-source microcontroller platform used for building interactive
electronic projects. It consists of a microcontroller board and an IDE for coding and
uploading programs, known as sketches. A microcontroller is a compact integrated
circuit that can be programmed to control devices. Arduino boards feature digital and
analog pins for interfacing with components like LEDs and buttons.
Digital signals are binary, represented as HIGH (5V) or LOW (0V). An LED can be
turned on or off by setting a digital pin’s state, while a button’s state can be read to
detect presses. The Arduino IDE facilitates writing sketches with a basic
structure: setup() runs once at startup, and loop() runs continuously. Serial
communication enables data exchange between the Arduino and a computer,
viewable via the Serial Monitor.
Procedure:
1. Set up the Arduino IDE:
- Download and install the Arduino IDE from the official website.
- Connect the Arduino board to the computer using the USB cable.
- In the IDE, select the board type and port under the *Tools* menu.

2. Blink an LED:
- Connect an LED’s anode to digital pin 13 and cathode to ground via a 220Ω
resistor.
- Write and upload this sketch to blink the LED:
```cpp
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
- Observe the LED blinking every second.

3. Read a Button and Control the LED:


- Connect a pushbutton between digital pin 2 and ground.
- Modify the sketch to turn the LED on when the button is pressed:

int buttonState = 0;
void setup() {
pinMode(13, OUTPUT);
pinMode(2, INPUT_PULLUP);
}
void loop() {
buttonState = digitalRead(2);
if (buttonState == LOW) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
}
- Upload and test by pressing the button.

4. Add Serial Communication:


- Update the sketch to print the button state to the Serial Monitor:

int buttonState = 0;
void setup() {
pinMode(13, OUTPUT);
pinMode(2, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(2);
if (buttonState == LOW) {
digitalWrite(13, HIGH);
Serial.println("Button Pressed");
} else {
digitalWrite(13, LOW);
Serial.println("Button Released");
}
delay(100);
}
- Upload, open the Serial Monitor (Ctrl+Shift+M), and set the baud rate to 9600.
Observation Table:

Button State LED State Serial Monitor Output


Pressed ON “Button Pressed”
Released OFF “Button Released”

Result:
This experiment introduced the Arduino platform, IDE setup, and basic sketch
structure. It demonstrated digital output (controlling an LED), digital input (reading a
button), and serial communication (displaying messages), laying the foundation for
Arduino programming.

Experiment 2: Analog Input and Output with PWM


Aim:
To understand how to measure analog voltage using Arduino’s analog input pins and
generate analog-like voltage using Pulse Width Modulation (PWM).
Apparatus:
 Arduino board
 Potentiometer (10kΩ)
 LED
 220Ω resistor
 Breadboard
 Jumper wires
Theory:
Analog signals vary continuously, unlike binary digital signals. The Arduino uses an
Analog-to-Digital Converter (ADC) to convert analog voltages (0–5V) into digital values
(0–1023), accessible via the analogRead() function. For output, true analog voltage
isn’t possible, so Pulse Width Modulation (PWM) is used. PWM rapidly switches a
digital pin on and off, with the duty cycle determining the average voltage, controlled
by analogWrite() (0–255 range). A potentiometer, a variable resistor, provides
adjustable analog input.
Procedure:
1. Measure Analog Voltage:
- Connect the potentiometer’s middle pin to analog pin A0, and its outer pins to 5V and
ground.
- Write and upload this sketch:

void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(100);
}
- Open the Serial Monitor and turn the potentiometer to see varying values.

2. Control LED Brightness with PWM:


- Connect an LED to digital pin 9 (PWM-capable) via a 220Ω resistor.
- Modify the sketch to adjust LED brightness based on the potentiometer:

void setup() {
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
int brightness = map(sensorValue, 0, 1023, 0, 255);
analogWrite(9, brightness);
Serial.print("Analog Value: ");
Serial.print(sensorValue);
Serial.print(" | Brightness: ");
Serial.println(brightness);
delay(100);
}
- Upload and observe the LED’s brightness changing with the potentiometer.
Observation Table:
Potentiometer Position Analog Brightness LED Brightness
Value
Minimum 0 0 Off
Middle ~512 ~128 Medium
Maximum 1023 255 Full

Result:
This experiment demonstrated measuring analog voltage with analogRead() and
generating analog-like output with PWM using analogWrite(). The potentiometer
controlled LED brightness, reinforcing serial communication skills.

Experiment 3: Timing and Interrupts


Aim:
To learn how to measure time and handle events efficiently using the millis() function
and interrupts in Arduino programming.
Apparatus:
 Arduino board
 Pushbutton
 LED
 220Ω resistor
 10kΩ resistor (for pull-down)
 Breadboard
 Jumper wires
Theory:
Timing is essential in programming. The millis() function tracks time in milliseconds
since the Arduino started, enabling non-blocking delays, unlike delay(). Interrupts
allow immediate response to events (e.g., button presses) by pausing the main
program to run an Interrupt Service Routine (ISR). This enhances efficiency over
constant polling. In this experiment, millis() controls LED blinking, and an interrupt
toggles it via a button, with time between presses measured.
Procedure:
1. Blink LED with millis():
- Connect an LED to digital pin 13 via a 220Ω resistor.
- Upload this sketch to blink the LED every 500ms:

unsigned long previousMillis = 0;


const long interval = 500;
int ledState = LOW;
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
ledState = (ledState == LOW) ? HIGH : LOW;
digitalWrite(13, ledState);
}
}
- Observe the LED blinking.

2. Add Interrupt for Button Press:


- Connect a pushbutton to digital pin 2 (interrupt-capable) and ground, with a 10kΩ
pull-down resistor.
- Update the sketch to toggle blinking with an interrupt:

volatile bool blinking = true;


unsigned long previousMillis = 0;
const long interval = 500;
int ledState = LOW;
void setup() {
pinMode(13, OUTPUT);
pinMode(2, INPUT);
attachInterrupt(digitalPinToInterrupt(2), toggleBlinking, RISING);
}
void loop() {
if (blinking) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
ledState = (ledState == LOW) ? HIGH : LOW;
digitalWrite(13, ledState);
}
} else {
digitalWrite(13, LOW);
}
}
void toggleBlinking() {
blinking = !blinking;
}
- Upload and press the button to toggle blinking.

3. Measure Time Between Presses:


- Enhance the sketch to display time intervals:

volatile bool blinking = true;


volatile unsigned long lastPressTime = 0;
unsigned long previousMillis = 0;
const long interval = 500;
int ledState = LOW;
void setup() {
pinMode(13, OUTPUT);
pinMode(2, INPUT);
attachInterrupt(digitalPinToInterrupt(2), buttonPressed, RISING);
Serial.begin(9600);
}
void loop() {
if (blinking) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
ledState = (ledState == LOW) ? HIGH : LOW;
digitalWrite(13, ledState);
}
} else {
digitalWrite(13, LOW);
}
}
void buttonPressed() {
unsigned long currentTime = millis();
if (lastPressTime != 0) {
unsigned long timeDiff = currentTime - lastPressTime;
Serial.print("Time between presses: ");
Serial.print(timeDiff);
Serial.println(" ms");
}
lastPressTime = currentTime;
blinking = !blinking;
}
- Upload, open the Serial Monitor, and press the button multiple times to see time
differences.
Observation Table:
Button Press Space Time between Presses(ms)
First press N/A (intial press)
Second press 2000
Third press 1500

Result:
This experiment taught non-blocking timing with millis(), efficient event handling with
interrupts, and measuring time intervals, enhancing responsiveness in Arduino
projects.

Aim:
To determine the unknown capacitance using De Sauty’s Bridge Method.

Apparatus Required:
 A.C. source
 Headphones
 Two capacitors (one known , one unknown )
 Two resistors and (one variable)
 De Sauty’s bridge setup
 Connecting wires

Circuit Diagram:
(Leave space to draw the De Sauty’s bridge circuit diagram. If you want a labelled diagram, I can provide
it.)

Theory:
De Sauty's Bridge is a modified Wheatstone bridge used to compare two capacitances. The bridge consists
of two capacitors and two resistors in a bridge network. A headphone is connected between the midpoints of
the capacitor and resistor arms. An A.C. source is applied across the opposite corners.
At balance (no sound in the headphone), the ratio of capacitances equals the ratio of resistances:

Procedure:
1. Connect the circuit as per the diagram.
2. Use the known capacitor and connect the unknown capacitor in the respective arms.
3. Connect resistors (variable) and in the other two arms.
4. Apply an A.C. source between terminals A and C.
5. Connect the headphone between points B and D.
6. Vary until no sound is heard in the headphones (bridge balanced).
7. Note the values of , , and .
8. Calculate the unknown capacitance using the balance condition.
Observations:
Known Capacitance (μF) (Ω) (Ω) Calculated (μF)

Calculation:
C_2 = C_1 \cdot \frac{R_1}{R_2}

Result:
The unknown capacitance is found to be ______ μF.

Precautions:
1. Ensure all connections are tight and correct.
2. Use pure sinusoidal A.C. supply.
3. Adjust the resistors slowly for accurate balance point.
4. Use ideal capacitors if possible.

Let me know if you need the circuit diagram or a Viva Questions section too.

You might also like