Arduino Advent Calendar Day 17 (Hall Effect Sensor) - NOT WORKING!

Description

I have just completed the Arduino Advent Calendar Day 17 (Hall Effect Sensor) and there is no magnetic field nearby and the LED turns on. I copied the code from the Git Hub code hosting on the guide. Please help I have attached images and my code.

Image

Block Image

Block Image

Block Image

Block Image

Code

int led = 13;//LED pin

int sensor = 10; //sensor pin

int val; //numeric variable

void setup()

{

pinMode(led, OUTPUT);

pinMode(sensor, INPUT); //set sensor pin as input

}

void loop()

{

val = digitalRead(sensor); //Read the sensor

if(val == HIGH) //when magnetic field is detected, turn led on

{

digitalWrite(led, HIGH);

}

else

{

digitalWrite(led, LOW);

}

}

Answer this question I have this problem too

Is this a good question?

Score 0

Comments:

We had the same problem and we think the signal from the sensor is just the opposite state to that expected by the code.

Try changing the if(val == HIGH) to if(val==LOW). Then the magnetic field will turn the LED on.

by

Thank you for your help. The light goes off with a magnetic field.

by

Add a comment