0% found this document useful (0 votes)
4 views6 pages

Arduino 20 Interfacing Programs

The document contains 20 Arduino interfacing programs with solutions, covering various functionalities such as blinking an LED, reading sensor values, controlling motors, and displaying information on an LCD. Each program includes setup and loop functions with specific code implementations for tasks like temperature monitoring, Bluetooth control, and keypad interfacing. These examples serve as practical applications for learning Arduino programming and interfacing with different components.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Arduino 20 Interfacing Programs

The document contains 20 Arduino interfacing programs with solutions, covering various functionalities such as blinking an LED, reading sensor values, controlling motors, and displaying information on an LCD. Each program includes setup and loop functions with specific code implementations for tasks like temperature monitoring, Bluetooth control, and keypad interfacing. These examples serve as practical applications for learning Arduino programming and interfacing with different components.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

20 Arduino Interfacing Programs with Solutions

1. Blink an LED continuously with a delay of 1 second.


void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

2. Read analog value from LDR and display on Serial Monitor.


void setup() {
[Link](9600);
}
void loop() {
int ldr = analogRead(A0);
[Link](ldr);
delay(1000);
}

3. Interface push button to turn ON/OFF LED.


void setup() {
pinMode(2, INPUT);
pinMode(13, OUTPUT);
}
void loop() {
if (digitalRead(2) == HIGH)
digitalWrite(13, HIGH);
else
digitalWrite(13, LOW);
}

4. Display 'Hello World' on 16x2 LCD.


#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
[Link](16, 2);
[Link]("Hello World");
}
void loop() {}

5. Turn ON LED when temperature > 30°C using DHT11.


#include <DHT.h>
DHT dht(2, DHT11);
void setup() {
[Link](9600);
[Link]();
pinMode(13, OUTPUT);
}
void loop() {
float t = [Link]();
if (!isnan(t) && t > 30)
digitalWrite(13, HIGH);
else
digitalWrite(13, LOW);
delay(1000);
}

6. Control LED via Bluetooth by sending '1' or '0'.


void setup() {
pinMode(13, OUTPUT);
[Link](9600);
}
void loop() {
if ([Link]()) {
char c = [Link]();
digitalWrite(13, c == '1' ? HIGH : LOW);
}
}

7. Control servo motor angle using potentiometer.


#include <Servo.h>
Servo myservo;
void setup() {
[Link](9);
}
void loop() {
int val = analogRead(A0);
val = map(val, 0, 1023, 0, 180);
[Link](val);
delay(15);
}

8. Interface buzzer and beep it every 2 seconds.


void setup() {
pinMode(8, OUTPUT);
}
void loop() {
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(2000);
}

9. Interface ultrasonic sensor to measure distance.


#define trig 9
#define echo 10

void setup() {
[Link](9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long duration = pulseIn(echo, HIGH);
float distance = duration * 0.034 / 2;
[Link](distance);
delay(500);
}

10. Display temperature and humidity on LCD using DHT11.


#include <LiquidCrystal.h>
#include <DHT.h>
DHT dht(2, DHT11);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
[Link](16, 2);
[Link]();
}
void loop() {
float t = [Link]();
float h = [Link]();
[Link](0, 0);
[Link]("Temp: ");
[Link](t);
[Link](0, 1);
[Link]("Hum: ");
[Link](h);
delay(2000);
}

11. Interface MQ135 sensor and show values on Serial.


void setup() {
[Link](9600);
}
void loop() {
int gas = analogRead(A0);
[Link]("MQ135: ");
[Link](gas);
delay(1000);
}

12. Turn ON fan (motor) when temperature > 28°C.


#include <DHT.h>
DHT dht(2, DHT11);
void setup() {
[Link]();
pinMode(9, OUTPUT);
}
void loop() {
float t = [Link]();
digitalWrite(9, t > 28 ? HIGH : LOW);
delay(1000);
}

13. Use IR sensor to detect object and turn ON LED.


void setup() {
pinMode(2, INPUT);
pinMode(13, OUTPUT);
}
void loop() {
if (digitalRead(2) == LOW)
digitalWrite(13, HIGH);
else
digitalWrite(13, LOW);
}

14. Interface relay module to control lamp.


void setup() {
pinMode(8, OUTPUT);
}
void loop() {
digitalWrite(8, HIGH);
delay(5000);
digitalWrite(8, LOW);
delay(5000);
}

15. Display analog sensor value as PWM brightness on LED.


void setup() {
pinMode(9, OUTPUT);
}
void loop() {
int val = analogRead(A0);
int brightness = map(val, 0, 1023, 0, 255);
analogWrite(9, brightness);
delay(100);
}

16. Buzzer alarm if LDR detects darkness.


void setup() {
pinMode(9, OUTPUT);
}
void loop() {
int light = analogRead(A0);
if (light < 300)
digitalWrite(9, HIGH);
else
digitalWrite(9, LOW);
}
17. LED chaser with 5 LEDs.
int pins[] = {2, 3, 4, 5, 6};
void setup() {
for (int i = 0; i < 5; i++)
pinMode(pins[i], OUTPUT);
}
void loop() {
for (int i = 0; i < 5; i++) {
digitalWrite(pins[i], HIGH);
delay(200);
digitalWrite(pins[i], LOW);
}
}

18. Display 'hello world' if 'hello word' is received via Serial.


String input = "";
void setup() {
[Link](9600);
}
void loop() {
while ([Link]()) {
input += char([Link]());
delay(10);
}
if ([Link]() > 0) {
if (input == "hello word") {
[Link]("hello world");
}
input = "";
}
}

19. Count button presses and show on Serial Monitor.


int count = 0;
bool lastState = LOW;
void setup() {
pinMode(2, INPUT);
[Link](9600);
}
void loop() {
bool currentState = digitalRead(2);
if (currentState == HIGH && lastState == LOW) {
count++;
[Link]("Count: ");
[Link](count);
delay(200);
}
lastState = currentState;
}

20. Interface keypad and print key pressed on Serial Monitor.


#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
[Link](9600);
}
void loop() {
char key = [Link]();
if (key) {
[Link](key);
}
}

You might also like