digitalRead always HIGH

I am creating the following Instructable: www.instructables.com/id/Motion_Activated_Halloween_Spider/

I am having a problem with reading the power from the power adapter which is plugged to the security light. Essentially, I am taking the 3V power source to pin #3 and I then enable the code to run the motor. However, with a wire plugged into pin #3, the code executes. With just a wire hanging out of pin #3 and not connected to anything the code fires.

Here is an example:

int inputPin = 3;
int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  pinMode(inputPin, INPUT);
}

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

The LED is always lit unless I connect the wire to the Arduino's ground. The instructable just has the power from the wall-wart coming to pin #3 but I cannot get the LED to turn off with the wire connected to pin #3.

What am I missing to make this project work? Any assistance would be greatly appreciated.

With the input floating, what value are you expecting? It sounds like it's working fine.

Since the power supplied to pin #3 is coming from a wall-wart plugged into the socket of the security lights, I would expect it to be LOW while powered off (ie: the security light hasn't been tripped) and HIGH when powered on.

That isn't the case. When powered off, pin #3 acts HIGH at seemingly random times. When I place a multimeter on the circuit to pin #3 and its wrapped up negative, the voltage is zero yet the LED still lights up.

Maybe a better question would be: using the security light to turn on a wall-wart to trigger on, what would be the best connection to the Arduino to enable my condition to turn on the motor?

smv, are you using a pulldown/pullup resistor?

What I assume I need, a pull down resistor. I take it that without either the pull up or pull down resistor that this is just floating and therefore isn't able to differentiate the delta change.

Since the connection from the wall-wart is +5v when turned on, I assume that I want to pull down to group while it is disabled. And since the circuit from the wall-wart is normally off, I assume again that I would want to pull down to ground on the Arduino.

So this is what I've tried and it works! But... please tell me if I'm correct.

Between the power from the wall-wart and the cable to pin #3, I placed a 10K resistor to the ground on the Arduino. Is that all there is to this?

I wondering if I should place a relay to ensure that the power is only 5vDC.

Thanks for all your assistance! :slight_smile:

You could use a relay. Is the Arduino and the wall-wart on the same power supply? I.e., are you powering the arduino from the wall wart? If not, you need to connect their grounds.

No, I didn't connect the grounds together but that does make sense. I cannot have the wall-wart from the security light powering the Arduino as that wall-wart is simply providing a signal indicating that it should fire the loop.

This is the code to control the motor which lowers and raises the ghost.

int inputPin = 3;
int forwardPin = 4;
int reversePin = 5;

void setup() {
  pinMode(forwardPin, OUTPUT);
  pinMode(reversePin, OUTPUT);
  pinMode(inputPin, INPUT);
}

void loop() {
  if (digitalRead(inputPin) == HIGH) {
    digitalWrite(forwardPin, HIGH);
    digitalWrite(reversePin, LOW);
    delay(750);
    digitalWrite(forwardPin, LOW);
    digitalWrite(reversePin, HIGH);
    delay(3000);
    digitalWrite(reversePin, LOW);
    delay(2000);
  }
}

I want to thank you for all the direction you've given me. I thought the creation of the H-bridge using transistors would be the most difficult part. I've read about pull-down resistors several months ago but I never linked the need for it today.