Example Code for Arduino-Read Slide Value

Last revision 2026/01/15

This article demonstrates how to read slide values with Arduino using analog sensors, providing detailed example code and wiring diagrams to facilitate implementation.

Hardware Preparation

  • Product name: Rotation Sensor v1/v2 or Analog Slide Position Sensor
  • Product SKU : DFR0054/DFR0058/DFR0053
  • Version : 1.0

Wiring Diagram

Analog sensor connection diagram

Other Preparation Work

Signal output pin -> Analog pin 0

Sample Code


// # Editor     : Lauren from DFRobot
// # Date       : 30.12.2011

// #
// # Editor     : Lauren from DFRobot
// # Date       : 17.01.2012

// # Product name: Rotation Sensor v1/v2 or Analog Slide Position Sensor
// # Product SKU : DFR0054/DFR0058/DFR0053
// # Version     : 1.0

// # Description:
// # the sample to drive some analog sensors

// # Connection:
// #        Signal output pin  -> Analog pin 0
// #


void setup()
{
  Serial.begin(9600);     //Set serial baud rate to 9600 bps
}
void loop()
{
  int val;
  val=analogRead(0);      //Read slider value from analog 0
  Serial.println(val,DEC);//Print the value to serial port
  delay(100);
}

Result

The value read from the slider will be printed to the serial port.

Was this article helpful?

TOP