My inputs seem to be HIGH by default...

I am trying to get an input read by arduino from a sensor using an external power supply, but even if i don't connect the sensor my inputs seem to be acting as high, and the action is being executed as though the input is high. If i tie the input to arduino's GND then it does recognise it as a low signal and does execute the action.
I know that may not make much sense..
but any help would be appreciated
thanks

Signals that do not have an input assigned are usually floating, which can give seemingly random values.

The ATmega has internal pullup resistors that can be turned on to pull the input signal up to VCC. It's possible that the pullups are turned on, hence your consistent logic high with nothing connected.

-j

that could be the problem!?

how do I turn the pull up resistors off?
thanks for your help

I guess I don't understand the problem - the first time I read your post it seemed you were reading high with nothing connected.

Are you saying it reads high even with your input connected? If this is the case, what is the input?

We need more information about your circuit.

-j

ok :slight_smile: I am very new to this (2 days) so my knowledge on the arduino is limited atm! so sorry about that.

Please bear with me! there is quite a bit of reading.

The circuit is a very simple one, just 2 inputs (one analogue and a digital) both controlling one output.

Basically it is a IR beam (digital input) that is used to turn on a set of garden lights, and is only operational at night time (use of an LDR). The output is via a relay to switch on the garden light circuit.

The analogue input is by use of an LDR to detect light levels. I have connected this as per (http://webzone.k3.mah.se/projects/arduino-workshop/projects/arduino_meets_processing/instructions/ldr.html)
and that part of the circuit works fine. This is being used as a detector of day and night, and in the programming is set so that the rest of the actions will only take place if it is night time (or past my set threshhold).

The problem lies with the digital input, which is an IR beam, which outputs a 12V signal once the beam is broken. To over come the obvious problem of the 12V I have used it to switch an NPN and thus switch the arduino's 5V logic level to the input. (this also works fine when tested standalone from the arduino board, it successfully delivers 5V to the input when the beam is cut.

The output is via the digital output and this switches an NPN to give required external source to power the relay. (This also works fine).

OK, so back to the problem, say I set my digital input to digitalPin 7 and output to Pin 12, once the light level is low enough for the program to recognise initialisation of the IR sensing, even with nothing connected to Pin 7, the relay will switch on, indicating a HIGH value at Pin 7, the relay will only remain OFF if I tie Pin 7 to GND (this obviously doesn't help anything except to realise the problem further.

my c code is as follows: (the problem most likely is in my code)

int IRpin = 7;
int RLYpin = 12;
int analogPin = 3;
int threshold = 512;
int val = 0;
int vald = 0;
int timedelay = 5000;

void setup()
{
pinMode(IRpin, INPUT);
pinMode(RLYpin, OUTPUT);
}

void loop()
{
val = analogRead(analogPin);
vald = digitalRead(IRpin);
if (val >= threshold && vald == HIGH)
{
digitalWrite(RLYpin, HIGH);
delay(timedelay);
digitalWrite(RLYpin, LOW);
}
}

OH! i forgot one more thing, when the system is completly switched on (both inputs are satisfied) the garden lights will stay on for 10 minutes - this is the delay in the code, set for 5 seconds for testing, this is just the amount of time the relay is switched on for.

And to answer your question, yes even with the IR sensor connected to Pin 7, Pin 7 will always act as HIGH (no matter what the state of the sensor).

thanks for the description, the problem is much clearer now.

I'm pretty sure the Arduino's internal pullups, even if enabled, would not be causing this problem unless the transistor is supplying extremely low current (such that it can't overcome the pullup).

Have you used a meter or scope to verify the signal levels at the input pin?

Your code looks fine to me. I can't help but think it's a problem with the circuit. Is there any way you can post your schematic?

-j

I have come up with this very quick schematic, layout is poor but it gives you the general idea.

JUST REALISED THAT I FORGOT TO NAME TWO TERMINALS!! :
LSP3 is the positive of the power supply for the relay and
LSP4 is the negative for the relay.


so, just to re-cap, pin7 seems to read HIGH regardless of what is connected to it (unless tied to GND).

The measured value at pin7 with nothing connected is 0.12V this is actually a LOW signal, so i don't understand why the board or program is treating it as HIGH.

hi

the problem is with the top transistor.... the way you have it wired, it adds a 10 million ohm resistor to the base and the collector of the transistor. This is because it is driving a high-impedance, 10 million ohm input. There's also no ground reference for that transistor: it couldn't get to ground if it wanted to. it should work immediately if you connect a 1K from pin 7 to ground.

Have a look at the top diagram on this page: Re in your circuit= 10,000,000, probably more. :slight_smile:

Can you describe very simply what that transistor is supposed to do? I'm a little unclear about he sensor connect to the top transistor. It's a good start for a schematic, the relay driver is perfect, but I am not sure why you have that configuration for the input transistor.

D

ps; oops apologies kg4, I didn't see you were goign to answer this :slight_smile:

I wil try your suggestion which sounds like it will probably fix the problem! but the other thing I am wondering is why, when nothing is connected to the input pin 7 it is being read as HIGH (this is even when the sensor and transistor setup is completely removed from the circuit).

The top transistor has been used because the output of the sensor it +12V DC, and has a separate ground to that of the arduino board, so that 12V signal is being used to switch the transistor and allow the 5V arduino supply to run through it and to the input pin.
I used this method of switching because it was the only solution I could come up with to give the input a readable and valid logic value. If there is a better way to do this that would be great! :slight_smile:

hi

the top is probably reading high because it has internal pullups enabled... electricaly it is because the teensy-tiny input transistors or mosfets in the Atmega can't find a path to ground for their current. anyway, does it matter? When you connect a proper circuit it will read high and low. :slight_smile: :o :slight_smile:

You should scrap that transistor input circuit post-haste, pronto, immediately, etc, and make one that is essentially the same as the relay output circuit. Wire it in common-emitter configuration, like the top diagram on this page: Common emitter - Wikipedia

The collector will be your output to pin 7, the Re resistor should be about 1 to 10K, and your 12V source goes into the base-emitter connection through a 1K resistor. Be sure to connect the 12V ground to the Arduino gnd.

D

PS: for voltage isolation I am a big fan of optoisolators.... they do the voltage shifting, and they give you 100% electrical isolation from harmful voltages. Check out this diagram, it shows how the designer was able to sense 120V and use it in a low-level DC circuit.

ok ill give the common - emmitter a go..

just a little confused as to what goes to where in it all..

the Re restistor you reffered to is that the Rc resistor? or are we adding another one in the works somewhere? and also what connects to the V+ ?... if it is the arduino 5V won't that go straight through the resistor and show high on pin 7 anyway?

the sensor gives out a voltage across its two terminals when activated, so when it is activated i WANT to see a high value at pin 7.

thanks heaps for your help it is greatly appreciated and I apologise for my lack of knowledge at this point! :slight_smile:

hi Dan

people ask this question a lot, so I took a few minutes to redraw a diagram I usually give my students who ask this...
you'll find it here: Arduino Playground - HomePage

Hope this helps

D