🎓 हर हाथ कंप्यूटर, हर हाथ रोज़गार

    Study Material

    O Level IoT Practical Questions 2026 — 30 PR-4 (M4-R5.1) Arduino Programs with Solution

    30 real O Level PR-4 IoT practical questions — LED, buzzer, buttons, traffic light, relay, sensors, LCD and keypad — with checked Arduino sketches, wiring, Hindi + English tips, viva questions, a free simulator and a free practical test.

    ZK

    Zed-King Group of Institute

    Zed-King Group of Institute

    26 November 2026 39 min read 3 views
    O Level IoT Practical Questions 2026 — 30 PR-4 (M4-R5.1) Arduino Programs with Solution
    Free O Level Mock TestM1–M4 theory + practical papers, instant result. No fees.Start now

    Zed-King Study app · Free

    O Level students across India practise here, free

    Daily M1–M4 quizFull 100-question mocksAll-India rank
    Open the free app

    Google login · no Play Store needed

    🏆 Free All-India Sunday Mock · Sun, 29 Nov, 11 AM · CCC + O LevelRegister

    In O Level M4-R5.1 (Internet of Things and its Applications), the PR-4 practical is an Arduino program: you write the sketch, wire the circuit and show it working. Most questions are short — blink an LED, read a sensor, print on an LCD — but students lose marks on small things: a delay of 2 instead of 2000, a missing pull-down resistor, a sensor read on a digital pin, a toggle that flips a hundred times.

    O Level M4 का PR-4 practical एक Arduino program है — sketch लिखना, circuit जोड़ना और चलाकर दिखाना। ज़्यादातर सवाल छोटे हैं (LED blink, sensor पढ़ना, LCD पर लिखना), फिर भी छोटी गलतियों से नंबर कटते हैं: 2000 की जगह delay(2), pull-down resistor नहीं, sensor को digital pin पर पढ़ना, toggle का सौ बार पलटना। यह guide इन्हीं से बचाती है।

    This guide solves 30 real PR-4 practical questions — from the NIELIT PR-4 previous year practical set, the complete solved set and the M4-R5.1 practical assignments. Each one has the question with its components and wiring, the question in Hindi, a complete Arduino sketch that we have checked, and an exam tip in Hindi and English.

    The O Level January 2027 practicals are scheduled from 23 January to 22 February 2027 (tentative, as per NIELIT). Zed-King Group of Institute, Kaithal is a NIELIT Study Centre (ACCR-O3292) under the Ministry of Electronics & IT, Government of India. No Arduino board at home? Every program here runs in our free online Arduino simulator, and you can take the free PR-4 practical test for marks out of 40.


    What This Guide Covers

    Item

    Detail

    Module

    M4-R5.1 — Internet of Things and its Applications

    Practical paper

    PR-4 (Arduino)

    Programs solved

    30 — LED/Serial 7 · buttons/relay 9 · sensors 9 · LCD/keypad 5

    Source

    NIELIT PR-4 previous year set, complete solved set, M4-R5.1 practical assignments

    Board

    Arduino Uno (Arduino IDE or the free online simulator)

    Each program has

    Question + wiring · question in Hindi · full sketch · exam tip in English + Hindi

    Also inside

    Mistakes that cost marks · viva questions · free simulator and PR-4 test


    How the PR-4 Practical Is Judged

    Like every O Level module, the practical has to be cleared on its own at 50%. In PR-4 the examiner looks at:

    • The sketch — the right pin modes, the right functions (digitalRead, analogRead, analogWrite, Serial, LiquidCrystal) and the logic the question asks for.

    • The exact values — 2 seconds, 30 and 60 seconds, 25 °C, 1 metre, "NIELIT HQ". A wrong number is a lost mark.

    • A working circuit — LED with resistor, button with pull-down, sensor on the right pin. Any valid pin number is accepted.

    • Viva — what setup() and loop() do, analog vs digital pins, what PWM is, what a relay or sensor does.

    Examiner देखता है: sketch में सही pinMode और functions हैं या नहीं, सवाल वाली values (2 second, 25 °C, 1 metre) सही हैं या नहीं, circuit चलता है या नहीं (कोई भी सही pin चलेगा), और आख़िर में viva।


    Topic Map — Where the 30 Programs Come From

    Topic

    Programs

    What it tests

    LED, Buzzer and Serial Monitor

    7

    digitalWrite, delay, Serial.print, for loop, PWM with analogWrite

    Buttons, Traffic Lights and Relay

    9

    digitalRead, if-else, OR condition, toggle with state, relay module

    Sensors

    9

    analogRead, LDR, LM35, DHT11, ultrasonic, water, flame, soil moisture, MQ-135

    LCD and Keypad

    5

    LiquidCrystal, setCursor, scrolling, DHT on LCD, Keypad library

    Every program is built from the same few blocks: pinMode + digitalWrite for outputs, digitalRead + if for buttons, analogRead + threshold for sensors, and LiquidCrystal for the LCD. Learn those four patterns and every PR-4 question becomes a small change to one of them.


    LED, Buzzer and Serial Monitor (7 programs)

    LED, buzzer और Serial Monitor · Covers: digitalWrite, delay, Serial.print, for loop, PWM with analogWrite

    1. Blink an LED with a 2 second delay

    Question (Source: NIELIT PR-4 practical, set 1)

    Write a program to blink the default Light Emitting Diode (LED) on the Arduino board with a delay of 2 seconds.

    Components and wiring

    • Arduino Uno
    • LED
    • 220Ω resistor
    • Breadboard and jumper wires
    • The LED anode goes to a digital pin through the resistor, the cathode to GND

    प्रश्न: Arduino board की default LED को 2 second के delay से blink कराने का program लिखिए।

    Solution — Arduino sketch:

    const int ledPin = 13;   // LED_BUILTIN
    
    void setup() {
      pinMode(ledPin, OUTPUT);
    }
    
    void loop() {
      digitalWrite(ledPin, HIGH);   // turn the LED on
      delay(2000);                  // wait 2 seconds
      digitalWrite(ledPin, LOW);    // turn the LED off
      delay(2000);                  // wait 2 seconds
    }

    💡 Exam tip: Arduino counts time in milliseconds: 2 seconds = delay(2000). Writing delay(2) makes the LED flicker so fast it looks always on.

    💡 टिप: Arduino में समय milliseconds में होता है — 2 second = delay(2000)। delay(2) लिखा तो LED इतनी तेज़ blink करेगी कि हमेशा जलती दिखेगी।

    2. Buzzer on and off with a 1 second delay

    Question (Source: NIELIT PR-4 practical, set 1)

    Write a program to interface a buzzer with the Arduino board so that it buzzes on and off with a delay of 1 second.

    Components and wiring

    • Arduino Uno
    • Buzzer
    • Jumper wires
    • Breadboard
    • The buzzer's positive terminal goes to a digital pin, the negative terminal to GND

    प्रश्न: Arduino के साथ buzzer जोड़कर उसे 1 second के delay से on-off (बजना-रुकना) कराने का program लिखिए।

    Solution — Arduino sketch:

    const int buzzerPin = 13;
    
    void setup() {
      pinMode(buzzerPin, OUTPUT);
    }
    
    void loop() {
      digitalWrite(buzzerPin, HIGH);   // buzzer ON
      delay(1000);
      digitalWrite(buzzerPin, LOW);    // buzzer OFF
      delay(1000);
    }

    💡 Exam tip: Put a delay after both HIGH and LOW. With only one delay, the off state lasts a few microseconds and the buzzer never seems to stop.

    💡 टिप: HIGH और LOW दोनों के बाद delay लगाइए। एक ही delay हो तो off बस कुछ microseconds रहेगा और buzzer रुकता हुआ नहीं लगेगा।

    3. Print even numbers from 100 to 200 on the Serial Monitor

    Question (Source: NIELIT PR-4 practical, set 1)

    Write a program to print the even numbers in the range of 100 to 200 on the Serial Monitor.

    Components and wiring

    • Arduino Uno
    • USB cable to connect the board to the computer
    • The Arduino IDE, with the Serial Monitor open at 9600 baud

    प्रश्न: 100 से 200 तक के even (सम) numbers Serial Monitor पर print करने का program लिखिए।

    Solution — Arduino sketch:

    void setup() {
      Serial.begin(9600);
      for (int num = 100; num <= 200; num++) {
        if (num % 2 == 0) {
          Serial.println(num);
        }
      }
    }
    
    void loop() {
      // nothing to repeat — the list is printed once in setup()
    }

    💡 Exam tip: Print the list in setup(), not loop() — otherwise it repeats forever. An even number is num % 2 == 0; starting at 100 and adding 2 each time also works.

    💡 टिप: List setup() में print कीजिए, loop() में नहीं — वरना बार-बार छपती रहेगी। Even number = num % 2 == 0; या 100 से शुरू करके हर बार 2 जोड़िए।

    4. Read input from the Serial Monitor and echo it back

    Question (Source: NIELIT PR-4 practical, set 2)

    Write a program that will read input from the Serial Monitor and echo it back to you.

    Components and wiring

    • Arduino Uno
    • USB cable — no other wiring is needed
    • The Arduino IDE Serial Monitor, set to 9600 baud

    प्रश्न: Serial Monitor से input पढ़कर वही वापस (echo) दिखाने का program लिखिए।

    Solution — Arduino sketch:

    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      if (Serial.available() > 0) {
        char incomingByte = Serial.read();
        Serial.print("You typed: ");
        Serial.println(incomingByte);
      }
    }

    💡 Exam tip: Always check Serial.available() > 0 before Serial.read(). Without it, read() returns −1 when nothing has arrived and the monitor fills with junk.

    💡 टिप: Serial.read() से पहले हमेशा Serial.available() > 0 जाँचिए — वरना कुछ न आने पर −1 पढ़ा जाएगा और monitor कचरे से भर जाएगा।

    5. Print “Hello, Arduino!” on the Serial Monitor

    Question (Source: NIELIT PR-4 practical, set 5)

    Use the Serial Monitor in the Arduino IDE to display the message Hello, Arduino! after successfully uploading a sketch.

    In your answer, also write a short comment in the sketch explaining how the Serial Monitor helps in debugging.

    Components and wiring

    • Arduino Uno
    • USB cable — no other wiring is needed
    • The Serial Monitor set to 9600 baud

    प्रश्न: Sketch upload होने के बाद Serial Monitor पर "Hello, Arduino!" दिखाइए, और sketch में comment लिखिए कि Serial Monitor debugging में कैसे मदद करता है।

    Solution — Arduino sketch:

    void setup() {
      Serial.begin(9600);
      Serial.println("Hello, Arduino!");
      // The Serial Monitor helps in debugging because it lets us print the value of
      // any variable or sensor while the sketch is running, so we can check where the
      // program is going wrong without any extra hardware.
    }
    
    void loop() {
      // nothing to repeat
    }

    💡 Exam tip: The question asks for a comment — write it inside the sketch with //. The baud rate in Serial.begin(9600) must match the one chosen in the Serial Monitor, or you see garbage characters.

    💡 टिप: सवाल comment माँगता है — उसे sketch में // से लिखिए। Serial.begin(9600) वाला baud rate Serial Monitor में भी 9600 हो, वरना उल्टे-सीधे अक्षर दिखेंगे।

    6. Fade an LED using PWM

    Question (Source: NIELIT PR-4 practical, set 3)

    Write a program demonstrating the use of analog output (Pulse Width Modulation — PWM) to fade an LED.

    Components and wiring

    • Arduino Uno
    • LED with a 220Ω resistor
    • The LED must be on a PWM-capable pin — one marked with a ~ symbol
    • Breadboard and jumper wires

    प्रश्न: Analog output (PWM — Pulse Width Modulation) से LED को धीरे-धीरे जलाने और बुझाने (fade) का program लिखिए।

    Solution — Arduino sketch:

    int ledPin = 9;   // a PWM-capable pin
    
    void setup() {
      pinMode(ledPin, OUTPUT);
    }
    
    void loop() {
      // fade in
      for (int brightness = 0; brightness <= 255; brightness++) {
        analogWrite(ledPin, brightness);
        delay(10);
      }
      // fade out
      for (int brightness = 255; brightness >= 0; brightness--) {
        analogWrite(ledPin, brightness);
        delay(10);
      }
    }

    💡 Exam tip: analogWrite() works only on PWM pins — the ones marked ~ (3, 5, 6, 9, 10, 11 on the Uno). The value goes from 0 to 255; one loop up and one loop down gives the fade in and out.

    💡 टिप: analogWrite() सिर्फ़ ~ वाले PWM pins (Uno पर 3, 5, 6, 9, 10, 11) पर चलता है। Value 0 से 255 तक — एक loop ऊपर, एक नीचे = fade in और fade out।

    7. Blink four LEDs alternately

    Question (Source: NIELIT PR-4 practical, set 3)

    Write a program to interface LEDs on pin numbers 10, 11, 12 and 13 and blink them alternately at a delay of 1 second.

    Components and wiring

    • Arduino Uno
    • 4 LEDs
    • 4 × 220Ω resistors
    • Breadboard and jumper wires
    • Each LED anode to its pin, each cathode to GND through a resistor

    प्रश्न: Pin 10, 11, 12 और 13 पर चार LED जोड़कर उन्हें बारी-बारी (alternately) 1 second के delay से blink कराइए।

    Solution — Arduino sketch:

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

    💡 Exam tip: In every step switch the other three LEDs off, not just the next one on — otherwise all four end up glowing together after the first round.

    💡 टिप: हर step में बाकी तीन LED को off भी कीजिए, सिर्फ़ अगली को on नहीं — वरना पहले round के बाद चारों साथ जलती रहेंगी।


    Buttons, Traffic Lights and Relay (9 programs)

    Button, traffic light और relay · Covers: digitalRead, if-else, OR condition, toggle with state, relay module

    8. Interface a button and an LED

    Question (Source: NIELIT PR-4 practical, set 2)

    Write a program to interface a button and an LED, so that the LED glows when the button is pressed.

    Components and wiring

    • Arduino Uno
    • LED with a 220Ω resistor
    • Pushbutton with a 10kΩ pull-down resistor
    • The LED anode to a digital pin, the button to another digital pin and GND

    प्रश्न: Button और LED जोड़िए ताकि button दबाने पर LED जले।

    Solution — Arduino sketch:

    const int ledPin = 9;
    const int buttonPin = 7;
    
    void setup() {
      pinMode(ledPin, OUTPUT);
      pinMode(buttonPin, INPUT);
    }
    
    void loop() {
      int buttonState = digitalRead(buttonPin);
      if (buttonState == HIGH) {
        digitalWrite(ledPin, HIGH);
      } else {
        digitalWrite(ledPin, LOW);
      }
    }

    💡 Exam tip: Use a 10kΩ pull-down resistor on the button pin (or INPUT_PULLUP and test for LOW). A floating input pin reads random HIGH/LOW and the LED flickers by itself.

    💡 टिप: Button pin पर 10kΩ pull-down resistor लगाइए (या INPUT_PULLUP लेकर LOW जाँचिए)। खुला (floating) pin अपने आप HIGH/LOW पढ़ता है और LED टिमटिमाती है।

    9. Interface an LED and a buzzer together

    Question (Source: NIELIT PR-4 practical, set 2)

    Write a program to interface an LED and a buzzer with the Arduino board, so that the buzzer is put on whenever the LED is on, and the buzzer is put off when the LED is off.

    Components and wiring

    • Arduino Uno
    • LED with a 220Ω resistor
    • Buzzer
    • Breadboard and jumper wires
    • The LED on one digital pin, the buzzer on another, both returning to GND

    प्रश्न: LED और buzzer दोनों जोड़िए — जब LED on हो तो buzzer भी on, और LED off हो तो buzzer भी off।

    Solution — Arduino sketch:

    const int ledPin = 9;
    const int buzzerPin = 8;
    
    void setup() {
      pinMode(ledPin, OUTPUT);
      pinMode(buzzerPin, OUTPUT);
    }
    
    void loop() {
      digitalWrite(ledPin, HIGH);      // LED on
      digitalWrite(buzzerPin, HIGH);   // buzzer on with it
      delay(2000);
      digitalWrite(ledPin, LOW);       // LED off
      digitalWrite(buzzerPin, LOW);    // buzzer off with it
      delay(2000);
    }

    💡 Exam tip: Write the LED and buzzer lines next to each other before one shared delay(), so both change at the same instant.

    💡 टिप: LED और buzzer की lines साथ-साथ लिखकर फिर एक ही delay() लगाइए, ताकि दोनों एक ही पल में बदलें।

    10. Button, buzzer and LED together

    Question (Source: NIELIT PR-4 practical, set 5)

    Write a program to interface a button, a buzzer and an LED, so that whenever the button is pressed the buzzer sounds and the LED glows, and both stop when the button is released.

    Components and wiring

    • Arduino Uno
    • LED with a 220Ω resistor
    • Buzzer
    • Pushbutton with a 10kΩ pull-down resistor
    • Breadboard and jumper wires

    प्रश्न: Button, buzzer और LED जोड़िए — button दबाने पर buzzer बजे और LED जले, छोड़ने पर दोनों बंद।

    Solution — Arduino sketch:

    const int ledPin = 9;
    const int buzzerPin = 8;
    const int buttonPin = 7;
    
    void setup() {
      pinMode(ledPin, OUTPUT);
      pinMode(buzzerPin, OUTPUT);
      pinMode(buttonPin, INPUT);
    }
    
    void loop() {
      if (digitalRead(buttonPin) == HIGH) {
        digitalWrite(ledPin, HIGH);
        digitalWrite(buzzerPin, HIGH);
      } else {
        digitalWrite(ledPin, LOW);
        digitalWrite(buzzerPin, LOW);
      }
    }

    💡 Exam tip: The else part is half the marks: without it the LED and buzzer stay on after you release the button.

    💡 टिप: else वाला हिस्सा आधे नंबर का है — उसके बिना button छोड़ने के बाद भी LED और buzzer चालू रहेंगे।

    11. Control an LED with three separate buttons

    Question (Source: NIELIT PR-4 practical, set 7)

    Write a program to control an LED with three separate buttons — pressing any one of the three buttons should light the LED.

    Components and wiring

    • Arduino Uno
    • LED with a 220Ω resistor
    • 3 pushbuttons, each with a 10kΩ pull-down resistor
    • Each button on its own digital pin

    प्रश्न: तीन अलग buttons से एक LED चलाइए — तीनों में से कोई भी button दबाने पर LED जले।

    Solution — Arduino sketch:

    const int button1 = 2;
    const int button2 = 3;
    const int button3 = 4;
    const int ledPin = 9;
    
    void setup() {
      pinMode(button1, INPUT);
      pinMode(button2, INPUT);
      pinMode(button3, INPUT);
      pinMode(ledPin, OUTPUT);
    }
    
    void loop() {
      int b1 = digitalRead(button1);
      int b2 = digitalRead(button2);
      int b3 = digitalRead(button3);
    
      if (b1 == HIGH || b2 == HIGH || b3 == HIGH) {
        digitalWrite(ledPin, HIGH);
      } else {
        digitalWrite(ledPin, LOW);
      }
    }

    💡 Exam tip: "Any one of the three" means OR: b1 == HIGH || b2 == HIGH || b3 == HIGH. Using && lights the LED only when all three are pressed.

    💡 टिप: "तीनों में से कोई भी" = OR (||)। && लिखा तो LED तभी जलेगी जब तीनों buttons एक साथ दबें।

    12. Toggle an LED using the push button state and the LED state

    Question (Source: NIELIT PR-4 practical, set 7)

    Write a program for controlling the LED with a push button state and the LED state — each press should toggle the LED, so one press turns it on and the next press turns it off.

    Components and wiring

    • Arduino Uno
    • LED with a 220Ω resistor
    • Pushbutton with a 10kΩ pull-down resistor
    • Breadboard and jumper wires

    प्रश्न: Push button की state और LED की state से LED चलाइए — हर press पर LED toggle हो: एक press पर on, अगले पर off।

    Solution — Arduino sketch:

    const int buttonPin = 7;
    const int ledPin = 9;
    
    int ledState = LOW;
    int lastButtonState = LOW;
    
    void setup() {
      pinMode(buttonPin, INPUT);
      pinMode(ledPin, OUTPUT);
    }
    
    void loop() {
      int buttonState = digitalRead(buttonPin);
    
      // act only on the moment the button goes down
      if (buttonState == HIGH && lastButtonState == LOW) {
        ledState = !ledState;          // flip the remembered state
        digitalWrite(ledPin, ledState);
        delay(50);                     // simple debounce
      }
      lastButtonState = buttonState;
    }

    💡 Exam tip: Toggle on the moment of the press — buttonState == HIGH && lastButtonState == LOW — and remember the last state. If you toggle whenever the button reads HIGH, the LED flips hundreds of times while your finger is down.

    💡 टिप: Toggle सिर्फ़ दबाने के पल पर कीजिए (अभी HIGH और पिछली बार LOW) और पिछली state याद रखिए। सिर्फ़ HIGH देखकर toggle किया तो उँगली दबी रहने तक LED सैकड़ों बार पलटेगी।

    13. Street traffic signal

    Question (Source: NIELIT PR-4 practical, set 4)

    Design an interface showing the street traffic signal, programmed to keep the red light for 30 seconds and the green light for 60 seconds.

    Components and wiring

    • Arduino Uno
    • Red, yellow and green LEDs
    • 3 × 220Ω resistors
    • Breadboard and jumper wires
    • Each LED on its own digital pin, cathodes to GND

    प्रश्न: सड़क का traffic signal बनाइए — लाल बत्ती 30 second और हरी बत्ती 60 second तक जले।

    Solution — Arduino sketch:

    const int redPin = 8;
    const int yellowPin = 9;
    const int greenPin = 10;
    
    void setup() {
      pinMode(redPin, OUTPUT);
      pinMode(yellowPin, OUTPUT);
      pinMode(greenPin, OUTPUT);
    }
    
    void loop() {
      // RED for 30 seconds
      digitalWrite(redPin, HIGH);
      digitalWrite(yellowPin, LOW);
      digitalWrite(greenPin, LOW);
      delay(30000);
    
      // GREEN for 60 seconds
      digitalWrite(redPin, LOW);
      digitalWrite(greenPin, HIGH);
      delay(60000);
    
      // YELLOW briefly before the cycle repeats
      digitalWrite(greenPin, LOW);
      digitalWrite(yellowPin, HIGH);
      delay(3000);
      digitalWrite(yellowPin, LOW);
    }

    💡 Exam tip: 30 s = delay(30000), 60 s = delay(60000). Name the pins red, yellow and green and switch the other lights off in each phase — two lights glowing together is the most common mistake.

    💡 टिप: 30 s = delay(30000), 60 s = delay(60000)। Pins के नाम red, yellow, green रखिए और हर phase में बाकी बत्तियाँ off कीजिए — दो बत्तियाँ साथ जलना सबसे आम गलती है।

    14. Pedestrian crossing

    Question (Source: NIELIT PR-4 practical, set 4)

    Write a program for a pedestrian crossing: the traffic lights normally let the vehicles pass, and when a pedestrian presses the request button the lights change to red so that the pedestrian can cross, then return to normal.

    Components and wiring

    • Arduino Uno
    • Red and green LEDs for the traffic, plus LEDs for the pedestrian signal
    • Pushbutton with a 10kΩ pull-down resistor
    • Breadboard and jumper wires

    प्रश्न: Pedestrian crossing का program: आम तौर पर गाड़ियों के लिए हरी बत्ती; कोई पैदल यात्री button दबाए तो गाड़ियों की बत्ती लाल हो, वह सड़क पार करे, फिर सब सामान्य हो जाए।

    Solution — Arduino sketch:

    const int carRed = 8;
    const int carGreen = 9;
    const int walkGreen = 10;
    const int buttonPin = 7;
    
    void setup() {
      pinMode(carRed, OUTPUT);
      pinMode(carGreen, OUTPUT);
      pinMode(walkGreen, OUTPUT);
      pinMode(buttonPin, INPUT);
      digitalWrite(carGreen, HIGH);   // traffic flows by default
    }
    
    void loop() {
      if (digitalRead(buttonPin) == HIGH) {
        digitalWrite(carGreen, LOW);
        digitalWrite(carRed, HIGH);     // stop the traffic
        delay(2000);
        digitalWrite(walkGreen, HIGH);  // let the pedestrian cross
        delay(8000);
        digitalWrite(walkGreen, LOW);
        digitalWrite(carRed, LOW);
        digitalWrite(carGreen, HIGH);   // back to normal
      }
    }

    💡 Exam tip: Set the normal state (car green) once in setup(); loop() only waits for the button. Keep a short gap between car-red and walk-green, as on a real road.

    💡 टिप: सामान्य हालत (गाड़ी के लिए हरी) setup() में एक बार लगाइए; loop() बस button का इंतज़ार करे। गाड़ी की लाल और पैदल की हरी के बीच थोड़ा gap रखिए, असली सड़क जैसा।

    15. Control a relay using a button

    Question (Source: NIELIT PR-4 practical, set 9)

    Write a program to control a relay using a button — pressing the button should switch the relay on, releasing it should switch the relay off.

    Components and wiring

    • Arduino Uno
    • Single-channel 5V relay module
    • Pushbutton with a 10kΩ pull-down resistor
    • The relay IN pin to a digital pin, VCC to 5V, GND to GND

    प्रश्न: Button से relay चलाइए — button दबाने पर relay on, छोड़ने पर off।

    Solution — Arduino sketch:

    const int relayPin = 8;
    const int buttonPin = 7;
    
    void setup() {
      pinMode(relayPin, OUTPUT);
      pinMode(buttonPin, INPUT);
    }
    
    void loop() {
      if (digitalRead(buttonPin) == HIGH) {
        digitalWrite(relayPin, HIGH);    // relay ON
      } else {
        digitalWrite(relayPin, LOW);     // relay OFF
      }
    }

    💡 Exam tip: The code is the same as button + LED — only the output is a relay module. Some relay modules are active-LOW (they click on with LOW); if yours works in reverse, swap HIGH and LOW.

    💡 टिप: Code बिल्कुल button + LED जैसा है, बस output relay है। कुछ relay modules active-LOW होते हैं (LOW पर चालू) — उल्टा चले तो HIGH और LOW बदल दीजिए।

    16. Control a 220 V lamp through a relay

    Question (Source: NIELIT PR-4 practical, set 9)

    Write a program to control a lamp operating at 220 V using the Arduino and a relay module, switching it on and off at a fixed interval.

    Safety note: mains wiring must only be done under supervision. In the simulator, use the relay module with an LED or a lamp component in place of the mains lamp.

    Components and wiring

    • Arduino Uno
    • 5V relay module rated for mains switching
    • Lamp (or an LED in the simulator)
    • The relay IN pin to a digital pin, VCC to 5V, GND to GND

    प्रश्न: Arduino और relay module से 220 V पर चलने वाला lamp तय समय के अंतराल पर on-off कीजिए।

    Solution — Arduino sketch:

    const int relayPin = 8;   // drives the lamp through the relay
    
    void setup() {
      pinMode(relayPin, OUTPUT);
    }
    
    void loop() {
      digitalWrite(relayPin, HIGH);   // lamp ON
      delay(5000);
      digitalWrite(relayPin, LOW);    // lamp OFF
      delay(5000);
    }

    💡 Exam tip: Never touch the 220 V side — the Arduino only drives the relay's IN pin. In the simulator use an LED in place of the lamp, and say this in the viva: it shows you understand mains safety.

    💡 टिप: 220 V वाले हिस्से को कभी न छुएँ — Arduino सिर्फ़ relay का IN pin चलाता है। Simulator में lamp की जगह LED लगाइए, और viva में यह बात बताइए — safety की समझ दिखती है।


    Sensors (9 programs)

    Sensors · Covers: analogRead, LDR, LM35, DHT11, ultrasonic, water, flame, soil moisture, MQ-135

    17. Read an LDR and print the values every 2 seconds

    Question (Source: NIELIT PR-4 practical, set 3)

    Write a program to interface a Light Dependent Resistor (LDR) and display the values read on the Serial Monitor after a delay of 2 seconds each.

    Components and wiring

    • Arduino Uno
    • LDR
    • 10kΩ resistor for the voltage divider
    • The junction of the LDR and the resistor goes to an analog pin such as A0

    प्रश्न: LDR (Light Dependent Resistor) जोड़कर उसकी values हर 2 second पर Serial Monitor पर दिखाइए।

    Solution — Arduino sketch:

    int ldrPin = A0;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      int ldrValue = analogRead(ldrPin);
      Serial.print("LDR Value: ");
      Serial.println(ldrValue);
      delay(2000);
    }

    💡 Exam tip: An LDR needs a 10kΩ resistor as a voltage divider and an analog pin (A0–A5). analogRead() gives 0–1023; cover the LDR with your hand and the value should change.

    💡 टिप: LDR के साथ 10kΩ resistor (voltage divider) और analog pin (A0–A5) चाहिए। analogRead() 0–1023 देता है; LDR को हाथ से ढकिए, value बदलनी चाहिए।

    18. Room temperature with an LM35 sensor

    Question (Source: NIELIT PR-4 practical, set 5)

    Write a program in Arduino to interface a temperature sensor (LM35) to detect the temperature of a room and show it on the Serial Monitor.

    Components and wiring

    • Arduino Uno
    • LM35 analog temperature sensor
    • The LM35 output pin to an analog pin such as A0, VCC to 5V, GND to GND
    • The LM35 output rises by 10 mV per °C

    प्रश्न: LM35 temperature sensor से कमरे का तापमान पढ़कर Serial Monitor पर दिखाइए।

    Solution — Arduino sketch:

    const int lm35Pin = A0;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      int sensorValue = analogRead(lm35Pin);
      float voltage = sensorValue * (5.0 / 1023.0);   // convert to volts
      float temperatureC = voltage * 100;             // 10 mV per degree C
    
      Serial.print("Temperature: ");
      Serial.print(temperatureC);
      Serial.println(" C");
      delay(2000);
    }

    💡 Exam tip: Learn the two-line formula: voltage = reading × 5.0 / 1023.0, temperature = voltage × 100 (LM35 gives 10 mV per °C). Write 5.0, not 5 — integer division would make it 0.

    💡 टिप: दो line का formula याद कीजिए: voltage = reading × 5.0/1023.0, temperature = voltage × 100 (LM35 = 10 mV प्रति °C)। 5 नहीं 5.0 लिखिए — integer division से जवाब 0 आ जाएगा।

    19. Switch on an LED when the temperature rises above 25 °C

    Question (Source: NIELIT PR-4 practical, set 6)

    Write a program to interface a DHT sensor with an LED. The program will switch ON the LED once the temperature rises above 25 degrees.

    Components and wiring

    • Arduino Uno
    • DHT11 or DHT22 temperature and humidity sensor
    • LED with a 220Ω resistor
    • The DHT data pin to a digital pin, VCC to 5V, GND to GND

    प्रश्न: DHT sensor और LED जोड़िए — तापमान 25 degree से ऊपर जाते ही LED on हो जाए।

    Solution — Arduino sketch:

    #include <DHT.h>
    
    #define DHTPIN 2
    #define DHTTYPE DHT11
    DHT dht(DHTPIN, DHTTYPE);
    
    const int ledPin = 9;
    
    void setup() {
      Serial.begin(9600);
      dht.begin();
      pinMode(ledPin, OUTPUT);
    }
    
    void loop() {
      float temperature = dht.readTemperature();
      Serial.print("Temperature: ");
      Serial.println(temperature);
    
      if (temperature > 25) {
        digitalWrite(ledPin, HIGH);
      } else {
        digitalWrite(ledPin, LOW);
      }
      delay(2000);
    }

    💡 Exam tip: Write #include <DHT.h>, create the DHT dht(DHTPIN, DHTTYPE); object and call dht.begin() in setup. The DHT11 is slow — read it every 2 seconds, not in a tight loop.

    💡 टिप: #include <DHT.h>, DHT object और setup() में dht.begin() — तीनों ज़रूरी हैं। DHT11 धीमा है, उसे हर 2 second पर पढ़िए।

    20. Sense an obstacle closer than 1 metre

    Question (Source: NIELIT PR-4 practical, set 6)

    Write a program to sense an obstacle closer than 1 metre using an ultrasonic sensor, and give an indication when one is found.

    Components and wiring

    • Arduino Uno
    • HC-SR04 ultrasonic sensor
    • LED or buzzer for the indication
    • Trig and Echo to two digital pins, VCC to 5V, GND to GND

    प्रश्न: Ultrasonic sensor (HC-SR04) से 1 metre से नज़दीक की रुकावट (obstacle) पहचानिए और मिलने पर संकेत (LED/buzzer) दीजिए।

    Solution — Arduino sketch:

    const int trigPin = 9;
    const int echoPin = 10;
    const int ledPin = 13;
    
    void setup() {
      pinMode(trigPin, OUTPUT);
      pinMode(echoPin, INPUT);
      pinMode(ledPin, OUTPUT);
      Serial.begin(9600);
    }
    
    void loop() {
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
    
      long duration = pulseIn(echoPin, HIGH);
      float distance = duration * 0.034 / 2;   // centimetres
    
      Serial.print("Distance: ");
      Serial.println(distance);
    
      if (distance < 100) {          // closer than 1 metre
        digitalWrite(ledPin, HIGH);
      } else {
        digitalWrite(ledPin, LOW);
      }
      delay(500);
    }

    💡 Exam tip: Distance in cm = duration * 0.034 / 2 — sound travels 0.034 cm per microsecond, and divide by 2 because the echo goes there and back. 1 metre = distance < 100 (cm), not < 1.

    💡 टिप: Distance (cm) = duration × 0.034 / 2 — आवाज़ जाकर लौटती है, इसलिए 2 से भाग। 1 metre = distance < 100 (cm में), < 1 नहीं।

    21. Buzz when water is detected

    Question (Source: NIELIT PR-4 practical, set 6)

    Write a program to buzz when water is detected by a water sensor.

    Components and wiring

    • Arduino Uno
    • Water level / rain sensor module
    • Buzzer
    • The sensor's analog output to an analog pin, the buzzer to a digital pin

    प्रश्न: Water sensor पर पानी आते ही buzzer बजाने का program लिखिए।

    Solution — Arduino sketch:

    const int waterPin = A0;
    const int buzzerPin = 8;
    const int threshold = 300;
    
    void setup() {
      pinMode(buzzerPin, OUTPUT);
      Serial.begin(9600);
    }
    
    void loop() {
      int waterValue = analogRead(waterPin);
      Serial.print("Water sensor: ");
      Serial.println(waterValue);
    
      if (waterValue > threshold) {      // water detected
        digitalWrite(buzzerPin, HIGH);
      } else {
        digitalWrite(buzzerPin, LOW);
      }
      delay(500);
    }

    💡 Exam tip: Print the sensor value on the Serial Monitor first, dip the sensor, and choose the threshold from what you see. Examiners like it when the threshold is a named constant.

    💡 टिप: पहले sensor की value Serial Monitor पर छापिए, sensor को पानी में डुबोकर देखिए, फिर threshold तय कीजिए। Threshold को नाम वाला constant रखना examiner को अच्छा लगता है।

    22. Detect light with a photoresistor and report the LED state

    Question (Source: NIELIT PR-4 practical, set 8)

    Write a program for the detection of light using a photo resistor, with the output showing whether light was detected and what the LED state is.

    Components and wiring

    • Arduino Uno
    • Photo resistor (LDR) with a 10kΩ resistor as a voltage divider
    • LED with a 220Ω resistor
    • The divider junction to an analog pin such as A0

    प्रश्न: Photo resistor (LDR) से रोशनी पहचानिए — output में दिखाइए कि रोशनी मिली या नहीं और LED की state क्या है।

    Solution — Arduino sketch:

    const int ldrPin = A0;
    const int ledPin = 9;
    const int threshold = 500;
    
    void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT);
    }
    
    void loop() {
      int lightValue = analogRead(ldrPin);
    
      if (lightValue > threshold) {
        digitalWrite(ledPin, LOW);
        Serial.println("Light detected - LED state: OFF");
      } else {
        digitalWrite(ledPin, HIGH);
        Serial.println("Darkness detected - LED state: ON");
      }
      delay(1000);
    }

    💡 Exam tip: The question asks for two things in the output: light or dark, and the LED state — print both in the same line. Which way the value moves depends on how the divider is wired, so test with your hand over the LDR.

    💡 टिप: Output में दो बातें चाहिए — रोशनी है या अँधेरा, और LED की state — दोनों एक ही line में छापिए। Value किस तरफ़ बदलेगी यह wiring पर निर्भर है, हाथ से ढककर जाँचिए।

    23. Alert system using a flame sensor

    Question (Source: NIELIT PR-4 practical, set 8)

    Write a program to develop an alert system using a flame sensor — when a flame is detected the buzzer should sound and a warning should appear on the Serial Monitor.

    Components and wiring

    • Arduino Uno
    • Flame / IR fire sensor module
    • Buzzer
    • LED with a 220Ω resistor
    • The sensor's digital output to a digital pin, VCC to 5V, GND to GND

    प्रश्न: Flame sensor से alert system बनाइए — आग दिखते ही buzzer बजे और Serial Monitor पर चेतावनी आए।

    Solution — Arduino sketch:

    const int flamePin = 7;
    const int buzzerPin = 8;
    const int ledPin = 9;
    
    void setup() {
      pinMode(flamePin, INPUT);
      pinMode(buzzerPin, OUTPUT);
      pinMode(ledPin, OUTPUT);
      Serial.begin(9600);
    }
    
    void loop() {
      int flame = digitalRead(flamePin);
    
      if (flame == LOW) {                 // most modules pull LOW on detection
        digitalWrite(buzzerPin, HIGH);
        digitalWrite(ledPin, HIGH);
        Serial.println("WARNING: Fire detected!");
      } else {
        digitalWrite(buzzerPin, LOW);
        digitalWrite(ledPin, LOW);
        Serial.println("No fire");
      }
      delay(500);
    }

    💡 Exam tip: Most flame modules pull their digital output LOW when they see fire — so the test is flame == LOW. If your alarm rings all the time, this is the reason.

    💡 टिप: ज़्यादातर flame modules आग दिखने पर output LOW करते हैं — इसलिए शर्त flame == LOW है। Alarm हर समय बजे तो वजह यही है।

    24. Read values from a soil moisture sensor

    Question (Source: NIELIT PR-4 practical, set 8)

    Write a program to read values from a soil moisture sensor and display them on the Serial Monitor, indicating whether the soil is dry or wet.

    Components and wiring

    • Arduino Uno
    • Soil moisture sensor module
    • The sensor's analog output to an analog pin such as A0, VCC to 5V, GND to GND

    प्रश्न: Soil moisture sensor की values पढ़कर Serial Monitor पर दिखाइए और बताइए कि मिट्टी सूखी है या गीली।

    Solution — Arduino sketch:

    const int soilPin = A0;
    const int threshold = 500;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      int moisture = analogRead(soilPin);
      Serial.print("Soil moisture value: ");
      Serial.println(moisture);
    
      if (moisture > threshold) {
        Serial.println("Soil is DRY - watering needed");
      } else {
        Serial.println("Soil is WET");
      }
      delay(2000);
    }

    💡 Exam tip: With the common resistive module a higher reading means drier soil, so moisture > threshold = dry. Print the value as well as the words "dry"/"wet" — both are asked.

    💡 टिप: आम resistive module में ज़्यादा reading = सूखी मिट्टी, इसलिए moisture > threshold = dry। Value और "dry/wet" दोनों छापिए — सवाल दोनों माँगता है।

    25. Air quality sensor for pollution monitoring

    Question (Source: NIELIT PR-4 practical, set 9)

    Write a program for interfacing an air quality sensor to sense the air index value and warn when the pollution level crosses a safe limit.

    Components and wiring

    • Arduino Uno
    • MQ-135 air quality sensor
    • Buzzer or LED for the warning
    • The sensor's analog output to an analog pin such as A0

    प्रश्न: Air quality sensor (MQ-135) से हवा का index पढ़िए और pollution तय सीमा से ऊपर जाने पर चेतावनी दीजिए।

    Solution — Arduino sketch:

    const int airPin = A0;
    const int buzzerPin = 8;
    const int safeLimit = 400;
    
    void setup() {
      Serial.begin(9600);
      pinMode(buzzerPin, OUTPUT);
    }
    
    void loop() {
      int airQuality = analogRead(airPin);
      Serial.print("Air quality index: ");
      Serial.println(airQuality);
    
      if (airQuality > safeLimit) {
        digitalWrite(buzzerPin, HIGH);
        Serial.println("WARNING: Air pollution is high!");
      } else {
        digitalWrite(buzzerPin, LOW);
      }
      delay(2000);
    }

    💡 Exam tip: The MQ-135 needs a minute or two to warm up — early readings are high. Keep the safe limit in a named constant and give both a buzzer and a Serial Monitor warning.

    💡 टिप: MQ-135 को गर्म होने में 1–2 मिनट लगते हैं — शुरू की readings ज़्यादा आती हैं। Safe limit को नाम वाला constant रखिए और buzzer व Serial Monitor दोनों पर चेतावनी दीजिए।


    LCD and Keypad (5 programs)

    LCD और keypad · Covers: LiquidCrystal, setCursor, scrolling, DHT on LCD, Keypad library

    26. Display “Hello World” on an LCD

    Question (Source: NIELIT PR-4 practical, set 4)

    Write a program to interface an LCD with the Arduino board and display Hello World on it.

    Components and wiring

    • Arduino Uno
    • 16×2 LCD display
    • 10kΩ potentiometer for contrast
    • RS, E and the four data pins D4–D7 to digital pins; RW to GND

    प्रश्न: Arduino के साथ LCD जोड़कर उस पर Hello World दिखाइए।

    Solution — Arduino sketch:

    #include <LiquidCrystal.h>
    
    // RS, E, D4, D5, D6, D7
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    
    void setup() {
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
      lcd.print("Hello World");
    }
    
    void loop() {
      // nothing to repeat
    }

    💡 Exam tip: Remember the order in LiquidCrystal lcd(12, 11, 5, 4, 3, 2): RS, E, D4, D5, D6, D7. If the screen shows only boxes or nothing, turn the 10kΩ contrast potentiometer.

    💡 टिप: LiquidCrystal lcd(12, 11, 5, 4, 3, 2) का क्रम याद रखिए: RS, E, D4, D5, D6, D7। Screen पर सिर्फ़ डिब्बे दिखें या कुछ नहीं, तो contrast वाला potentiometer घुमाइए।

    27. Show the button press count on an LCD

    Question (Source: NIELIT PR-4 practical, set 7)

    Write a program to display the button press count on an LCD. Every time the button is pressed the count should increase by one and the new value should be shown on the display.

    Components and wiring

    • Arduino Uno
    • 16×2 LCD display with a 10kΩ potentiometer for contrast
    • Pushbutton with a 10kΩ pull-down resistor
    • RS, E and D4–D7 to digital pins

    प्रश्न: LCD पर button press की गिनती दिखाइए — हर press पर count एक बढ़े और नया number display पर आए।

    Solution — Arduino sketch:

    #include <LiquidCrystal.h>
    
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    
    const int buttonPin = 7;
    int count = 0;
    int lastButtonState = LOW;
    
    void setup() {
      lcd.begin(16, 2);
      pinMode(buttonPin, INPUT);
      lcd.setCursor(0, 0);
      lcd.print("Press count:");
      lcd.setCursor(0, 1);
      lcd.print(count);
    }
    
    void loop() {
      int buttonState = digitalRead(buttonPin);
    
      if (buttonState == HIGH && lastButtonState == LOW) {
        count++;
        lcd.setCursor(0, 1);
        lcd.print("        ");     // clear the old number
        lcd.setCursor(0, 1);
        lcd.print(count);
        delay(200);
      }
      lastButtonState = buttonState;
    }

    💡 Exam tip: Count only the moment of the press (now HIGH, last time LOW). Before printing the new number, print spaces over the old one — otherwise 10 followed by 9 shows as "90".

    💡 टिप: सिर्फ़ दबाने के पल पर गिनिए (अभी HIGH, पिछली बार LOW)। नया number छापने से पहले पुराने पर spaces छापिए — वरना 10 के बाद 9 "90" दिखेगा।

    28. Scroll “NIELIT HQ” on a 16×2 LCD

    Question (Source: NIELIT PR-4 practical, set 10)

    Write a program to display the scrolling text NIELIT HQ, scrolling from left to right and right to left, on a 16×2 LCD display.

    Components and wiring

    • Arduino Uno
    • 16×2 LCD display
    • 10kΩ potentiometer to adjust the contrast
    • RS to pin 12, EN to pin 11, D4–D7 to pins 5, 4, 3, 2; RW to GND

    प्रश्न: 16×2 LCD पर "NIELIT HQ" text को बाएँ से दाएँ और दाएँ से बाएँ scroll कराइए।

    Solution — Arduino sketch:

    #include <LiquidCrystal.h>
    
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    
    void setup() {
      lcd.begin(16, 2);
      lcd.print("NIELIT HQ");   // 9 characters, starting at column 0
      delay(1000);
    }
    
    void loop() {
      // scroll from left to right: 16 - 9 = 7 steps to the right edge
      for (int i = 0; i < 7; i++) {
        lcd.scrollDisplayRight();
        delay(400);
      }
      delay(500);
    
      // scroll from right to left: 7 steps back to the left edge
      for (int i = 0; i < 7; i++) {
        lcd.scrollDisplayLeft();
        delay(400);
      }
      delay(500);
    }

    💡 Exam tip: Use the built-in lcd.scrollDisplayRight() and lcd.scrollDisplayLeft(). "NIELIT HQ" is 9 characters on a 16-column screen, so 16 − 9 = 7 steps takes it exactly to the edge and back.

    💡 टिप: LCD library के lcd.scrollDisplayRight() और lcd.scrollDisplayLeft() इस्तेमाल कीजिए। "NIELIT HQ" 9 अक्षर का है और screen 16 का, इसलिए 16 − 9 = 7 steps में text ठीक किनारे तक जाकर लौटता है।

    29. Show temperature and humidity from a DHT11 on an LCD

    Question (Source: NIELIT PR-4 practical, set 10)

    Write a program to interface an LCD and a DHT11, displaying the temperature and the humidity on the display.

    Components and wiring

    • Arduino Uno
    • 16×2 LCD display with a 10kΩ potentiometer
    • DHT11 temperature and humidity sensor
    • The DHT data pin to a digital pin; the LCD on RS, E and D4–D7

    प्रश्न: LCD और DHT11 जोड़कर display पर तापमान (temperature) और नमी (humidity) दिखाइए।

    Solution — Arduino sketch:

    #include <LiquidCrystal.h>
    #include <DHT.h>
    
    #define DHTPIN 7
    #define DHTTYPE DHT11
    DHT dht(DHTPIN, DHTTYPE);
    
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    
    void setup() {
      lcd.begin(16, 2);
      dht.begin();
    }
    
    void loop() {
      float temperature = dht.readTemperature();
      float humidity = dht.readHumidity();
    
      lcd.setCursor(0, 0);
      lcd.print("Temp: ");
      lcd.print(temperature);
      lcd.print(" C  ");
    
      lcd.setCursor(0, 1);
      lcd.print("Humidity: ");
      lcd.print(humidity);
      lcd.print("% ");
    
      delay(2000);
    }

    💡 Exam tip: Temperature on row 0 and humidity on row 1 (lcd.setCursor(0, 1)). Print a couple of spaces after each value so a shorter number does not leave old digits behind.

    💡 टिप: Temperature पहली row में और humidity दूसरी row (lcd.setCursor(0, 1)) में। हर value के बाद दो spaces छापिए ताकि छोटा number आने पर पुराने अंक न बचें।

    30. Display the key pressed from a keypad on an LCD

    Question (Source: NIELIT PR-4 practical, set 10)

    Write a program to interface an LCD and a keypad with the Arduino board and display the key pressed from the keypad.

    Components and wiring

    • Arduino Uno
    • 16×2 LCD display with a 10kΩ potentiometer
    • 4×4 matrix keypad — 4 row pins and 4 column pins
    • The keypad rows and columns to eight digital pins

    प्रश्न: Arduino के साथ LCD और keypad जोड़कर दबाई गई key LCD पर दिखाइए।

    Solution — Arduino sketch:

    #include <LiquidCrystal.h>
    #include <Keypad.h>
    
    const byte ROWS = 4;
    const byte COLS = 4;
    
    char keys[ROWS][COLS] = {
      {'1','2','3','A'},
      {'4','5','6','B'},
      {'7','8','9','C'},
      {'*','0','#','D'}
    };
    
    byte rowPins[ROWS] = {9, 8, 7, 6};
    byte colPins[COLS] = {5, 4, 3, 2};
    
    Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
    LiquidCrystal lcd(13, 12, 11, 10, A0, A1);
    
    void setup() {
      lcd.begin(16, 2);
      lcd.print("Press a key:");
    }
    
    void loop() {
      char key = keypad.getKey();
    
      if (key) {
        lcd.setCursor(0, 1);
        lcd.print("Key: ");
        lcd.print(key);
      }
    }

    💡 Exam tip: Write the 4×4 keys map exactly as the keypad looks and use #include <Keypad.h>. getKey() returns 0 when no key is pressed, so print only inside if (key).

    💡 टिप: 4×4 keys map वैसा ही लिखिए जैसा keypad दिखता है, और #include <Keypad.h> लगाइए। कोई key न दबी हो तो getKey() 0 देता है — इसलिए सिर्फ़ if (key) के अंदर छापिए।


    8 Mistakes That Cost Marks in the IoT Practical

    • Seconds instead of milliseconds. delay() takes milliseconds — 2 seconds is delay(2000).

    • No pinMode. Every output pin needs pinMode(pin, OUTPUT) in setup(); without it the LED glows dimly or not at all.

    • Floating button. A button without a pull-down resistor (or INPUT_PULLUP) gives random readings.

    • Sensor on a digital pin. LDR, LM35, soil, water and MQ-135 sensors give a voltage — read them with analogRead() on A0–A5.

    • analogWrite on a non-PWM pin. Fading works only on pins marked ~.

    • Missing library line. LCD needs #include <LiquidCrystal.h>, DHT needs #include <DHT.h>, keypad needs #include <Keypad.h>.

    • Serial baud mismatch. Serial.begin(9600) and the Serial Monitor must both be 9600, or you see garbage.

    • Everything in loop(). Something that should happen once (print a list, write Hello World) goes in setup().

    सबसे ज़्यादा नंबर इनसे कटते हैं: delay में second लिखना, pinMode भूलना, button पर pull-down नहीं, sensor को digital pin पर पढ़ना, non-PWM pin पर analogWrite, library की #include line भूलना, baud rate अलग होना, और एक बार वाला काम loop() में डाल देना।


    PR-4 Viva Questions With Short Answers

    • What is Arduino? An open-source microcontroller board (the Uno uses the ATmega328P) programmed from the Arduino IDE.

    • What do setup() and loop() do? setup() runs once when the board starts; loop() runs again and again after that.

    • Digital vs analog pin? A digital pin reads or writes only HIGH or LOW; an analog pin (A0–A5) reads a voltage as a number from 0 to 1023.

    • What is PWM? Pulse Width Modulation — switching a pin on and off very fast to give an average voltage; analogWrite(pin, 0–255) on ~ pins.

    • What is a pull-down resistor? A resistor (usually 10kΩ) that holds an input pin at LOW when the button is not pressed.

    • What is the Serial Monitor? A window in the Arduino IDE that shows data sent by Serial.print — used to check values and debug.

    • What is a baud rate? The speed of serial communication in bits per second, such as 9600.

    • What does a relay do? It is an electrically operated switch — a small Arduino signal switches a high-voltage load such as a 220 V lamp.

    • How does an ultrasonic sensor measure distance? It sends a sound pulse and times the echo; distance = time × speed of sound ÷ 2.

    • What is an LDR? A Light Dependent Resistor whose resistance falls as light increases.

    • What does LM35 measure? Temperature — its output rises by 10 mV for every 1 °C.

    • What is IoT? The Internet of Things — everyday devices with sensors that collect data and share it over a network.


    Practise PR-4 for Free

    Reading a sketch is step one. Typing it, wiring it and watching it run is what prepares you. Everything below is free:

    Preparing for the M4 theory paper as well?

    Start the Free PR-4 Practical Test


    A Simple 2-Week Plan for the PR-4 Practical

    • Days 1–3 — LED, buzzer, Serial. Programs 1 to 7. Type each sketch yourself in the simulator; change the delay and watch the effect.

    • Days 4–7 — Buttons and relay. Programs 8 to 16. Get the toggle (program 12) working until you can write it without looking.

    • Days 8–11 — Sensors. Programs 17 to 25. For each one, print the raw value first, then add the threshold.

    • Days 12–13 — LCD and keypad. Programs 26 to 30. Learn the LiquidCrystal pin order by heart.

    • Day 14 — Test. The free PR-4 practical test, then five viva answers out loud.

    2 हफ़्ते का plan: पहले 3 दिन LED/buzzer/Serial (1–7), फिर 4 दिन button और relay (8–16) — toggle वाला program बिना देखे लिखने तक, फिर 4 दिन sensors (17–25) — पहले raw value छापिए फिर threshold, फिर 2 दिन LCD और keypad (26–30), और आख़िरी दिन free PR-4 test। रोज़ 5 viva सवाल बोलकर दोहराएँ।


    Learn O Level at Zed-King Institute, Kaithal

    Zed-King Group of Institute is a NIELIT Study Centre — ACCR-O3292 — Ministry of Electronics & IT, Government of India, running in Kaithal since 2006. O Level students do these IoT practicals on real Arduino kits in our lab, with a teacher beside them.

    Course

    Fee

    Duration

    NIELIT O Level (M1–M4 with all practicals)

    ₹20,000

    1 Year

    Visit us at: Kaithal - Pundri - Karnal Rd, near New Bus Stand, opp. Hanuman Vatika, Friends Colony, Kaithal, Haryana 136027. Call +91-9416111612.

    Join O Level Course — NIELIT Study Centre, Kaithal


    Related Reading

    Tags

    #o level iot practical questions#o level pr4 practical#m4-r5.1 practical questions#iot practical questions with solutions#arduino practical programs#o level practical questions#o level m4 practical#o level practical exam 2027#iot viva questions#nielit o level kaithal

    Free for every student

    Practise before the real exam — 100% free

    O Level mock tests (M1–M4 theory and PR-1–PR-4 practical) with instant grading, plus free notes, PDFs and video classes for CCC, O Level and ECC. No fees, no registration.

    FAQ

    Frequently Asked Questions

    5 Questions

    Share this Article

    Follow ZedKing

    Stay updated on all channels

    ZedKing Courses

    Is topic ko depth mein seekhna hai?

    NIELIT & Indian Govt. certified programmes, expert faculty, aur guaranteed career support.

    Ready to Begin Your Career in Technology?

    Join Zed-King Group of Institute — Kaithal's premier Indian Govt. Authorized computer education centre. NIELIT certified since 2006.

    📍 Zed-King Group of Institute, Kaithal, Haryana — 136027

    Drag me!