Example Code for Arduino-Digital Signal Reading

Last revision 2026/01/07

This article offers a detailed guide on reading digital signals with Arduino, covering hardware and software preparation, wiring diagrams, and example code for effective signal processing.

Software Preparation

Arduino software. For more details, please check the official PinMode function description.

Wiring Diagram

Adjustable Infrared Sensor Switch Dia

  • RED--->VCC
  • YELLOW-->Signal
  • GREY-->GND

Other Preparation Work

For making the sensor working more stable with your arduino processor, we use an external resistor(range from 1K to 10K) for pull-up!

However, it's also available to connect the signal pin directly to the Arduino digital pin for testing. Just take care of the pin mode initialization in your Arduino software. Set the "INPUT_PULLUP" mode for the digital detection. For more details, please check the official PinMode function description.

Sample Code

void setup()
{
 pinMode(3,INPUT);
 Serial.begin(9600);
}
void loop()
{
  int val=digitalRead(3);
  Serial.println(val);
  delay(500);
}

Was this article helpful?

TOP