|
» About me
» Bristol VA/TN
» E-Mail
» Hobby Electronics » PICAXE Microcontroller » Arduino Microcontroller » Microcontroller Input/Output Ports
Using Hall Effect Sensors with the Arduino-ATMEGA168by Lewis Loflin In the You Tube video above I demonstrated the use of a ratiometric Hall sensor with an Arduino-Atmega168 connected to a liquid crystal display. This page will show how to connect Hall sensors to the Arduino. See the two previous pages on Hall sensors the video covered:
Pictured above is a Hall effect switch connected to a light emitting diode. (LED) In the off condition TP2 will be "HIGH" or 5 volts measured relative to ground. The LED will be off. When switched on by a magnet TP2 will measure about .5 volts and the LED will be on. This can be directly connected to the input port of a micro-controller or other 5-volt digital logic.
We can use the above circuit to read the output from the sensor. The voltage reading will give us an idea of the polarity and strength of a magnet. Instead of a voltmeter, we use Arduino. In this case I'll be using a 5-volt UGN3502 and not 12-volts, which will damage the controller. A ratiometric Hall effect sensor outputs an analog voltage proportional to the magnetic field intensity. With no magnetic field applied the output is about one-half the supply voltage. The voltage will increase with the south magnetic pole on the face or decrease with the north magnetic pole on the face. The range is from about 1 to 4 volts.
Here is a direct application. A calibrated linear Hall device in this example will measure the current through the wire. The higher the current the stronger the magnetic field and thus a higher output voltage. We could sound an alarm with excessive or low current, etc. About the ProgramAn analog to digital converter (ADC) in the ATMEGA168 or ATMEGA328 are 10-bit (1024 steps) and over a range at 5 volts is 5.0/1024 = 4.882 mV per step. Here we simply measure the output voltage from the sensor and display that voltage. It's simply a modified version of my TMP37 program and uses the exact same schematic. See Using the TMP37Temperature Sensor with Arduino
/*
Demonstrates the use a 16x2 LCD display
The ratiometric Hall sensor I'm using is the UGN3503
and is connected to analog pin 0 (AD0)
Note the schematic below.
*/
// include the library code:
#include "LiquidCrystal.h"
float refVoltage = 5.0 / 1024; // volts per step on ADC
float sensorVolts;
int val;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2); // 16 char by 2 lines
lcd.noCursor(); // Hides the LCD cursor.
}
void loop() {
// read AD0
val = analogRead(0);
sensorVolts = refVoltage * val;
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
lcd.print("Hall Volts =");
lcd.setCursor(0, 1);
lcd.print(sensorVolts);
delay(500); // 500 mSec
} // end loop
To purchase Hall sensors or explore the many varied types of sensors see www.allegromicro.com. If one wants a kit of parts to perform the above experiments contact me at lewis@bvunet.net for information. Added January 2012: PICAXE Micro-controller Projects!The PICAXE series of micro-controllers rank as the easiest and most cost effective way to use Microchip processors. I wanted an easier and less expensive way to introduce my students to the "PIC" micro-controller. Here I hope to get those starting out past poorly written literature and lack of simple working code examples.
The next groups of links below go to specific electronic/electrical devices on how to use and test them.
If using this material on another site, please provide a link back to my site. |