Halloween Forum banner
1 - 1 of 5 Posts

· Registered
Joined
·
130 Posts
I have only programmed one arduino for my groundbreaker, the sketch file is listed below. Similar to what you want to do, it is paired with a relay board and kicks off a mini SD card MP3 player for the sound effects (also using a powered speaker), leds behind his mask and of course the left and right arm movements. The trigger is a PIR sensor. I am sure there is a more elegant programming solution than mine, but it works. Hope this helps.


int RightArmPin = 3; //This is the output pin for Solenoid 1
int LeftArmPin = 4; //This is the output pin for Solenoid 2
int speakerPin = 5; //This is the ouptut pin to activate the sound
int lightPin = 6; //This is the output pin for light effects
int motionPin = 7; //This is the input pin for the motion detector

int motiondetected = LOW; //Sets motion detector to off initially


void setup() {
// put your setup code here, to run once:
pinMode(RightArmPin, OUTPUT); //Sets pin as an output
pinMode(LeftArmPin, OUTPUT); //Sets pin as an output
pinMode(speakerPin, OUTPUT); //Sets pin as an output
pinMode(lightPin, OUTPUT); //Sets pin as an output
pinMode(motionPin, INPUT); //Sets pin as an input

delay(7000); //Allows motion sensor to calibrate
digitalWrite(RightArmPin, LOW); //RightArm down
digitalWrite(LeftArmPin, LOW); //LeftArm down
digitalWrite(speakerPin, LOW); //set speaker off
digitalWrite(lightPin, LOW); //set light off
}

void loop() {
// put your main code here, to run repeatedly:
motiondetected = digitalRead(motionPin);
if (motiondetected == HIGH)
{
digitalWrite(speakerPin, HIGH); //Speaker is ON
digitalWrite(lightPin, HIGH); //effect lighting is ON

ArmMotion1 ();
delay(3000);

ArmMotion2 ();
delay(5000);

}

// reset all to start position
digitalWrite(RightArmPin, LOW); //RightArm down
digitalWrite(LeftArmPin, LOW); //LeftArm down
digitalWrite(speakerPin, LOW); //Speaker is OFF
digitalWrite(lightPin, LOW); //effect lighting is OFF
digitalWrite(motiondetected, LOW); //reset motion detector to OFF


}

void ArmMotion1() {
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(1000); //Wait 1 second
digitalWrite(LeftArmPin, HIGH); //LeftArm up
delay(300); //Wait 0.3 seconds
digitalWrite(LeftArmPin, LOW); //LeftArm down
delay(300); //Wait 0.3 second
digitalWrite(LeftArmPin, HIGH); //LeftArm up
delay(2000); //Wait 2 second
digitalWrite(RightArmPin, LOW); //RightArm down
delay(1000); //Wait 1 second
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(1000); //Wait 1 second
digitalWrite(LeftArmPin, LOW); //LeftArm down

digitalWrite(RightArmPin, LOW); //RightArm down
delay(500); //Wait 0.5 second
digitalWrite(LeftArmPin, HIGH); //LeftArm up
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(750); //Wait 0.75 second
digitalWrite(LeftArmPin, LOW); //LeftArm down OFF
delay(200); //Wait 0.2 second
digitalWrite(LeftArmPin, HIGH); //LeftArm up
digitalWrite(RightArmPin, LOW); //RightArm down
delay(100); //Wait 0.1 seconds
digitalWrite(LeftArmPin, LOW); //LeftArm down
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(200); //Wait 0.2 second
digitalWrite(LeftArmPin, HIGH); //LeftArm up
digitalWrite(RightArmPin, LOW); //RightArm down
delay(100); //Wait 0.1 seconds
digitalWrite(LeftArmPin, LOW); //LeftArm down
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(500); //Wait 0.5 seconds
digitalWrite(RightArmPin, LOW); //RightArm down
delay(500); //Wait 0.5 second
digitalWrite(LeftArmPin, HIGH); //LeftArm up
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(750); //Wait 0.75 seconds
digitalWrite(LeftArmPin, LOW); //LeftArm down
digitalWrite(RightArmPin, LOW); //RightArm down
delay(200); //Wait 0.2 second
digitalWrite(LeftArmPin, HIGH); //LeftArm up
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(100); //Wait 0.1 seconds
digitalWrite(RightArmPin, LOW); //RightArm down
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(200); //Wait 0.2 second
digitalWrite(RightArmPin, LOW); //RightArm down
delay(300); //Wait 0.3 seconds
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(200); //Wait 0.2 second
digitalWrite(RightArmPin, LOW); //RightArm down
delay(300); //Wait 0.3 seconds
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(200); //Wait 0.2 second
digitalWrite(LeftArmPin, HIGH); //LeftArm up
digitalWrite(RightArmPin, LOW); //RightArm down
delay(300); //Wait 0.3 seconds
digitalWrite(RightArmPin, HIGH); //RightArm up
delay(100); //Wait 0.1 seconds
digitalWrite(LeftArmPin, LOW); //LeftArm down
delay(300); //Wait 0.3 seconds
digitalWrite(RightArmPin, LOW); //RightArm down

digitalWrite(LeftArmPin, HIGH); //LeftArm up
delay(100); //Wait 0.1 seconds
digitalWrite(LeftArmPin, LOW); //LeftArm down
}

void ArmMotion2() {
digitalWrite(RightArmPin, HIGH); //RightArm up

digitalWrite(LeftArmPin, HIGH); //LeftArm up

delay(2000); //Wait 5 seconds

digitalWrite(LeftArmPin, LOW); //LeftArm down
delay(300); //Wait 0.3 seconds
digitalWrite(RightArmPin, LOW); //RightArm down

delay(2000); //Wait 5 seconds
digitalWrite(RightArmPin, HIGH); //RightArm up
digitalWrite(LeftArmPin, HIGH); //LeftArm up

}
 
1 - 1 of 5 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top