0% found this document useful (0 votes)
646 views5 pages

Arduino Practical Questions

The document contains 8 Arduino code examples that demonstrate various functions: 1) A counter program that displays the seconds on an LCD screen. 2) A program that turns an LED on and off using a push button. 3) A program that prints all integer numbers from 0 to 99 using a for loop. 4) A program that reads a number from the serial monitor and prints its multiplication table. 5) A program that calculates and prints the square root of a given number. 6) A program that turns a buzzer on and off with a 1 second delay to create a buzzing sound. 7) A simple "Hello World" program for an LCD display. 8

Uploaded by

radharathour505
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)
646 views5 pages

Arduino Practical Questions

The document contains 8 Arduino code examples that demonstrate various functions: 1) A counter program that displays the seconds on an LCD screen. 2) A program that turns an LED on and off using a push button. 3) A program that prints all integer numbers from 0 to 99 using a for loop. 4) A program that reads a number from the serial monitor and prints its multiplication table. 5) A program that calculates and prints the square root of a given number. 6) A program that turns a buzzer on and off with a 1 second delay to create a buzzing sound. 7) A simple "Hello World" program for an LCD display. 8

Uploaded by

radharathour505
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
You are on page 1/ 5

Arduino Practical Questions/Answers

1. Arduino program to run a counter and display in LCD?


1. #include
2. int seconds = 0;
3. Adafruit_LiquidCrystal lcd(0);
4. void setup()
5. {
6. lcd.begin(16,2);
7. lcd.print("Start");
8. }
9. void loop()
10. {
11. lcd.setCursor(0, 1);
12. lcd.print(seconds);
13. lcd.setBacklight(1);
14. delay(500); // Wait for 500 millisecond(s)
15. lcd.setBacklight(0);
16. delay(500); // Wait for 500 millisecond(s)
17. seconds += 1;
18. }

2. Arduino program to connect a led through push button?


int buttonState = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
// read the state of the pushbutton value
buttonState = digitalRead(2);
if (buttonState == HIGH)
{
digitalWrite(LED_BUILTIN, HIGH);
}
else {
digitalWrite(LED_BUILTIN, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

3. Arduino program to print all 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()
{

}
4. Arduino program to read a integer number and print its
table
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);
}
}
}

5.Arduino program to print the square root of a given


number
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);

6. Arduino program to interface buzzer with Arduino board to buzz on off


with the delay of 1sec.
const int BUZZER = 9;//buzzer to arduino pin 9
void setup()
{
pinMode(BUZZER, OUTPUT);//7 Set buzzer - pin 9 as an output
}
void loop()
{
tone(BUZZER, 1000); // Send 1KHz sound signal...
delay(1000);//for 1 sec
noTone(BUZZER); //Stop sound...
delay(1000); //..for 1sec
}

7.Arduino program to print Hello word in LCD


#include
Adafruit_LiquidCrystal lcd(0);
void setup()
{
lcd.begin(16,1);
lcd.print("hello world");
}
void loop()
{

8.Arduino program to interface buzzer with LDR and LED


void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(8,OUTPUT);
pinMode(A0,INPUT);

}
void loop()
{
int signal;
signal=analogRead(A0);
Serial.println(signal);
if(signal>=400)
{
tone(8,1000);
digitalWrite(13,HIGH);
delay(100);
noTone(8);
digitalWrite(13,LOW);
delay(100);
Serial.println("ALARM ACTIVATED");
}
else
{
noTone(8);
digitalWrite(13,LOW);
Serial.println("ALARM DEACTIVATED");
}
}

You might also like