Arduino digital input

I cannot make an input of 0.04v into a digital pin think its low. Does low only mean 0v on Arduino Nano, thanks

Show us a good schematic of your circuit. Show us a good image of your wiring.

You do have GNDs connected?

.

Datasheet page 313. Everything below 0,3 x Vcc is a LOW. Everything above 0,6 x Vcc is a HIGH. Everything in between is just up to the mood of the chip and the distance to the moon (aka, undefined, might read LOW, might read HIGH but I probably hysteresis). For Vcc of 5V that’s <1,5V for LOW and >3,0V for HIGH.

For Vcc lower then 2,4V it’s 0,2 x Vcc and 0,7 x Vcc.

Thanks Larry, it’s just a hall switch output going into D3. The hall switch is an A3213EAU-T. It’s input volts is 5v, a 100k resistor goes from 5v input to the output pin, the center wire going to ground.

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize pins 
  pinMode(13, OUTPUT);
  pinMode(3, INPUT);
}


void loop() {


  if (3==LOW)
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  else             
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
               
}

I have tried reversing magnet, checked wiring etc.

if (3==LOW)

When is 3 ever going to be equal to low aka 0 :wink: Did you mean to red the pin?

PS, you can save the resistor by enabling the internal pull ups.

Thanks septillion, sorry missed your earlier reply.

Hall output goes to pin 3, and I am trying to make something happen when pin 3 is made low by the hall switch.

Alright, but that line isn't going to do that. Like I said, the number 3 isn't magically going to equal the number 0 :wink: If you want to read pin 3, you have to do so.

Many thanks, that woke me up.

int ledPin = 13; // LED connected to digital pin 13
int inPin = 3;   // pushbutton connected to digital pin 7
int val = 0;     // variable to store the read value

void setup()
{
  pinMode(ledPin, OUTPUT);   
  pinMode(inPin, INPUT);  // Hall switch
}

void loop()
{
  val = digitalRead(inPin); 
  digitalWrite(ledPin, val);  
}

Thanks again. :slight_smile:

Few comments

Use the smallest possible variable type. For pins that's a byte.

Things that don't change, make them const. In a lot of cases the compiler can save ram then. And it's my preference (and from a lot others as well) to UpperCamelCase const variables to remind me I can't change those variables.

The name inPin, yeah, it's an input. But it would tell you even more if you would just call it buttonPin :wink: But is it a button?

But worst, you comment doesn't match the code! Comment says 7, code says 3. That's why I don't talk about values in the comments because then I would need to edit both code and comment when I change the number with the risk I forget to edit one of both.

val can be a bool (again, smallest possible). But more over, it has NO right to be global :slight_smile: Just make it a local.

Or even less code, just inline it if you just use it in one place.

And like I said, you can save a resistor by using the internal pull ups.

What you end up with is

const byte LedPin = 13; // Pin to the LED
const byte ButtonPin = 3;   // pin to the button / hall switch

void setup()
{
  pinMode(LedPin, OUTPUT);   
  pinMode(ButtonPin, INPUT_PULLUP);
}

void loop()
{
  digitalWrite(ledPin, digitalRead(ButtonPin)); 
}

Many thanks again, all very useful advice. Your code is much cleaner and readable. I have a lot to learn. Thanks again for taking the time explaining.

Regards