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.

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.
Solutionvoid 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: 