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

I've written the code (below) for a sequence of events to occur based on the user "cutting the wires" to "diffuse" a "bomb". Of course this is just a special effect and not the real thing. There are several elements involved and this is just the wire cutting sequence.

I thought this would be rather simple, but I think I'm over writing the code. I'm new at this and have done all the relevant tutorials, and have tried researching for similar codes, but are not having any luck. I've changed and changed the code based on other projects but to of no avail.

I've also included the layout of the bread board layout so you can see if I've done something wrong there. (I've changed it many times as well.) I've also checked to make sure there is continuity on all the LEDs circuits.

I've figured out the "final reward", but still need to code the special effects actions, but that is later when parts arrive.

Not sure if this is relevant, but when I press the rest button on the Arduino UNO it's not flashing the TX and RX onboard LEDS like it has in the past.

Just got the beginner level starter kit this Christmas (2015) and I'm excited to get some stuff working. I'm just struggling with the code I think. I should have all the current updates to the programming.

Any help in figuring out where I'm going wrong, would be highly appreciated.

Thanks in advance!

Mark

/*Wire Cutting sequence test
  Cut the right wires in the right order and you win. Cut the wrong wire and or in the wrong order, 
  and you lose, and the special effect activates.

LED s represent the wires.  If you pull out the LEDs ("cut the wire") it opens the circuit.  
Which sets off the effect.  The first Green LED on the left represents the three "wrong" Wires.  
All three would be wired in series and cutting any one would open the one circuit. So one LED will 
work to test the code. 

The next 3 Yellow LED s represent the three correct wires to cut and in the order they need to be 
cut,  Left to Right.  The Red LED s represent the three elements of the special effects.  
Their codes to be added later.  These will light up if activated by cutting the wrong wires or 
cutting the right ones out of order.  

The last Blue LED represents the final Correct solution.  It activates another effect that signals 
the successful completion of test.  

*/ 


const int wrongWire = 13;   // the number of the wrong wire pin
const int firstWire = 12;  // the number of the first wire pin
const int secondWire = 11;  // the number of the second wire pin
const int thirdWire = 10;   // the number of the third wire pin
const int smoke = 7;   // the number of the smoke pin
const int light = 6;   // the number of the light pin
const int sound = 5;   // the number of the sound pin
const int drawer = 4;   // the number of the drawer pin

int wrongWireState = HIGH;
int firstWireState = HIGH;
int secondWireState = HIGH;
int thirdWireState = HIGH;
int smokeState = LOW;
int lightState = LOW;
int soundState = LOW;
int drawerState = LOW;

void setup() {
pinMode(wrongWire, INPUT);
pinMode(firstWire, INPUT);
pinMode(secondWire, INPUT);
pinMode(thirdWire, INPUT);
pinMode(smoke, OUTPUT);
pinMode(sound, OUTPUT);
pinMode(light, OUTPUT);
pinMode(drawer, OUTPUT);
}

void loop() {{
digitalRead(wrongWire);
digitalRead(firstWire);
digitalRead(secondWire);
digitalRead(thirdWire);
digitalRead(drawer);
}
 
  // if wrong wire is cut sets off special effects
if (wrongWire == LOW) {
digitalWrite(smoke, HIGH);
delay(500);
digitalWrite(light, HIGH);
delay(500);
digitalWrite(sound, HIGH);
}
   //if wires cut in wrong order sets off special effects
if ((secondWire == LOW) && (firstWire == HIGH)){  
digitalWrite(smoke, HIGH);
//delay(500);
digitalWrite(light, HIGH);
//delay(500);
digitalWrite(sound, HIGH);
}
   //if wires cut in wrong order sets off special effects
if ((thirdWire == LOW) && (firstWire == HIGH) || (secondWire == HIGH)){
digitalWrite(smoke, HIGH);
//delay(500);
digitalWrite(light, HIGH);
//delay(500);
digitalWrite(sound, HIGH);
}
  // all wires cut in correct order , activates effect to indicate sucessful completion
if ((thirdWire == LOW) && (firstWire == LOW) && (secondWire == LOW)){
(drawer, HIGH);
}
}

Wire_Cutting_Sequence.ino (2.73 KB)

You should start with something more simple.

Try to make one LED light up when you open a switch (or disconnect a wire).

Look at the examples that come with the Arduino IDE on how digitalRead() is used.

const int wrongWire = 13;   // the number of the wrong wire pin
...
if (wrongWire == LOW) {

That will never be true.

Simple servo button code. Wire all the external wires in series from the pin to ground. When any of the wires are cut, the servo will move to the other position.

//zoomkat servo button test 7-30-2011
//Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

Thanks Jobi-Wan,

I reviewed the tutorials, specificly "spaceship Interface", and thought I had left out the "else" component. But that did not help either. I broke down just a simple code to try to get the LED to come on with "opening" the switch, and still can't get it. I got it to work in another code , but it's not working here.

If you have any more specific suggestions, I would appreciate it.

Mark

zoomkat,

Appreciate the reply, but it's not helping. I've reviewd and tried several of the codes in your suggestion, but it's still not working. I broke down the code to just a simple turn on an LED when the control pin is LOW and I just can't seem to get it. I got it to work in another code, that controls a motor. Maybe I can break that one down again to figure out what I'm doing wrong.

Thanks, any other suggestions are appriecated.

Mark

ridenhr:
specificly "spaceship Interface"

If you have any more specific suggestions, I would appreciate it.

Look closely at how the digitalRead() function is used and what is done with the result
in the spaceship interface code, and in your own code.

Also, the condition of the if-statement that I pointed out in reply #1 compares a pin number to LOW.
I'm sure you don't mean that. Again, look closely at the spaceship code.

ridenhr:
I've written the code (below) for a sequence of events to occur based on the user "cutting the wires" to "diffuse" a "bomb".

Don't you use a disrupter to "diffuse" a bomb? 8)

Again, Thanks Jobi-Wan,

I did pretty much copy the code from Spaceship Interface. Yes I do mean, if (wrongWire == LOW) {

If the wire is high to begin with and the circuit gets "cut" it would turn it to low and then set off the other actions. Am I wrong? Is there another way to accomplish the same thing?

Here is a simplified code to just accomplish the above task.

int cutWire = 13; // the number of the cut wire pin
int smoke = 7;   // the number of the smoke pin
int cutWireState = HIGH;  // variable for reading the cutWire's status

void setup() {
 pinMode(smoke, OUTPUT);
 pinMode(cutWire, INPUT);

}

void loop() {
 // read the state of the cut wire value:
  cutWireState = digitalRead(cutWire);
// check if the cut wire is cut.
  if (cutWireState == HIGH) {
    // keep smoke off:
digitalWrite(smoke, LOW); //nothing will happen
}
if (cutWireState == LOW) {
  digitalWrite(smoke, HIGH); //smoke will happen
}
}

AWOL:
Don't you use a disrupter to "diffuse" a bomb? 8)

AWOL,

A disrupter sounds like something that might do the job, however, being new to the C++ language, I've not come across that command in the tutorials or any other research I've read. I just looked it up now and don't really find anything relevant. Looks extremely complicated, at least what I'm finding....

Could you explain how I could use such a command? Or are you just dissing me because I'm a newbie? Ha!

Mark

A diffuser is something a bomb disposal engineer uses to separate the bomb from the initiator, and may itself be an explosive device, but may be something as simple as a jet of high pressure water.

ridenhr:
Yes I do mean, if (wrongWire == LOW) {

No, you don't. You didn't look closely enough at the spaceship code (that works) and your own code (that doesn't) and what's different (what makes it work).

wrongWire is 13, and will always be 13, as it is const. And so it should be. It is the pin number. It doesn't change. It is not variable. It is constant.
LOW is zero. (wrongWire == LOW) <-- is always false.

digitalRead() is a function. It has an input and an output. The input of the function, what you feed it inside the parentheses, is the pin number. The result of the function is the state of the pin you read.

The spaceship code does something with the result of the function. You do not.

ridenhr:
If the wire is high to begin with and the circuit gets "cut" it would turn it to low and then set off the other actions. Am I wrong? Is there another way to accomplish the same thing?

Here is a simplified code to just accomplish the above task.

That code does correctly read and test the result of the digitalRead() function. The state, not the pin number.

Does it not work for you?

If nothing is connected to the input pin, that doesn't make it go low. It is 'floating'. It has to be connected to ground to go low.
You could use INPUT_PULLUP as the pinMode instead of just INPUT. That makes the pin go high when nothing is connected. You can then connect the wire to ground, so it is low as long as the wire is in place, and goes high when you cut it.

Instead of that 2nd 'if', you could use 'else', but this is not wrong.

AWOL, Thanks but this is NOT a real bomb, but a Puzzle to figure out. The game players will, thru a series of clues and puzzles, learn the correct color of wires to cut and the correct sequence to cut them. If they do not, they take the chance of cutting wrong wire and losing the game. We are going for the cliche "cutting of the right wires before time runs out to diffuse the bomb movie plot"

Jobi-Wan,

I assume you are trying to get me to come to my own solution, but I'm at my wits end. What I 'm trying to accomplish is when the game player literally CUTS the wrong wire, the "bomb" effects (Light, Sound and smoke) are triggered. If I'm going about this all the wrong way, then PLEASE write me a code that accomplishes the task I'm trying to accomplish.

Thanks, Mark

Jobi-Wan,

When I run the program, the effect is triggered with out the user input, ("cutting the wire"). I triggers about as soon as the Arduino is reset.

Thanks, Mark

ridenhr:
If I'm going about this all the wrong way

That last simplified sketch of yours works for me.

I built a circuit with pin 7 to a led, then to a 220Ω resistor, then to ground, and a wire to pin 13.
Grounding the wire would light the led.

Edit to add: Is the other end of your wire connected to +5?

Attached is an image EXACTLY how my board is connected. I used to have an LED on pin 13 but changed it to just a wire to make sure the LED was causing the problem. You asked if it was attached to +5V. I've tried that. I assumed the positive was coming from the pin 13. Is this where I'm going wrong?

Thanks, Mark

According to your diagram, pin 13 is connected to ground, so it is low.

 if (cutWireState == LOW) {
   digitalWrite(smoke, HIGH); //smoke will happen
 }

According to your code, that means smoke will happen.

You could change your pinMode for pin 13 to INPUT_PULLUP.
That way, the pin remains LOW as long as the wire is in place, and goes HIGH when the wire is cut.

And then swap the conditions in the if()s in your code, so that HIGH means smoke.

ridenhr:
AWOL, Thanks but this is NOT a real bomb, but a Puzzle to figure out. The game players will, thru a series of clues and puzzles, learn the correct color of wires to cut and the correct sequence to cut them. If they do not, they take the chance of cutting wrong wire and losing the game. We are going for the cliche "cutting of the right wires before time runs out to diffuse the bomb movie plot"

I think your confusion arises from your misuse of "diffuse".
It's a verb (to scatter or disperse) or an adjective (spread over a large area), it has nothing to do with removing the fuse (or fuze) from ordanance or de-fusing.

A disrupter diffuses a bomb by scattering its components.

Jobi-Wan,

I got it to work with changing my code to the following;

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
}
}

It goes against common since, but it seems to work. All I changed was (smokePin, HIGH) when the cutWirePinState was HIGH and the smokePin, LOW when the cutWirePinState was LOW. I was just trying anything and this worked. I did just a bit.

Now if I can just carry this new found info forward to the rest of the code, I might be able to make it all work.

Any idea as to why the LED comes ON when it's pin is set to LOW???

Thanks, Mark

Any idea as to why the LED comes ON when it's pin is set to LOW???

Because you've wired the LED between +5V and the I/O pin?

(Best give your keyboard a shake - your '?' is sticking down)