Docsity

Sensors, Study notes of Embedded Systems

Toggle sidebar
bg1
The ultimate goal when a robot is built is to be optimized and to be
compliant with all specifications. To meet the requirements
sometimes you can spend many hours just to sort and identify the
sensors that would be the best for an application like detecting and
tracking an object. In this article, we explore all sensor types that
can be used for target detection and tracking as well as features
and the types of applications where they can be used.
Selecting the right sensor is not a strict process. This is about eliminating all
the wrong choices based on a series of question aiming to eliminate first the
technology that underlying the sensor and then the product that it doesn’t fit
to the robot requirements.
When we use the word target, we refer in the same time at a small ball, at an
object like a chair, or even at a human that stay in front of the robot.
To select the best sensor from a variety of products and manufacturers is a
hard work especially when you’re a beginner and try to build a simple robot.
In few words the sensor has to be selected in concordance with your targets
size, shape and range. All of these three features have to be on the same
line with the specification of the robot. But even so, it is hard to define the
best sensor since the performance and precision of this depend on many
factors.
Principle of an active sonar (photo source wikipedia.org)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Sensors and more Study notes Embedded Systems in PDF only on Docsity!

The ultimate goal when a robot is built is to be optimized and to be

compliant with all specifications. To meet the requirements

sometimes you can spend many hours just to sort and identify the

sensors that would be the best for an application like detecting and

tracking an object. In this article, we explore all sensor types that

can be used for target detection and tracking as well as features

and the types of applications where they can be used.

Selecting the right sensor is not a strict process. This is about eliminating all

the wrong choices based on a series of question aiming to eliminate first the

technology that underlying the sensor and then the product that it doesn’t fit

to the robot requirements.

When we use the word target, we refer in the same time at a small ball, at an

object like a chair, or even at a human that stay in front of the robot.

To select the best sensor from a variety of products and manufacturers is a

hard work especially when you’re a beginner and try to build a simple robot.

In few words the sensor has to be selected in concordance with your targets

size, shape and range. All of these three features have to be on the same

line with the specification of the robot. But even so, it is hard to define the

best sensor since the performance and precision of this depend on many

factors.

Principle of an active sonar (photo source wikipedia.org)

A sensor is a sophisticated device that measures a physical quantity like

speed or pressure and converts it into a signal that can be measured

electrically. Sensors are based on several working principals and types of

measurements. In our case almost all types of sensors emit signals and

measure the reflection to make measurements.

There are many sensors that can be used for a simple application like line

following (IR LED and a Photodiode, LED and LDR, etc.), but this is a simple

case when a simple sensor can be selected. A complicated case is when you

have to track an object and the budget is limited to purchase a mini

computer like Raspberry Pi. In this case it can be used an ultrasonic sensor to

scan from side to side till the sensor detect a drop in distance (at this stage it

detects the edge of the object and from now on the sensor see only the

background). The scanning process continues back to the point where the

object is with left and right scanning.

This is one of the cases when expensive products can be replaced with cheap

sensors.

In the following, you can explore the features of sensors that can be used for

detecting and tracking a target.

Criteria to choose the right sensor

With so many models available on the market from various vendors would be

very useful to know from where you can start. A good starting point is to

know certain features, and some of them are given below:

  • Type of Sensor – the presence of an object can be detected with

proximity sensors, and there are several kinds of sensor technologies

including here ultrasonic sensors, capacitive, photoelectric, inductive,

or magnetic. Tracking objects can works using proximity sensors (ex. :

ultrasonic sensors), or for advanced applications generally it is used

image sensors (ex.: webcams) and vision software like OpenCV;

  • Accuracy – the accuracy is very important in detecting and tracking

objects, and it is useful to choose sensors with accuracy values

between desired measurement margins;

  • Resolution – a high resolution can detect smallest changes in the

position of the target;

  • Range – involves choosing the sensors based on measurement limits

and compared with the desired detection range of the robot;

Color sensor

Different colors are reflected with different intensity, for example the orange

color reflects red light in an amount greater than the green color, and this is

the color sensor. This simple sensor is in the same range with light sensor,

but with a few extra features that can be useful for applications where the

robot has to detect the presence of an object with a certain color, or to

detect the types of objects or the surfaces.

Touch sensor

The touch sensor can be included in the proximity sensors category and are

designed to sense objects at a small distance with or without direct contact.

This sensor is designed to detect the changes in the capacitance between

the on-board electrodes and the object making contact.

Ultrasonic sensor

These sensors are designed to generate high frequency sound waves and

receive the echo reflected by the target. These sensors are used in a wide

range of applications and are very useful when it is not important the

detection of colors, surface texture, or transparency.

Advantages of Ultrasonic sensors

  • the output value is linear with the distance between the sensor and

the target;

  • sensor response is not dependent on the colors, transparency of

objects, optical reflection properties, or by the surface texture of the

object;

  • these sensors are designed for contact-free detection;
  • sensors with digital (ON/OFF) outputs have excellent repeat sensing

accuracy;

  • accurate detection even of small objects;
  • ultrasonic sensors can work in critical conditions such as dirt and

dust;

  • they are available in cuboid or cylinder forms, which is better for a

freedom design;

Disadvantages of Ultrasonic sensors

  • ultrasonic sensors must view a high density surface for good results.

A soft surface like foam and cloth has low density and absorb the

sound waves emitted by the sensor;

  • could have false responds for some loud noises such as air hoses;
  • the ultrasonic sensors have a response time with a fraction less than

other types of sensors;

  • an ultrasonic sensor has a minimum sensing distance, which should

be taken into consideration when you choose the sensor;

  • some changes in the environment can affect the response of the

sensor (temperature, humidity, pressure, etc.);

Infrared sensor

An infrared sensor measure the IR light that is transmitted in the

environment to find objects by an IR LED. This type of sensor is very popular

in navigation for object avoidance, distance measured or line following

applications. This sensor is very sensitive to IR lights and sunlight, and this is

the main reason that an IR sensor is used with great precision in spaces with

low light.

Advantages of Ultrasonic sensors

  • infrared sensors can detect infrared light over a large area;
  • they can operate in real-time;
  • the IR sensor uses non-visible light for detection;
  • they are cheap sensors;

Disadvantages of Ultrasonic sensors

  • this sensor is very sensitive to IR lights and sunlight;
  • it has a weakness to darker colors such as black;

Using an Ultrasonic Sensor (HC-SR04) with a Tiva C

Series micro-controller and Energia

This guide will provide you with everything needed to connect an Ultrasonic Sensor (HC-SR04) to your Tiva C Series based micro-controller. In essence, this guide will work for most 3.3v based controller’s

such as a 3.3v based Arduino and compatible boards as the Energia development platform is based off of the Arduino IDE.

What is an Ultrasonic HC-SR04 Distance Sensor Module?

It is a relatively cheap sensor to measure distance between itself and another object by sending an ultrasonic pulse and listening for an echo response. This sensor can be connected to many devices that provide 5v or 3.3v logic. As I will be using a 3.3v logic micro-controller for this demonstration, a 1K resistor will be required in order to not damage the GPIO on the micro-controller. You can purchase these HC-SR04 Sensor’s from SainSmart, they offer pretty decent prices as well as quick shipping.

Connecting everything up

There are four pins on the sensor, and they are fairly straight forward to connect. VCC requires a 5v signal, which in my case is coming from the VBUS pin on the Tiva C Series. If you were using the Arduino, you simply connect to the +5v pin. The GND pin goes to any common ground pin’s on your micro-controller, and the pins “TRIG” and “ECHO” will be connected to any available GPIO pins on your micro-controller. Keep in mind, when using a 3.3v logic controller you will be required to use a 1K resistor between the “ECHO” pin and your GPIO pin on the micro-controller as it by default will send 5v and we need to regulate this.

Energia Based C Library for the HC-SR04 Sensor

As I am using a Tiva C Series and like the Arduino IDE, I have adapted to using Energia IDE as it brings the Arduino way of coding to the Tiva. As I am new programmer, I have decided to attempt to write my first C++ library for this sensor. You can download this class library from GitHUB here. Installation is very straight forward and there is an example included to get you up and running quickly

Using an FSR

For this example I'm showing it with a 5V supply but note that you can use this with a

3.3v supply just as easily. In this configuration the analog voltage reading ranges from

0V (ground) to about 5V (or about the same as the power supply voltage).

The way this works is that as the resistance of the FSR decreases, the total resistance of

the FSR and the pulldown resistor decreases from about 100Kohm to 10Kohm. That

means that the current flowing through both resistors increases which in turn causes the

voltage across the fixed 10K resistor to increase. Its quite a trick!

Force

(lb)

Force

(N)

FSR

Resistance

(FSR + R)

ohm

Current thru FSR

+R

Voltage across R

None None Infinite Infinite! 0 mA 0V

0.04 lb 0.2 N 30 Kohm 40 Kohm 0.13 mA 1.3 V

0.22 lb 1 N 6 Kohm 16 Kohm 0.31 mA 3.1 V

2.2 lb 10 N 1 Kohm 11 Kohm 0.45 mA 4.5 V

22 lb 100 N 250 ohm 10.25 Kohm 0.49 mA 4.9 V

This table indicates the approximate analog voltage based on the sensor force/

resistance w/a 5V supply and 10K pulldown resistor.

Note that our method takes the somewhat linear resistivity but does not provide linear

voltage! That's because the voltage equasion is:

Vo = Vcc ( R / (R + FSR) )

That is, the voltage is proportional to the inverse of the FSR resistance.

Simple Demonstration of Use

Wire the FSR as same as the above example, but this time lets add an LED to pin 11.

Simple Code for Analog FSR Measurements

Here is a code example for measuring the FSR on an analog pin.

This code doesn't do any calculations, it just prints out what it interprets as the amount

of pressure in a qualitative manner. For most projects, this is pretty much all thats

needed!

1.1. /* FSR simple testing sketch. 1.2. 1.3. Connect one end of FSR to power, the other end to Analog 0. 1.4. Then connect one end of a 10K resistor from Analog 0 to ground 1.5. 1.6. For more information see www.ladyada.net/learn/sensors/fsr.html */ 1.7. 1.8. int fsrPin = 0; // the FSR and 10K pulldown are connected to a 1.9. int fsrReading; // the analog reading from the FSR resistor divider 1.10. 1.11. void setup(void) { 1.12. // We'll send debugging information via the Serial monitor 1.13. Serial.begin(9600); 1.14. } 1.15. 1.16. void loop(void) { 1.17. fsrReading = analogRead(fsrPin); 1.18. 1.19. Serial.print("Analog reading = "); 1.20. Serial.print(fsrReading); // the raw analog reading 1.21.

1.1. /* FSR testing sketch. 1.2. 1.3. Connect one end of FSR to power, the other end to Analog 0. 1.4. Then connect one end of a 10K resistor from Analog 0 to ground 1.5. 1.6. For more information see www.ladyada.net/learn/sensors/fsr.html */ 1.7. 1.8. int fsrPin = 0; // the FSR and 10K pulldown are connected to a

1.43. Serial.println(fsrConductance); 1.44. 1.45. // Use the two FSR guide graphs to approximate the force 1.46. if (fsrConductance <= 1000) { 1.47. fsrForce = fsrConductance / 80; 1.48. Serial.print("Force in Newtons: "); 1.49. Serial.println(fsrForce); 1.50. } else { 1.51. fsrForce = fsrConductance - 1000; 1.52. fsrForce /= 30; 1.53. Serial.print("Force in Newtons: "); 1.54. Serial.println(fsrForce); 1.55. } 1.56. } 1.57. Serial.println("--------------------"); 1.58. delay(1000); 1.59. (^) }

BONUS! Reading FSR Measurements Without Analog Pins.

Because FSR's are basically resistors, its possible to use them even if you don't have

any analog pins on your microcontroller (or if say you want to connect more than you

have analog input pins. The way we do this is by taking advantage of a basic electronic

property of resistors and capacitors. It turns out that if you take a capacitor that is

initially storing no voltage, and then connect it to power through a resistor, it will charge

up to the power voltage slowly. The bigger the resistor, the slower it is.

This capture from an oscilloscope shows whats happening on the digital pin (yellow).

The blue line indicates when the sketch starts counting and when the couting is

complete, about 1.2ms later.

This is because the capacitor acts like a bucket and the resistor is like a thin pipe. To fill

a bucket up with a very thin pipe takes enough time that you can figure out how wide

the pipe is by timing how long it takes to fill the bucket up halfway.