Programming Examples

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


analog and digital sensor both

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

Solution

void setup()
{
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(2, INPUT);
}

void loop()
{
  // Read analog data from the LDR
  int lightValue = analogRead(A0);

  // Read digital data from the IR sensor
  int obstacleStatus = digitalRead(2);

  Serial.print("LDR Analog Value: ");
  Serial.print(lightValue);

  Serial.print(" PIR Sensor: ");

  if (obstacleStatus == LOW)
  {
    Serial.println("Obstacle Detected");
  }
  else
  {
    Serial.println("No Obstacle");
  }

  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