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