A little curiosity. A whole lot of making.Robotics, CNC & connected ideas
robodatech.
Arduino sample library

Analog Sensor Read 22

Sample potentiometers, light sensors, thermistors, and analog robot signals.

Open in compiler →
/*
  Roboda verified Arduino sample 0528
  Feature: Analog Sensor Read
  Generated for online build, classroom practice, and hardware upload testing.
*/

const byte sensorPin = A3;
const int threshold = 610;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  int value = analogRead(sensorPin);
  digitalWrite(13, value > threshold ? HIGH : LOW);
  Serial.print("analog=");
  Serial.println(value);
  delay(395);
}

How it works

Read a variable analog voltage and compare it with a threshold.

  1. Connect the sensor output to the listed analog pin.
  2. Connect sensor VCC and GND to the board.
  3. Open Serial Monitor to see raw 0-1023 values on AVR boards.
  4. Adjust threshold for your sensor range.

Connections

PinConnect toNote
A3Potentiometer wiper, LDR divider, thermistor divider, or analog sensor outputUse the same board ground as the sensor.
D13Built-in LEDTurns on when the analog value crosses the threshold.

Good ideas start here.

Robotics lessons, build notes and useful updates. Subscribe by entering your email.