Arduino en español
Circuitos con Arduino - Juan Antonio Villalpando
-- Tutorial de iniciación a Arduino --
Volver al índice del tutorial
____________________________
44C.- Interruptor de efecto Hall. Tacómetro. Sensor analógico Hall. 3144E. A1302.
- Efecto Hall: un cuerpo por el que circula una corriente eléctrica y que se encuentra en el interior de un campo magnético, crea un campo eléctrico (proporcional al magnetismo) en su interior.
- Si tenemos un sensor Hall y le aproximamos un imán, creará una tensión eléctrica.
- Vamos a ver dos tipo:
1.- Módulo con el sensor A3144E, es un sensor digital.
2.- Sensor 1302, es un sensor analógico.
________________________________________________________
- Módulo con el sensor 3144E. Digital.
- El sensor 3144E es un sensor Hall Digital, no es analógico.
1. Funciona de 3,3 a 5 V
2.-
Cuando detecta campo magnético, su salida digital se pone a BAJO y se enciede un LED. Si no hay campo magnético, su salida es ALTA y el LED está apagado.
3.- Este módulo aunque tiene marcada una salida A0, no funciona. Solo es Digital, D0.
____________________________________
- Cargamos el siguiente código.
- Aproximamos un imán y observamos el LED13.
- Importante: es distinto acercar el imán por una cara y por la otra, es decir es distinto que aproximemos el polo Norte o el polo Sur del imán.
Código |
int Hall = 6;
int LED13 = 13;
void setup() {
pinMode(Hall,INPUT);
pinMode(LED13,OUTPUT);
}
void loop() {
if(digitalRead(Hall) == HIGH)
{
digitalWrite(LED13,LOW);
}
else
{
digitalWrite(LED13,HIGH);
}
}
|
______________________________________
- Hall A1301 y A1302. Analógico.
- Estos sensores son Analógicos.
- El que utilizo no está en módulo. He puesto una resistencia de unos 10 k.
- En caso que no obtenga valores, quita la resistencia de 10 k
// A1301: 2.5mV = 1Gauss. Si en 5V ponemos 1024 pasos. 1 paso = 1953mG
// A1302: 1.3mV = 1Gauss. Si en 5V ponemos 1024 pasos. 1 paso = 3756mG
A1301-2-Datasheet.pdf
- Los códigos están obtenido de:
http://playground.arduino.cc/Code/HallEffect
Código |
#define NOFIELD 505L // Analog output with no applied field, calibrate this
// Uncomment one of the lines below according to device in use A1301 or A1302
// This is used to convert the analog voltage reading to milliGauss
//#define TOMILLIGAUSS 1953L // For A1301: 2.5mV = 1Gauss, and 1024 analog steps = 5V, so 1 step = 1953mG
#define TOMILLIGAUSS 3756L // For A1302: 1.3mV = 1Gauss, and 1024 analog steps = 5V, so 1 step = 3756mG
void setup()
{
Serial.begin(9600);
}
void DoMeasurement()
{
// measure magnetic field
int raw = analogRead(0); // Range : 0..1024
// Uncomment this to get a raw reading for calibration of no-field point
// Serial.print("Raw reading: ");
// Serial.println(raw);
long compensated = raw - NOFIELD; // adjust relative to no applied field
long gauss = compensated * TOMILLIGAUSS / 1000; // adjust scale to Gauss
Serial.print(gauss);
Serial.print(" Gauss ");
if (gauss > 0) Serial.println("(South pole)");
else if(gauss < 0) Serial.println("(North pole)");
else Serial.println();
}
void loop()
{
delay(1000);
DoMeasurement();
}
|
Código |
#define NOFIELD 505L // Analog output with no applied field, calibrate this
// Uncomment one of the lines below according to device in use A1301 or A1302
// This is used to convert the analog voltage reading to milliGauss
// For A1301: 2.5mV = 1Gauss, and 1024 analog steps = 5V, so 1 step = 1953mG
// For A1302: 1.3mV = 1Gauss, and 1024 analog steps = 5V, so 1 step = 3756mG
// #define TOMILLIGAUSS 1.953125
#define TOMILLIGAUSS 3.756010
void setup()
{
Serial.begin(115200);
}
void loop()
{
float gauss = (analogRead(0) - NOFIELD) * TOMILLIGAUSS;
Serial.print(gauss, 2);
Serial.print(" Gauss ");
if (gauss > 0) Serial.println("(South pole)");
else if(gauss < 0) Serial.println("(North pole)");
else Serial.println();
delay(1000);
}
|
________________________________
|