Home » Arduino, _Favourites

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

11 November 2009 One Comment

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);
 }

One Comment »

  • GSX-R600 gurl said:

    Great information, I just bookmarked you.

    Sent from my iPad 4G

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.