Arduino and analog sensors:Proximity, Light, Force and Tilt detectors

In this article we’ll see how to retrieve data from 4 cool electronic sensors often used in domotica and robotica projects: Infrared Proximity Sensor, Force Resistive Resistor (FSR), Light Photo Detector (LDR), tilt Sharp (inclination).

To see them in action the returned values will be mapped to update a LED luminosity (using PWM – Pulse-Width Modulation). I have provided Arduino sketch files (written in C), breadboard connection pictures and a demo video for each sensor.

Following a video demo for each sensor (I’m sorry for the video quality : )

1) Infrated Proximity Sensor

2) Force Resistive Resistor (FSR)

3) Light Photo Detector (LDR)

4) tilt Sharp (inclination)

To accomplish these tests I used following electronic components:
- Arduino Duemilanova Microcontroller
- A mini breadboard
- an RGB Led with only 1 color pin connected to Arduino digital pin 9, using a 200ohm resistor
- various sensors connected to Arduino analog pin 2, using a a 10k ohm resistor

Following the arduino / breadboard wire images, for both sensor types, 2 and 3 connectors, that can be reused for other similar components.

forcesensitiveresistor2

infraredproximity

Arduino sketch:

/*
  Analog input, serial output
 
 Reads an analog input pin, prints the results to the serial monitor and
 modify the LED luminosity mapping the returned values from 0 to 255 (using PWM)
 
*/
 
 
int ledPin =  9;            // LED connected to digital pin 9
int sensorPin = 2;        // value read from the sensor
int outputValue = 0;        // value output to the PWM (analog out)
 
 
void setup() {
  Serial.begin(9600);
}
 
 void loop() {
 
   // read the analog input
   int analogValue = analogRead(sensorPin);
 
   // NOTE: you should modify following script in according with your project goals, resistors and used sensors.
 
 
   // Sensors return values from 0 until 1023 but I mapped them from 250 to 900 to get a better visual result.
   // The map() method will return us a value from 0 to 255, good PWM values to turn on my LED
   outputValue = map(analogValue, 250, 900, 0, 255);
 
 
   // Some sensors, when their value is near to zero, return a variable value between 2 and 3, creating a loop
   // that could generate bad visual effects. To avoid this issue I always turn off the LEd when sensor value is < 5
   if (outputValue<5)
     analogWrite(ledPin, 0);
    else
     analogWrite(ledPin, outputValue);
 
 
 
   // print the result to the serial monitor
   Serial.print(analogValue);
   Serial.print(" : ");
   Serial.print(outputValue);
   Serial.println("----");
 
 
 
   // wait 10 milliseconds for the analog-to-digital converter
   delay(10);
 }

Comments (2)

  1. GSX-R600 gurl (reply)

    July 22, 2010 at 10:53 am

    Great information, I just bookmarked you.

    Sent from my iPad 4G

  2. Henry (reply)

    August 22, 2012 at 9:22 am

    what type of Infrared Proximity Sensor, Force Resistive Resistor (FSR) did u use? Hope to get them

Leave a Reply

Your email address will not be published. Required fields are marked *

Published on: 11 November 2009
Posted by:
Discussion: 2 Comments