Professional Documents
Culture Documents
IOT Practical Question With Answer
IOT Practical Question With Answer
Questions
Components Required:
• Arduino UNO
• LCD 16*2
• Ultrasonic sensor ( for distance measurement)
• Buzzer
• Breadboard
• Jumper wire for connections
• Resistor and potentiometer for LCD
fi
fi
#include<LiquidCrystal.h>
LiquidCrystal lcd (1,2,4,5,6,7);
void setup()
{ lcd.begin(16,2);
lcd.setCursor(5,0);
lcd.print("WELCOME");
lcd.setCursor(3,1);
lcd.print("TO MY CLASS");
delay(2000);
lcd.setCursor(5,0);
lcd.print("New Way");
lcd.setCursor(3,1);
lcd.print("Of Learning");
delay(2000);
lcd.clear();
}
void loop()
{
lcd.setCursor(2,0);
lcd.print("Arduino class");
lcd.setCursor(2,1);
lcd.print("INFOMAX COMPUTER ACADEMY");
delay(500);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Arduino class");
delay(500);
}
Write a Arduino program to print the Counter value in LCD 16 x 2
#include
int seconds = 0;
Adafruit_LiquidCrystal lcd(0);
void setup()
{
lcd.begin(16,2);
lcd.print("Start");
}
void loop()
{
lcd.setCursor(0, 1);
lcd.print(seconds);
lcd.setBacklight(1);
delay(500); // Wait for 500 millisecond(s)
lcd.setBacklight(0);
delay(500); // Wait for 500 millisecond(s)
seconds += 1;
Output
Arduino Program to take input from serial and on the
led based on input.
Arduino Program which accept the (R,G,Y) from Serial Input and On the Light
Based on Given Input
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
}
void loop()
{
char ch;
if(Serial.available())
{
ch=Serial.read();
Serial.print(ch);
if(ch=='r'||ch=='R')
{
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
else if(ch=='g'||ch=='G')
{
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
}
else if(ch=='y' ||ch=='Y' )
{
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
}
}
}
Arduino program to connect a led through push button
Arduino program to connect a led through push button and use the
if else Statement
int buttonState = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
// read the state of the pushbutton value
buttonState = digitalRead(2);
// check if pushbutton is pressed. if it is, the
// buttonState is HIGH
if (buttonState == HIGH) {
// turn LED on
digitalWrite(LED_BUILTIN, HIGH);
} else {
// turn LED off
digitalWrite(LED_BUILTIN, LOW);
}
delay(10); // Delay a little bit to improve
simulation performance
}
Arduino program to fade the led bulb using for loop
Write a Arduino Code to fade a LED bulb using For loop and repeat the
Process
void setup()
{
// pinMode(10, OUTPUT);
//to analogWrite
}
void loop()
{
for(int a=0;a<=255;a++)
{
analogWrite(10,a);
delay(10); // Wait for 10 millisecond(s)
}
for(int a=255;a>=0;a--)
{
analogWrite(10, a);
delay(10); // Wait for 10 millisecond(s)
}
}
Output
In digitalWrite() we can write only HIGH and LOW but if we want to write
some other values means between 0 to 1 the we need to analogWrite. when
we use analogWrite() the we don't need to set pinMode()
Arduino program to print all integer number from 0 to
99 using for loop
Write a Arduino program to print Integer number from 0 to 99 using for loop.
void setup()
{
Serial.begin(9600);
for(int a=0;a<100;a++)
{
Serial.println(a);
}
}
void loop()
{
}
Arduino program to print odd numbers from 1 to 99
void setup()
{
Serial.begin(9600);
for(int a=1;a<100;a+=2)
{
Serial.println(a);
}
}
void loop()
{
}
Arduino program to print odd numbers from 99 to 1
void setup()
{
Serial.begin(9600);
for(int a=99;a>0;a-=2)
{
Serial.println(a);
}
}
void loop()
{
Output
99
97
95
93
91
89
87
85
83
81
79
77
75
73
71
69
67
65
63
61
59
57
55
53
51
49
47
45
43
41
39
37
35
33
31
29
27
25
23
21
19
17
15
13
11
7
5
1
Arduino program to read a integer number and print its
table
Solution
int num = 0;
int a;
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0)
{
num = Serial.parseInt();
Serial.print("Table of : ");
Serial.println(num);
for(a=1;a<=10;a++)
{
Serial.println(num*a);
}
}
}
Arduino program to print the square root of a given
number
Solution
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
float number = Serial.parseFloat();
float squareRootValue = sqrt(number);
Serial.print("Square Root of ");
Serial.print(number);
Serial.print(" is: ");
Serial.println(squareRootValue);
}
}
Output
int sensorValue = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop()
{
// read the value from the sensor
sensorValue = analogRead(A0);
Serial.print(sensorValue);
// turn the LED on
digitalWrite(LED_BUILTIN, HIGH);
// stop the program for the <sensorValue>
// milliseconds
delay(sensorValue); // Wait for sensorValue
millisecond(s)
// turn the LED off
digitalWrite(LED_BUILTIN, LOW);
// stop the program for the <sensorValue>
// milliseconds
delay(sensorValue); // Wait for sensorValue
millisecond(s)
}
Arduino program to interface buzzer with Arduino board
to buzz on off with the delay of 1sec
Write a program to interface buzzer with Arduino board to buzz on off with the
delay of 1sec