Book Image

Arduino Essentials

Book Image

Arduino Essentials

Overview of this book

Table of Contents (17 chapters)
Arduino Essentials
About the Author
About the Reviewer

Calibrating sensors serially

In Chapter 6, Analog Inputs to Feel between All and Nothing, I promised you that I'd show you how we can use a serial communication to calibrate the analog sensors you could connect to your projects, in particular in the ambient light meter and the motor speed control projects.

The time has now come to revisit these projects and finally unveil how we got the correct output range for the mapping we made in these projects.

If you remember, we used the following circuit for the ambient light meter as shown in the following image:

Ambient light meter circuit schematic

In the sketch, we had to read the photocell value and map it to a four-state output range with the following lines of code:

void loop(){
  // Read the sensor and convert the value to
  // one of the four states we will use
  value = analogRead(photocell);
  state = map(value,0, 200, 1, 4);
  // acts depending on the obtained states
      case 1:

At that time, I didn't tell you how I...