3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Door Activated LED Lighting using Hall Effect Sensors

Step 4Arduino Test

Arduino Test
«
  • IMG_0644.JPG
  • IMG_0645.JPG
  • IMG_0646.JPG
I usually test out my AVR projects on an Arduino simply because of the ease of debugging. Below is the code I used to test the output of the Hall Effect sensor. I'm not going to go into the deep workings of the Hall Effect here but if you're interested, wikipedia has a bunch of good info.

What's cool about this sensor is that the output is latched. For those of you who don't know what a latch is, it's one of the most basic memory elements in all computing. This particular latch will remember a digital High reading at the output of the sensor until an opposing magnetic field is sensed, at which point it will drop to digital Low and stay there until it is triggered again.

What this means for our code is that we only need to scan the inputs and turn the lights on or off based on what the sensor's memory holds. If you wanted to make this project really energy efficient, you could set up an interrupt to wait for a sensor trigger but since I'll be running this from a wall wart, it doesn't really matter that much to me weather the microcontroller uses 10milliamps or 50.

int sensor=2;
int val=0;
int ledPin=12;

void setup(){
pinMode(sensor,INPUT);
pinMode(ledPin,OUTPUT);
}

void loop(){
val=digitalRead(sensor);
if(val){
digitalWrite(ledPin,HIGH);
else
digitalWrite(ledPin,LOW);
}

« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
8
Followers
1
Author:woody1189