Why am i getting floating input?!

Hi!

I have a knex roller coaster project, where i have wired loads of motors to my arduino uno, and controls them. I also have a magnet stuck underneath the train, which trips a magnetic reed switch, so i can make the motors respond. The switch works perfectly fine, but the pin constantly gives random input. I have
tried both connecting the input pin to ground (through a resistor) using both digital and analog, but nothing changed.

bool passed = false;
  while (!passed)
  {
    int i = analogRead(SENS1);
    Serial.println(i);
    if (i == 1)
    {
      Serial.println("Test");
      passed = true;
    }
  }

However, i am getting random input all the time! The reading the sensorpin will sometimes randomly read high.

I have read around floating input, and have found some good answers, but nothing is working for me!
(I've attached a photo of my Arduino setup)

I've tried everything, what's can i do?!

:frowning:

Can you draw a schematic of the input you are referring to on a blank sheet of printer paper and post a photo of it ?

Why are you using a pulldown resistor ? (what value is it?)

Sorry, I tried editing my post because i forgot to do that but it wouldn't let me.

It's basically the exact same as the one in this tutorial

You should be wired similar to one of these 3 switches:

Use digitalRead.
.

Sorry, I tried editing my post because i forgot to do that but it wouldn't let me.

https://www.arduino.cc/en/Tutorial/Button

It's basically the exact same as the one in this tutorial

No it is not. The one on the tutorial uses a digitial input like the ones used in LarryD's schematic.
Yours uses an ANALOG input.
They are COMPLETELY DIFFERENT !

Thank you! I will try these arrangements.

I'll reply when i have tested. :slight_smile:

also, i was just testing analog input, i am using digital

Don't get offended but do you know what you are doing ? (how much electronics experience do you have ?)

Little experience. :confused:

I have built myself up from the basics... but haven't learnt much. I've had lots of success with slightly simpler projects in the past, like rigging up an automatic nerf gun, but this problem is just bugging me.

I've probably just missed out on something simple.

I'll try those schematics that LarryD posted, and get back to you on the results.

What are the "basics" you are referring to ?

What , in your mind , ARE the "basics" in electronics ? (if you had to list them, what would they be ?)

(Do you know what they are ?)

You can use most analog inputs as digital inputs - that should be OK

regards

Allan.

You can use most analog inputs as digital inputs - that should be OK

I don't think that's the point. He is using analog code with an analog input for a digital type input wiring that he copied from a tutorial but changed the code to analog code.

Hi,
Do you have a DMM to measure voltages around your circuit.
What is the voltage on the input pin of the Arduino when the switch is open and when it is closed with respect to gnd?

Tom... :slight_smile: