I have digital pins 3 to 12 connected to ground with a separate wire per pin that I can interrupt.
All these pins are setup as pinmode input, and I did a digitalWrite HIGH on all these pins to activate the internal pull up resistors.
The problem is that I get a LOW on some pins when doing a digital read when the wire to ground on that pin is disconnected. So it should give me a HIGH, but it doesn't. I checked the voltages on all the pins and for some it gives 4.2V, but the once giving a false LOW are around 3.8V. It looks like this is just not high enough to make the input pin go to high.
I use a nano and the power is given by the USB port.
Now what is causing this false reading? Could it be that the USB doen't give a real 5V but only 4.2? Or is an external pull up better than the internal ones? Or are some pins more sensitive to this problem than other ones? (e.g. the I2C pins)
What you describe is odd and not normal.
It could be a faulty chip or the code you use. Have you tried using INPUT_PULLUP when you set the pin mode.
As a final thing you could use a pull up resistor but it should not be needed.
The problem would not be caused by a lower voltage on the power rail.
No pins connected to ground => all pins read HIGH, OK
Pin 3 connected to ground => Pin 3 reads LOW, the others HIGH, OK
Pin 3 & 4 connected to ground => 3 & 4 read LOW, others HIGH. OK. Voltage on pin 5 & 6 is 4.2V
Pin 3, 4 & 5 to GND => Pin 3, 4, 5 & 6 read LOW, others HIGH. Not OK. Voltage on Pin 6 dropped to 3.8V.
I don't understand it.
Reading on the 5V out pin is 4.2V, so the computer's USB does not give me more.
I think you need to post the code you are using and also a good photograph. As u said it could be a faulty board. What happens if you connect the pins directly to 5V?
Reading on the 5V out pin is 4.2V, so the computer's USB does not give me more.
Note that many computers and laptops do not supply the full 500mA that's allowed on each usb port. As a test, try with a USB hub with DC power adapter connected...this ensures there will be 500mA available...then check the voltage and see what you get. Also...are any ICs or MCU getting abnormally hot?
Test between pins 5 and 6 using a multimeter in resistance mode whilst the board is unpowered... If that reading is significantly different to the measurement between
other neighbouring pairs of pins it suggests a fried microcontroller. In which case
it suggests you did something bad to it (over voltage, inductive load?)
Using external pull-down resistors on inputs would be a better method. That way no need to worry about any glitch during erase or programming, inadvertent changes during code development or running other code (libraries sketches etc).
dlloyd:
Using external pull-down resistors on inputs would be a better method. That way no need to worry about any glitch during erase or programming, inadvertent changes during code development or running other code (libraries sketches etc).
No pins connected to ground => all pins read HIGH, OK
Pin 3 connected to ground => Pin 3 reads LOW, the others HIGH, OK
Pin 3 & 4 connected to ground => 3 & 4 read LOW, others HIGH. OK. Voltage on pin 5 & 6 is 4.2V
Pin 3, 4 & 5 to GND => Pin 3, 4, 5 & 6 read LOW, others HIGH. Not OK. Voltage on Pin 6 dropped to 3.8V.
I don't understand it.
Sounds to me like the pins are OUTPUT+HIGH, not INPUT_PULLUP. Connecting pins to ground is dragging down the voltage.
Easy way to find out: Connect pins to GND via a multimeter which shows current. If you see more than a milliamp of current then they're set as OUTPUT, not INPUT.
If one goes to ground, the other pins have a voltage drop as well. Similar problem if I use pull down resistors. If one goes high, the others have a voltage increase.
Completely in the dark now and deadline approaching. Who can help?
No code running yet. But it didn't make any difference. The code I used only set the pinmodes to input and did digital reads from the pins. Didn't get any further yet.
cbnation:
No code running yet. But it didn't make any difference. The code I used only set the pinmodes to input and did digital reads from the pins. Didn't get any further yet.
This is the code. As you will see I already uncommented a lot to rule out as much as possible.
Please note that in the clip I posted, the arduino was not on (no power) but it was the same with or without power, and hence with or without the code running.
/*
Arduino bomb
*/
#define buzzerPin 2
#define blackWire 3
#define whiteWire 4
#define greyWire 5
#define purpleWire 6
#define blueWire 7
#define greenWire 8
#define yellowWire 9
#define orangeWire 10
#define redWire 11
#define brownWire 12
boolean failed = false; // keep track if the bomb went off
int wireState = LOW; //to check the state of a wire. High means it is cut
boolean canBeHigh; // to keep track if the next wire can be high
void setup() {
Serial.begin(9600);
// initialize buzzer
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
// initialize wires as input:
pinMode(blackWire, INPUT);
pinMode(whiteWire, INPUT);
pinMode(greyWire, INPUT);
pinMode(purpleWire, INPUT);
pinMode(blueWire, INPUT);
pinMode(greenWire, INPUT);
pinMode(yellowWire, INPUT);
pinMode(orangeWire, INPUT);
pinMode(redWire, INPUT);
pinMode(brownWire, INPUT);
// Activate internal pull up resistors
/* digitalWrite(blackWire, HIGH);
digitalWrite(whiteWire, HIGH);
digitalWrite(greyWire, HIGH);
digitalWrite(purpleWire, HIGH);
digitalWrite(blueWire, HIGH);
digitalWrite(greenWire, HIGH);
digitalWrite(yellowWire, HIGH);
digitalWrite(orangeWire, HIGH);
digitalWrite(redWire, HIGH);
digitalWrite(brownWire, HIGH);
*/
}
void loop(){
/* Order of wires
blackWire
blueWire
brownWire
greenWire
greyWire
orangeWire
purpleWire
redWire
whiteWire
yellowWire
*/
if (!failed)
{
Serial.println("***Start***");
canBeHigh = true;
checkWireState(blackWire);
checkWireState(blueWire);
checkWireState(brownWire);
checkWireState(greenWire);
checkWireState(greyWire);
checkWireState(orangeWire);
checkWireState(purpleWire);
checkWireState(redWire);
checkWireState(whiteWire);
checkWireState(yellowWire);
}
}
void checkWireState(int theWire){
wireState = digitalRead(theWire);
Serial.print("Wire ");
Serial.println(theWire);
Serial.print("WireState ");
Serial.println(wireState);
if(wireState == HIGH)
{
if(!canBeHigh) activateBuzzer();
}
else
{
canBeHigh = false;
}
delay(50);
}
void activateBuzzer(){
/* digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(buzzerPin, LOW);
delay(500);*/
Serial.println("Buzzing");
failed = true;
}
Connecting it is not the issue, it just doesn't make any difference whether it is running or not. The behaviour from the movie clip is always the same. Looks like nobody can explain what is happening :~