Sunday, February 15, 2015

#8 - Sensors, Sensors, Sensors: Arduino Interfacing With Sonar and Infrared Sensors

Sensors and Arduino

Now that we've become more familiarized with programming the Arduino and an assortment of input/output devices, we can delve into more complex sensors and interfacing, and will even be able to build our own sensors to assist us with our robot in the future.

The Ultrasonic Sensor

In this lab, we will be working with the HC-SR04 ultrasonic range finder module. In other words, we will be working with a type of Sonar sensor, and will be using it to detect objects, or, in the case of our VEX robot, we will use it to avoid contact with walls and other objects in a future competition. Aside from this particular use, there are also many things that sensors such as this one can be used for, such as: parking sensors, motion/tracking devices, and more. This module has four pins: a power pin (Vcc +5V), a "trigger" pin, an "echo" pin, and a grounding pin. The power pin and ground pin are used for supplying power to the module (remember to observe correct polarity when connecting them); while the trigger and echo pins both act as signaling pins. The Trigger pin works by emitting a 10 microsecond long pulse, this way the transmitter knows when to begin sending out eight 40kHz pulses, which will be used to calculate the distance of whatever object rebounds the signal. In other words, the Trigger pin is what sends out the sonar frequency signal, waits for it to hit an object and return, and then calculates the distances based off of that. The Echo pin will then output a Pulse-Width Modulation wave that is proportional in ON/HIGH time to the distance traveled. So now, let's try getting this to work!

Some new commands here are the "return" commands, which tells the arduino to return a value whenever it runs a specific loop. Use this to return a value in the serial monitor based off of the distance measured by the sonar sensor. 
The Ultrasonic Sensor (sonar) setup on the breadboard.


Here, we see the sonar sensor detecting my hand. Whenever I move my hand within a certain distance of the sensor, the LED will turn on, and a message in the serial monitor displayed, saying that my hand was "Too Close" to the sensor.

Infrared Sensors

Other types of sensors include the Flame Sensor and the Line Follower. These are both very similar, especially in construction, as they both use a component called the phototransistor. A phototransistor works very similarly to the regular transistors. However, the longer lead no longer represents the positive end, but rather represents the negative end now. In addition, this transistor has only 2 pins, as the Base signal will be determined by the lighting of the room (hence the prefix 'photo'). 

The Flame Sensor

The flame sensor is a very simple utilization of the phototransistor. It only requires one phototransistor in series with a resistor (don't forget the correct polarity!), and has the signal pin in-between those two components. The circuit will work as a flame sensor, as it will give Voltage values at the signal pin based off of how close a flame (or any other light of similar wavelength). We will create one to locate a flame for the Firefighting Competition. 
A simple flame sensor.

The Infrared Sensor as a Line Follower

Another simple sensor is the Line Follower. It is very similar in construction to the flame detector, except now we must use an infrared (IR) emitter along with the phototransistor. We must keep the two close together, as the sensor works by having the IR emitter emit pulses of infrared light that will bounce off of an object. The light that bounces back from the object will have refracted/changed (as some light will not be rebounded), and as such, there will be various values for the phototransistor to receive, all based off of the color the object was. By using this theory of operation and adjusting the limitations of values in our programming, we can set the sensor to follow a black line, or to perform specific functions once it reaches the black line.
The Line Follower Prototype.

No comments:

Post a Comment