Programming Examples

Arduino program using any one development board (E.g., Arduino or Raspberry Pi) to read data from a sensor


O level July 2025 practical Exam question

Write a program using any one development board (E.g., Arduino or Raspberry Pi) to read data from a sensor. Experiment with both analog and digital sensors.

Solution

#define POT_PIN A0
#define BUTTON_PIN 2

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  int potValue = analogRead(POT_PIN);        // Read analog sensor
  int buttonState = digitalRead(BUTTON_PIN); // Read digital sensor

  Serial.print("Potentiometer Value: ");
  Serial.print(potValue);
  Serial.print(" | Button State: ");
  if (buttonState == HIGH)
    Serial.println("Pressed");
  else
    Serial.println("Not Pressed");

  delay(1000);
}
Output


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad