Hall Effect

Contents

Overview

Parts

Arduino microcontroller and carrier board

LiPo battery

Hall effect switch (see spec sheets below)

NOTE: There are two types of hall effect sensors in the electronics supply cabinet.

1) SS495B: An analog sensor that outputs a voltage between zero and the supply voltage. e.g. if Vsupply = 5V, when there is no magnetic field, it outputs 2.5V and then either 0 or 5v for north or south.

2) A3211/2 (not sure which): A switch, outputs 0v when there is magnetic field and Vsupply* when there isn't.

*Note! The Vsupply max for this is 3.5V so make sure to use a voltage divider to power it with a lower voltage than 5v.

General information about hall effect sensors:

http://bildr.org/2011/04/various-hall-effect-sensors/

Prepare the breadboard

http://bildr.org/blog/wp-content/uploads/2011/04/us1881.png

Program the Microcontroller

This is a code written by Brian Alvarez -- a hall effect sensor makes the mini-me follow a magnetic strip

//EVERY LINE THAT STARTS WITH // IS A COMMENT AND NOT CODE
//we are using the servo library to control servos.
//http://arduino.cc/en/Reference/Libraries for more info
#include <Servo.h>
//define variables we will use in the program
//feel free to change these as needed, they
//depend on your specific configuration
//set up the "servo" object, which comes from the
//included servo library (the #include... line)
Servo leftMotor;
//sets which pin the left motor is attached to
//pins 8 and 9 are the 2 servo attachment points located
//FURTHEST away from the actual arduino
#define leftMotorPin 9
//use this to help make sure you robot travels straight.
//It allows us to compensate for discrepencies in different
//motors, etc. Also, if your robot drives backwards,
//make this negative. If your robot spins or stuff like that, play
//around with the signs
const double leftMotorScaler = 0.5;
//leave this at 90 unless you have weird motors. If we tell the
//servos to run at "90" speed, they stay still. Less, they run
//backwards, more they run forward. This provides lots of
//flexibility for using different types of servos
const int leftZero = 90;
//all the same things for the right motor
Servo rightMotor;
#define rightMotorPin 8
const double rightMotorScaler = -0.5;
const int rightZero = 90;
//which pin is the hall effect sensor attached to?
//Refer to this diagram for how to wire up the sensor
//http://bildr.org/blog/wp-content/uploads/2011/04/us1881.png
//it is a slightly different sensor, but the wiring is the same
#define hallEffectPin 2 //feel free to change this as needed
//this set of code runs once
void setup()
{
  //tell the arduino its going to read from the hall effect sensor
  //instead of send power to it
  pinMode(hallEffectPin, INPUT);
 
  //set up the servos, tell them what pin to use
  leftMotor.attach(leftMotorPin);
  rightMotor.attach(rightMotorPin);
}
//this code loops infinitely
void loop()
{
  //this works by following the edge of the magnetic strip.
  //it essentially tries
  if(digitalRead(hallEffectPin) == HIGH) //we are ON the line
  {
    //turn OFF the line to follow the edge of line
   
    //run the left motor forward (hence the +) slowly
    leftMotor.write(leftZero+(20*leftMotorScaler));
    //run the right motor forward slightly faster
    rightMotor.write(leftZero+(40*rightMotorScaler));
  }
  else //we are off the line
  {
    //turn onto the line to follow the edge of line
   
    //same as above, but turning the other direction
    leftMotor.write(leftZero+(40*leftMotorScaler));
    rightMotor.write(rightZero+(20*rightMotorScaler));
  }
}