Careful with connecting a "voltage" to the input of a processor.
It could need current limiting, to prevent phantom-powering the processor. A 10k series resistor could be needed. In that case you must increase the pull down resistor to >100k.
An opto link prevents all those dangers.
Leo..
In this case, the voltage source will be the Arduino 5V.
I guess that your main problem is nothing to do with the pull down resistor value. It is likely to be this bug in the code you use to read the state of the toggle switches.
You must initialize the variable input
to 0 because local variables are not initialized for you and could contain anything and this will affect your switch/case statement.
Also ensure compiler warnings are active in preferences. You would have been warned to have a default selection in your switch statement.
For bit manipulation it is better to use unsigned numbers because the sign bit can cause unexpected behaviour.
Use Serial.print() to print the value of input
for debugging.
The higher the pull UP / DOWN resistance, the more susceptible to noise pickup. Try 33k, about the same as AtMega328 internal pullups. When input is HIGH, about 15 microAmps will flow through the 33k pulldown.
Addressing my original question, I made this test setup with only 10kohm pulldown resistors and a print output to see state of inputs. The same inputs I was using before now read as low when no connection is made to the input and high with 5V.
I must be picking up stray signal despite my precautions.
[code]
// Define the line circuit input pins
// Use pulldown resistors on these inputs
// This sketch is to check if a pulldown
// resistor will work as intended.
const int EH = A0; // Input from H toggle switch.
const int ED = A1; // Input from D toggle switch.
const int EFD = A2; // Input from FD toggle switch.
void setup() {
Serial.begin(115200);
pinMode(EH, INPUT);
pinMode(ED, INPUT);
pinMode(EFD, INPUT);
}
void loop() {
Serial.print ("EH input is ");
Serial.println(digitalRead(EH));
Serial.print ("ED input is ");
Serial.println(digitalRead(ED));
Serial.print ("EFD input is ");
Serial.println(digitalRead(EFD));
Serial.println("-------------");
delay(5000);
}
[/code]
That behaviour is exactly what you should expect from the circuit and code which appears in post #27. How does this differ from what you want to achieve?
The circuit shows the board powered by power jack (no USB cable connected) so you would not have been able to verify the results via the serial monitor with this exact setup.
Thank you!
The perspective makes it look worse than it actually was, but worth straightening.
I unplugged the cable for the photo. The serial monitor confirmed that the pulldowns worked.
I know it's hard to follow the whole chain, but that is the behavior I said I wanted in the original circuit, but my inputs would initially show LOW, then change to HIGH and stay there.
That is almost certainly because of the coding error you made in the program which you used at that time to test the state of the buttons. Did you read post #25 ?
You still have not correctely posted your original code.
Please see post #13
So you have a switch that is either open or connects 5V to the Arduino input pin.
So this is your circuit, basically.
10k should be sufficient.
If the switch is very far away say a metre or more, decreasing 10k to 4k7 and adding a 0.1uF capacitor between the Arduino input and gnd should prevent any noise problems.
Do you have a DMM? Digital Multimeter.
Thanks.. Tom..
That's it in a nutshell. Distance from the remote location is TBD, but I should figure in line resistance. The capacitor sounds like a good idea. I have a really cheap DMM.
How much current will be drawn in either case.
Use Ohms Law to calculate the drop.
Opto-coupler should be considered, as suggested earlier in this thread.
Tom..
PS. I have a feeling you are over thinking, instead of experimenting.
PPS. What actually is your project?
Initializing the variable didn't work, better shielding did.
Thanks to all who replied.
Now I will work on expanding the program for westward as well as eastward and adding local directional logic.
I also need to look into the effect of distance from the remote locations.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.