Tutorial.Calibration History

Show minor edits - Show changes to markup

October 25, 2012, at 11:28 AM by Roberto Guido - minor typo
Changed lines 5-6 from:

This example semonstrates one techinque for calibrating sensor input. The Arduino takes sensor readings for five seconds during the startup, and tracks the highest and lowest values it gets. These sensor readings during the first five seconds of the sketch execution define the minimum and maximum of expected values for the readings taken during the loop.

to:

This example demonstrates one techinque for calibrating sensor input. The Arduino takes sensor readings for five seconds during the startup, and tracks the highest and lowest values it gets. These sensor readings during the first five seconds of the sketch execution define the minimum and maximum of expected values for the readings taken during the loop.

May 02, 2012, at 03:41 AM by Scott Fitzgerald -
Changed line 86 from:
to:
November 16, 2011, at 04:11 AM by Scott Fitzgerald -
Changed line 86 from:
to:
September 30, 2011, at 03:11 AM by Scott Fitzgerald -
Changed line 86 from:
to:
September 24, 2010, at 07:05 AM by Tom Igoe -
Changed line 47 from:
to:
September 24, 2010, at 07:00 AM by Tom Igoe -
Changed line 47 from:
to:
September 24, 2010, at 06:07 AM by Tom Igoe -
Added lines 9-10:
Changed lines 18-19 from:
to:
Added lines 22-23:
Changed lines 34-35 from:
to:
September 24, 2010, at 06:06 AM by Tom Igoe -
Changed lines 75-76 from:
to:
Added lines 79-80:
September 24, 2010, at 06:05 AM by Tom Igoe -
Added lines 69-70:
Deleted lines 77-78:
September 24, 2010, at 06:03 AM by Tom Igoe -
Changed lines 74-75 from:
 Here's the whole program:
to:

Here's the whole program:

September 24, 2010, at 06:02 AM by Tom Igoe -
Changed lines 51-64 from:
  // calibrate during the first five seconds 
  while (millis() < 5000) {
    sensorValue = analogRead(sensorPin);

    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }

    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }
  }
to:
 // calibrate during the first five seconds 
 while (millis() < 5000) {
   sensorValue = analogRead(sensorPin);

   // record the maximum sensor value
   if (sensorValue > sensorMax) {
     sensorMax = sensorValue;
   }

   // record the minimum sensor value
   if (sensorValue < sensorMin) {
     sensorMin = sensorValue;
   }
 }
September 23, 2010, at 10:33 PM by Christian Cerrito -
Changed lines 3-4 from:

Calibration

to:

Calibration

September 23, 2010, at 09:32 PM by Christian Cerrito -
Changed lines 89-90 from:
to:
September 23, 2010, at 09:25 PM by Christian Cerrito -
Changed lines 35-37 from:
to:

September 23, 2010, at 09:24 PM by Christian Cerrito -
Changed lines 35-37 from:
to:
September 23, 2010, at 09:22 PM by Christian Cerrito -
Changed lines 35-37 from:

to:
September 17, 2010, at 06:20 PM by Tom Igoe -
Changed lines 67-68 from:
 This way, any further readings you take can be mapped to the range between this minimum and maximum like so:
to:

This way, any further readings you take can be mapped to the range between this minimum and maximum like so:

Changed lines 74-75 from:
to:
 Here's the whole program:
September 17, 2010, at 06:19 PM by Tom Igoe -
Changed lines 5-6 from:

Demonstrates one techinque for calibrating sensor input. The sensor readings during the first five seconds of the sketch execution define the minimum and maximum of expected values.

to:

This example semonstrates one techinque for calibrating sensor input. The Arduino takes sensor readings for five seconds during the startup, and tracks the highest and lowest values it gets. These sensor readings during the first five seconds of the sketch execution define the minimum and maximum of expected values for the readings taken during the loop.

Added lines 40-75:
September 16, 2010, at 10:08 PM by Tom Igoe -
Changed line 42 from:
to:
August 26, 2010, at 08:40 AM by Christian Cerrito -
Deleted lines 50-51:
August 26, 2010, at 08:39 AM by Christian Cerrito -
Changed lines 49-51 from:
  • [[Reference/while]()
  • [[Reference/millis]()
  • [[Reference/analogRead}()
to:
August 26, 2010, at 08:39 AM by Christian Cerrito -
Changed lines 28-30 from:
to:

Connect an LED to digital pin 9 with a 220 ohm current limiting resistor. Connect a photocell to 5V and then to analog pin 0 with a 10K ohm resistor as a reference to ground.

Changed lines 44-60 from:
to:
August 26, 2010, at 08:28 AM by Christian Cerrito -
Changed lines 7-17 from:
to:

Hardware Required

  • Arduino board
  • (1) LED
  • (1) analog sensor (a photocell will do)
  • (1) 10K ohm resistor
  • (1) 220 ohm resistor
  • breadboard
  • hook-up wire

August 24, 2010, at 08:19 AM by Christian Cerrito -
Changed line 30 from:
to:
February 23, 2010, at 07:57 PM by Tom Igoe -
Changed lines 30-54 from:
 /*
   Calibration
  
  Demonstrates one techinque for calibrating sensor input.  The
  sensor readings during the first five seconds of the sketch
  execution define the minimum and maximum of expected values
  attached to the sensor pin.
  
  The sensor minumum and maximum initial values may seem backwards.
  Initially, you set the minimum high and listen for anything 
  lower, saving it as the new minumum. Likewise, you set the
  maximum low and listen for anything higher as the new maximum.
  
  The circuit:
  * Analog sensor (potentiometer will do) attached to analog input 0
  * LED attached from digital pin 9 to ground
  
  created 29 Oct 2008
  By David A Mellis
  Modified 17 Jun 2009
  By Tom Igoe
  
  http://arduino.cc/en/Tutorial/Calibration
  
  */
to:
Deleted lines 31-78:
 // These constants won't change:
 const int sensorPin = 2;     // pin that the sensor is attached to
 const int ledPin = 9;        // pin that the LED is attached to

 // variables:
 int sensorValue = 0;         // the sensor value
 int sensorMin = 1023;  // minimum sensor value
 int sensorMax = 0;     // maximum sensor value

 void setup() {
   // turn on LED to signal the start of the calibration period:
   pinMode(13, OUTPUT);
   digitalWrite(13, HIGH);

   // calibrate during the first five seconds 
   while (millis() < 5000) {
     sensorValue = analogRead(sensorPin);

     // record the maximum sensor value
     if (sensorValue > sensorMax) {
       sensorMax = sensorValue;
     }

     // record the minimum sensor value
     if (sensorValue < sensorMin) {
       sensorMin = sensorValue;
     }
   }

   // signal the end of the calibration period
   digitalWrite(13, LOW);
 }

 void loop() {
   // read the sensor:
   sensorValue = analogRead(sensorPin);

   // apply the calibration to the sensor reading
   sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

   // in case the sensor value is outside the range seen during calibration
   sensorValue = constrain(sensorValue, 0, 255);

   // fade the LED using the calibrated value:
   analogWrite(ledPin, sensorValue);
 }
August 27, 2009, at 08:46 PM by Tom Igoe -
Added lines 16-18:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

July 05, 2009, at 07:20 PM by Tom Igoe -
Changed lines 23-27 from:

Code

[@ /*

  Calibration
to:
Changed lines 53-56 from:
 Demonstrates one techinque for calibrating sensor input.  The
 sensor readings during the first five seconds of the sketch
 execution define the minimum and maximum of expected values
 attached to the sensor pin.
to:
 // These constants won't change:
 const int sensorPin = 2;     // pin that the sensor is attached to
 const int ledPin = 9;        // pin that the LED is attached to
Changed lines 57-60 from:
 The sensor minumum and maximum initial values may seem backwards.
 Initially, you set the minimum high and listen for anything 
 lower, saving it as the new minumum. Likewise, you set the
 maximum low and listen for anything higher as the new maximum.
to:
 // variables:
 int sensorValue = 0;         // the sensor value
 int sensorMin = 1023;  // minimum sensor value
 int sensorMax = 0;     // maximum sensor value
Deleted lines 61-63:
 The circuit:
 * Analog sensor (potentiometer will do) attached to analog input 0
 * LED attached from digital pin 9 to ground
Changed lines 63-66 from:
 created 29 Oct 2008
 By David A Mellis
 Modified 17 Jun 2009
 By Tom Igoe
to:
 void setup() {
   // turn on LED to signal the start of the calibration period:
   pinMode(13, OUTPUT);
   digitalWrite(13, HIGH);
Changed lines 68-70 from:
 http://arduino.cc/en/Tutorial/Calibration
to:
   // calibrate during the first five seconds 
   while (millis() < 5000) {
     sensorValue = analogRead(sensorPin);
Changed lines 72-124 from:
 */

// These constants won't change: const int sensorPin = 2; // pin that the sensor is attached to const int ledPin = 9; // pin that the LED is attached to

// variables: int sensorMin = 1023; // minimum sensor value int sensorMax = 0; // maximum sensor value

int sensorValue = 0; // the sensor value

void setup() {

  // turn on LED to signal the start of the calibration period:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // calibrate during the first five seconds 
  while (millis() < 5000) {
    sensorValue = analogRead(sensorPin);

    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }

    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }
  }

  // signal the end of the calibration period
  digitalWrite(13, LOW);

}

void loop() {

  // read the sensor:
  sensorValue = analogRead(sensorPin);

  // apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  sensorValue = constrain(sensorValue, 0, 255);

  // fade the LED using the calibrated value:
  analogWrite(ledPin, sensorValue);

} @]

to:
June 30, 2009, at 02:06 PM by Paul Badger -
Added lines 56-57:

// variables:

Deleted line 60:

// variables:

June 30, 2009, at 02:05 PM by Paul Badger -
Changed lines 56-58 from:

const int sensorMin = 1023; // minimum sensor value const int sensorMax = 0; // maximum sensor value

to:

int sensorMin = 1023; // minimum sensor value int sensorMax = 0; // maximum sensor value

June 25, 2009, at 11:47 PM by Tom Igoe -
Changed lines 14-15 from:
to:
Changed lines 20-22 from:

to:

June 25, 2009, at 11:35 PM by Tom Igoe -
Changed lines 7-8 from:

Circuit

to:

Circuit

Added lines 12-22:

click the image to enlarge

Schematic

click the image to enlarge

June 17, 2009, at 11:26 PM by Tom Igoe -
Changed lines 14-19 from:

int sensorPin = 2; int ledPin = 9;

int val = 0; int sensorMin = 1023, sensorMax = 0;

to:

/*

  Calibration

 Demonstrates one techinque for calibrating sensor input.  The
 sensor readings during the first five seconds of the sketch
 execution define the minimum and maximum of expected values
 attached to the sensor pin.

 The sensor minumum and maximum initial values may seem backwards.
 Initially, you set the minimum high and listen for anything 
 lower, saving it as the new minumum. Likewise, you set the
 maximum low and listen for anything higher as the new maximum.

 The circuit:
 * Analog sensor (potentiometer will do) attached to analog input 0
 * LED attached from digital pin 9 to ground

 created 29 Oct 2008
 By David A Mellis
 Modified 17 Jun 2009
 By Tom Igoe

 http://arduino.cc/en/Tutorial/Calibration

 */

// These constants won't change: const int sensorPin = 2; // pin that the sensor is attached to const int ledPin = 9; // pin that the LED is attached to

const int sensorMin = 1023; // minimum sensor value const int sensorMax = 0; // maximum sensor value

// variables: int sensorValue = 0; // the sensor value

Changed line 53 from:
  // signal the start of the calibration period
to:
  // turn on LED to signal the start of the calibration period:
Changed line 56 from:
to:
Changed lines 59-60 from:
    val = analogRead(sensorPin);
to:
    sensorValue = analogRead(sensorPin);
Changed lines 62-63 from:
    if (val > sensorMax) {
      sensorMax = val;
to:
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
Changed line 65 from:
to:
Changed lines 67-68 from:
    if (val < sensorMin) {
      sensorMin = val;
to:
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
Changed line 71 from:
to:
Changed lines 77-78 from:
  val = analogRead(sensorPin);
to:
  // read the sensor:
  sensorValue = analogRead(sensorPin);
Changed lines 81-82 from:
  val = map(val, sensorMin, sensorMax, 0, 255);
to:
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
Changed lines 84-86 from:
  val = constrain(val, 0, 255);

  analogWrite(ledPin, val);
to:
  sensorValue = constrain(sensorValue, 0, 255);

  // fade the LED using the calibrated value:
  analogWrite(ledPin, sensorValue);
October 29, 2008, at 10:29 PM by David A. Mellis -
Changed lines 1-2 from:

Examples > Analog

to:

Examples > Analog I/O

October 29, 2008, at 10:28 PM by David A. Mellis -
Added lines 1-55:

Examples > Analog

Calibration

Demonstrates one techinque for calibrating sensor input. The sensor readings during the first five seconds of the sketch execution define the minimum and maximum of expected values.

Circuit

Analog sensor (e.g. potentiometer, light sensor) on analog input 2. LED on digital pin 9.

Code

int sensorPin = 2;
int ledPin = 9;

int val = 0;
int sensorMin = 1023, sensorMax = 0;

void setup() {
  // signal the start of the calibration period
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // calibrate during the first five seconds 
  while (millis() < 5000) {
    val = analogRead(sensorPin);

    // record the maximum sensor value
    if (val > sensorMax) {
      sensorMax = val;
    }

    // record the minimum sensor value
    if (val < sensorMin) {
      sensorMin = val;
    }
  }

  // signal the end of the calibration period
  digitalWrite(13, LOW);
}

void loop() {
  val = analogRead(sensorPin);

  // apply the calibration to the sensor reading
  val = map(val, sensorMin, sensorMax, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  val = constrain(val, 0, 255);

  analogWrite(ledPin, val);
}

Share