Thursday 16 February 2012

Hardware development: hall effect sensor

I bought a few things from proto-pic that need testing before implementing into the xBee radio system: The infra-red emitter/receiver pair, the hall effect sensor and magnet.

The infra-red sensors are intended to be used as a presence indicator.

Whilst looking for documentation on infra-red transmitter/receiver pairs, I found this: http://tthheessiiss.wordpress.com/2009/08/05/dirt-cheap-wireless/ a tutorial for using infra-red for wireless communication over long distances. It only works for serial communication, but could come in useful.

The first thing that I'm going to work on is the hall effect sensor and magnet. I am going to use this tutorial

http://arduino.cc/playground/Code/HallEffect

I used this datasheet http://www.sparkfun.com/datasheets/Components/General/Hall-US1881EUA.pdf to work out which pins were which.

I wired up my hall sensor according to the tutorial, and edited some sample code found at http://www.hobbytronics.co.uk/arduino-tutorial11-hall-effect It originally turned the light off when there was magnet contact. I made the code more explicit for ease of future development.

I find the hall effect sensor buggy at times. Sometimes it turned the light on/off permanently, and sometimes it turned it on/off depending on proximity as its meant to. I noted that i was using a 2.2k ohm resistor, and wondered if it would be more reliable if i used a 10k ohm or even a 560ohm resistor. There is a chance that it, however has something to do with the magnet ive chosen and the shape of its magnetic field. I am using a tiny ring magnet, and will test it with other magnets such as this one http://www.maplin.co.uk/magnets-34158. Debounce code may also be of benefit.

Below is the code that i'm using. I also tried it with the original code.


// constants won't change. They're used here to set pin numbers:
const int hallPin = 2;     // the number of the hall effect sensor pin - changed
const int ledPin =  13;     // the number of the LED pin
// variables will change:
int hallState = 0;          // variable for reading the hall sensor status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);    
  // initialize the hall effect sensor pin as an input:
  pinMode(hallPin, INPUT);  

    Serial.begin(9600);
}

void loop(){
  // read the state of the hall effect sensor:
  hallState = digitalRead(hallPin);

//code below this line has been changed

  if (hallState == HIGH) {  
    // turn LED on:  
    digitalWrite(ledPin, HIGH);
  }

  else if (hallState == LOW) {  
    // turn LED on:  
    digitalWrite(ledPin, LOW)
    ;
  }

Serial.print(hallState);
}





This will be easily integrated into the project.

Below is a photograph of the breadboard.

No comments:

Post a Comment