Laser Tripwire

I am creating a laser tripwire for a school project, but I am having trouble uploading files to the arduino nano. I got the idea from this website. [
There are two separate files: lasertripwire.ino and pitches.h. I have successfully uploaded the pitches file individually but once I try to do both files there is an error. Arduino: 1.6.8 (Windows Vista), Board: "Arduino Nano, ATmega328"

C:\Users\Kevin\AppData\Local\Temp\untitled886503113.tmp\sketch_apr23b\lasertripwire.ino: In function 'void setup()':

lasertripwire:21: error: redefinition of 'void setup()'

void setup() {


lasertripwire:1: error: 'void setup()' previously defined here

//Laser tripwire sketch - @vmfoo


C:\Users\Kevin\AppData\Local\Temp\untitled886503113.tmp\sketch_apr23b\lasertripwire.ino: In function 'void loop()':

lasertripwire:28: error: redefinition of 'void loop()'

void loop() {


lasertripwire:6: error: 'void loop()' previously defined here

#include "pitches.h" //include the frequency definitions of the pitches


exit status 1
redefinition of 'void setup()'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I am new to this and need some help.](

Post your code - it looks like you've got two loops and two setups.
Use code tags.

Please go back to your post and sort out the tags.

//Laser tripwire sketch - @vmfoo

//playMelody function and pitches.h borrowed from arduino tone tutorial and adapted

#include "pitches.h"  //include the frequency definitions of the pitches

#define PIEZO_PIN 3
#define ARMED_PIN 2
#define THRESHOLD 80 
#define LED_PIN 13

// notes in the melody:
int melody[] =

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = { 4, 4, 4, 6,12,4,6,12,2, 4, 4, 4, 6,12,4,6,12,2 };

void setup() {
  Serial.begin(19200); //for debug
  pinMode(PIEZO_PIN, OUTPUT);  //setup the pin to make noise on
  pinMode(LED_PIN, OUTPUT);  //setup the pin to light when set
  pinMode(ARMED_PIN, INPUT); //we are going to look for this to go high

void loop() {
  // read the input on RECEIVER_PIN
  int sensorValue = analogRead(RECEIVER_PIN);
  // print out the value you read if debugging
  if( sensorValue < THRESHOLD ) {
    digitalWrite(LED_PIN, HIGH);  //Turn it on to show that the trap is set
  } else {
    digitalWrite(LED_PIN, LOW);  //Turn it off 
  if (digitalRead(ARMED_PIN) && (sensorValue > THRESHOLD) ) { //make noise if the trap is armed and the laser is off
    Serial.println("INTRUDER ALERT!!");
    playMelody();  //this funciton blocks until melody is over

void playMelody() {
// iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 18; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    // e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    // I bumped 1000 up to 1500 to slow the tempo. raise it more to slow it down
    int noteDuration = 1500/noteDurations[thisNote];
    tone(PIEZO_PIN, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    // stop the tone playing:

Have you by any chance got 2 tabs in the IDE, both with code in them ?

Yes one tab is the lasertripwire file and the other is the pitches file.

Is there a setup() function in both ?