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);
}
▶ RUN

Output/ Explanation:


Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad