laser pistol

Hi all

I’m trying to build a laser pistol but i have a problem with my arduino
everytime i restart my arduino doesn’t start to work…
And i need to upload again. :confused:
can someone tell me why is this happening???
i tried changing the board and i get the same result :frowning:

My code

#include <SD.h>                      // need to include the SD library
#define SD_ChipSelectPin 4  //using digital pin 4 on arduino nano 328
#include <TMRpcm.h>           //  also need to include this library...
#pragma GCC diagnostic ignored "-Wwrite-strings"

const int buttonPin = 6;     // the number of the pushbutton pin
const int ledPin =  7;      // the number of the LED pin

// variables will change:
int buttonState = 0;
TMRpcm tmrpcm;   // create an object for use in this sketch
char mychar;

void setup(){
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);

  tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc

  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
    Serial.println("SD fail");  
    return;   // don't do anything more if not
  }
  delay(1000);
  tmrpcm.play("ab.ahs"); //the sound file "music" will play each time the arduino powers up, or is reset
}

void loop(){  

 
    
    
    while (digitalRead(buttonPin) == HIGH)
    {
    tmrpcm.play("ab.ahs");    
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);

     
  } 
  }

Are there any errors when you upload?

What happens if you press reset?

What hardware do you have attached?

Weedpharma

I'm using Nano V3.0 5V 16M ATmega328P.
When i press reset nothing happens.
no error while uploading :confused:
I noticed that it starts to work when i press serial monitor
Any ideas ??

I'm missing Serial.begin in your sketch.

BorisDukic:
I'm using Nano V3.0 5V 16M ATmega328P.
When i press reset nothing happens.
no error while uploading :confused:
I noticed that it starts to work when i press serial monitor
Any ideas ??

Sounds like you're using 1.6.8 on Windows. That version has a bug that causes it to continually reset any arduino boards connected, whenever the IDE is running and the serial monitor is not open.

Rather than pull the 1.6.8 release like they should have, they've just left it up, broken.