Very excited to join the community! I'm a newb (charitably) with no programming experience, but would like to create a singular sketch from 4 separate sketches and would really appreciate some help. I have an Arduino UNO and am trying to use a break in an IR eye beam to randomly trigger one of five servo arms to rotate 120 degrees and back three times and finally time-out for 60 minutes before returning to a "trigger-able" state.
I've started to modify the code below, but would appreciate help with syntax and to let me know if I'm moving in the right direction. Thank you!!
IR Breakbeam
/*
IR Breakbeam sensor demo!
// Arduino | IR Breakbeam Sensors | Adafruit Learning System
*/
#define LEDPIN 13
// Pin 13: Arduino has an LED connected on pin 13
// Pin 11: Teensy 2.0 has the LED on pin 11
// Pin 6: Teensy++ 2.0 has the LED on pin 6
// Pin 13: Teensy 3.0 has the LED on pin 13
#define SENSORPIN 4
// variables will change:
int sensorState = 0, lastState=0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup
Serial.begin(9600);
}
void loop(){
// read the state of the pushbutton value:
sensorState = digitalRead(SENSORPIN);
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState == LOW) {
// turn LED on:
digitalWrite(LEDPIN, HIGH);
}
else {
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
Random Number Generation
long randNumber;
void setup() {
Serial.begin(9600);
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
}
void loop() {
// print a random number from 0 to 4
randNumber = random(5);
Serial.println(randNumber);
Servo Movement
// Include the Servo library
#include <Servo.h>
// Declare the Servo pin
int servoPin = randNumber;
// Create a servo object
Servo Servo1;
void setup() {
// We need to attach the servo to the used pin number
Servo1.attach(servoPin);
}
void loop(){
// Make servo go to 0 degrees
Servo1.write(0);
delay(500);
// Make servo go to 120 degrees
Servo1.write(120);
delay(1000);
// Make servo go to 0 degrees
Servo1.write(0);
delay(500);
// Make servo go to 120 degrees
Servo1.write(120);
delay(1000);
// Make servo go to 0 degrees
Servo1.write(0);
delay(500);
// Make servo go to 120 degrees
Servo1.write(120);
delay(1000);
}
60 minute timeout
//60 minute timeout
delay(3600000)

