[SOLVED - OUTSOURCED] Defuse the Bomb! Coding and layout help needed

AWOL,

The I/O pin #5 is wired to the Anode Pin on the LED without anything else. The Cathode goes thru a 220 ohm resistor to the NEG.

If the code is telling the LED to be LOW then why would the LED be ON?

I'm not complaining that it works, but I thought this programming was supposed to be logical. I don't get WHY it works. (for future reference)

(I shook my keyboard, but I think it's too far from the dongle)

What is the pinMode on that pin?

pinMode(smokePin, OUTPUT);

here is the whole code;

int cutWirePin = 13; // the number of the cut wire pin
int smokePin = 5; // the number of the smoke pin LED
int cutWirePinState = HIGH; // variable for reading the cutWire's status
//int smokePinState = LOW; //LED off to begin

void setup() {
pinMode(smokePin, OUTPUT);
pinMode(cutWirePin, INPUT);
}

void loop() {
// read the state of the cut wire value:
cutWirePinState = digitalRead(cutWirePin);
// check if the cut wire is cut.
if (cutWirePinState == HIGH) {
// cut wire in place
digitalWrite(smokePin, HIGH); //nothing happens
}
if(cutWirePinState == LOW); {
//cut wire is cut
digitalWrite(smokePin, LOW); //LED will light, setting off effect
}
}

if(cutWirePinState == LOW);

oops

(Did you see how I used code tags?)

Sorry, I did do that in response #18 above, I just copied pasted #18 in #22 assuming it would copy the code tags as well.

I can't bear cluttered code
(Uncompiled, untested)

const byte  cutWirePin = 13; // the number of the cut wire pin
const byte smokePin = 5;   // the number of the smoke pin LED

void setup() 
{
  pinMode(smokePin, OUTPUT);
  pinMode(cutWirePin, INPUT); // There's a pullup on this pin, right?
}


void loop() 
{
  digitalWrite(smokePin, digitalRead(cutWirePin));
}

AWOL,

Your code work as well. and a bit less cluttered, as you say. I assume that "const byte" works the same as "const int".

The "pullup" I'm using is literally a wire from pin #13 to a NEG that you Pull out of the board to activate pin #5. This best simulates the literal "cutting of the wire" to defuse the bomb. If you mean some code language, No.

Thanks for your help, I was beginning to wonder if you were only going to give me grief over "diffusing" a bomb. But I was actually using the word "defuse" which means what I thought; "remove the fuse from (an explosive device) in order to prevent it from exploding.)" So I'm not technically "removing the fuse", so maybe I should use the word, "Disarm" to be technically correct.

So, the answer is no, you don't have a pullup on the wire pin?
So when you cut the wire, it is floating?

AWOL,

Sorry, I do not know what you mean by "floating".

I have a connection from pin#13 to row #2 on my breadboard. I also have a connection from the NEG column to row #1. I then have a piece of wire (cutWire) connected on one end to row #1 and the other to row #2. It's long enough for me to grab with my fingers.

I literally pull the connecting wire OUT of the breadboard to simulate the "cutting of the wire". That takes the cutWirePinState to low which activates the smokeWire.

OK, so the condition on the input pin with the wire in place is LOW, because it is connected to ground.

When you pull out the wire, what is the logical condition on the input pin?

Why do you think that?

To me, it seems logical that with the wire in place, (uncut), the input pin, #13, would be HIGH, and pin #7 would be LOW. When you pull the wire (cut it) #13 would then become LOW. If the code tells pin #7 to become HIGH when pin #13 becomes LOW. That would then activate the LED (effect).

But the way the following code reads to me, is that when the cutwire (#13, HIGH) is not pulled, then the LED (pin #7) is ON or HIGH. And when you cut the wire it should go off. But just the opposite is happening. (#13 is uncut and #7 LED is off. Pull #13 and the LED comes ON.)

I'm not complaining that it works , I just don't understand WHY?

void loop() {
 // read the state of the cut wire value:
  cutWirePinState = digitalRead(cutWirePin);
// check if the cut wire is cut.
  if (cutWirePinState == HIGH) {
    // cut wire in place 
digitalWrite(smokePin, HIGH); //nothing happens
}
if(cutWirePinState == LOW); {
  //cut wire is cut
  digitalWrite(smokePin, LOW); //LED will light, setting off effect
}
}
if(cutWirePinState == LOW);

Still "oops"

It is not at all logical that an unconnected pin should be HIGH.

Your code works (well .. worked) since reply #7. Your issue is with your circuit.

In reply #11, I first suggested to use INPUT_PULLUP and connect the wire to ground, so that it goes HIGH when cut. Because a pin doesn't just go LOW when nothing is connected. It will be 'floating' (flopping about).

If you want the pin to be HIGH when the wire is in place and LOW when cut, then you must make sure that the pin is pulled down with a pulldown resistor. But it would be easier to use the internal pullup resistor, and have the pin go HIGH when the wire is cut.

AWOL:
It is not at all logical that an unconnected pin should be HIGH.

AWOL,

That is my confusion. So, why does it work? Is there something on pin#13 that causes it to work? I know it has the built-in LED attached to it.

Jobi-Wan,

I tried to use INPUT_PULLUP, and it did nothing. Maybe I don't know exactly how to write the code to call for it.

Note the title of NEWBIE under my name.

We were all newbies once; it's just an indication of how many posts you have.
Have you fixed the problem I pointed out in reply #31?

I'm abandoning the code that confuses me and going with yours. It seems to work fine. I'm now moving own to the next steps. Instead of turning on an LED I've set it up to activate a solenoid valve when the "wire is cut"

I've used a MOSFET transistor in place of the LED to control a 12 volt water valve solenoid. I first tested it on a battery operated light. Now, I connected a 12 volt power drill battery like is shown in the Arduino beginner project book in the Motorized Pinwheel Project. The solenoid replaces the motor and the 12 volt battery replaces the 9volt.

And without changing you code at all, it works!!!! I'm waiting on parts for the sound and lights, before I can work on those. Then there is the countdown clock...

Next I'll tackle adding in the three wires that need to be cut in the correct order. If I have questions, maybe I should start a new topic string

Thanks for all your help. Sorry if my Newbie questions were annoying.

Mark

I really need to know that you fixed the problem in reply #31.

Programming is logical, but you have to have a logical, painstaking approach to it.

ridenhr:
I tried to use INPUT_PULLUP, and it did nothing. Maybe I don't know exactly how to write the code to call for it.

It is more about wiring than about code. (I'm an electronics noob myself, so I may have terms wrong..) If you use INPUT_PULLUP as the pin mode, the pin is internally connected to +5 through a high (50Kohm?) pullup resistor. This means that it takes very little to pull the pin low, but if it is not connected to anything, it will go high.
If you use this pin mode, your pin never goes floating and always has a valid/usable state. It is most appropriate for your wire cutting thing. Connect the pin to ground via the wire. This makes the pin low, because it is connected to ground. When you cut the wire, the pin is no longer connected to ground, so the pullup resistor pulls it up and it goes high. There is no pinMode INPUT_PULLDOWN.

AWOL:
I really need to know that you fixed the problem in reply #31.

Programming is logical, but you have to have a logical, painstaking approach to it.

Well, No. I don't know where it is you want me to put that in my code. Where it says high? (I would assume), But what about where it says LOW, do I change that to HIGH? If so, then I'm back to where I started. That, does not seem to work.

Or are you telling me to change the LOW to HIGH?

I just tried it again and the only way it seems to work is like this.

  if (cutWirePinState == HIGH) {
    // cut wire in place 
digitalWrite(smokePin, HIGH); //nothing happens
}
if(cutWirePinState == LOW); {
  //cut wire is cut
  digitalWrite(smokePin, LOW); //LED will light, setting off effect

And I don't really understand what makes yours work either.

{
  digitalWrite(smokePin, digitalRead(cutWirePin));
}