No, not POWERED by the Nano, they have their own V+ Rail.
Like I wrote earlier, this was a proof of Concept HACK.
I am now rebuilding it so it can run in a showcase and be triggered hundreds of times a week without busting something...
4x Servos are 9g lightweights, they do the light work like eye-lids.
1x Servo is a 20Kg HD servo that runs the slide through a block/tackle and a Hair-tie as a return spring.
There are references to the SOUND Board, it is a generic module that plays sounds from an SD card when triggers are pulled low.
All of the Pins usage are described in the header.
The Sketch Follows.
//This is the Control Software for the Motion Controlled Door-Eye
//Designed by Bob Sisson 2022 modeled, sort-of, on the Star Wars Jabba Hut Door scene
//Programmed in Arduino for the Uno/Nano
// The Device is designed to:
//
// 1: Start everything retracted/closed (Recommend starting with SLED OFF)
// 2; Upon triggering
// 3: Open the IRIS (and wait for it to get all the way open)
// 4: Slid the SLED forward (and wait...)
// 5: Open the EyeLIDs
// 6: Move the Eye pseudorandomly U/D & R/L
// 7: BLINK
// 8: Move the Eye pseudorandomly U/D & R/L
// 9: Close Eyelids
// 10: Retract SLED
// 11: Close IRIS
// 12: Delay to prevent retriggering too soon
// 13: Goto 1:
//
// Arduino Pin Assignments
#include <Servo.h>
Servo IRIS; // create servo object to control a servo (IRIS)
Servo EyeLids; // create servo object to control a servo (EyeLids)
Servo EyeRL; // create servo object to control a servo (EyeRL)
Servo EyeUD; // create servo object to control a servo (EyeUD)
Servo SLED; // create servo object to control a servo (SLED)
//
int DEBUG = 1;
int pos = 20;
int eyeXpos = 90;
int eyeYpos = 90; // variables to store the Eye position
int ClosedPosition = 47; // only for Eyelids as they are BACKWARDS
int OpenPosition = 0;
int OpenSpeed = 1;
int CloseSpeed = 10;
int state = LOW; // by default, no motion detected
int value = LOW; // variable to store the sensor status (value)
int IrisMaxClosed = 350; //
int IrisMaxOpen = 2500; // these two setup values allow tuning of the iris
// Pin Assignments
int IrisPin = 2; //Pins are logical not Physical
int SledPin = 3;
int LidsPin = 4;
int RLPin = 5;
int UDPin = 6;
int wav00001 = 7;
int sensor = 8; // the pin that the sensor is atteched to
int wav00002 = 9;
int wav00003 = 10;
int wav00004 = 11;
int wav00005 = 12;
int LED = 13; // the pin that the Status LED is atteched to
int wav00006 = 14;
// BLANK Pin 15
void setup() {
Serial.begin(9600); // initialize serial for debugging via TERMINAL
if (DEBUG == 1) {
Serial.println("Begin of Setup"); //debug
}
// All the Declarations and Such
if (DEBUG == 1) {
Serial.print(" Iris is on pin ");
Serial.println(IrisPin);
Serial.print(" Sled is on pin ");
Serial.println(SledPin);
Serial.print(" Lids are on pin ");
Serial.println(LidsPin);
Serial.print(" R/L is on pin ");
Serial.println(RLPin);
Serial.print(" U/D is on pin ");
Serial.println(UDPin);
}
pinMode(wav00001, OUTPUT);
digitalWrite(wav00001, HIGH);
pinMode(wav00002, OUTPUT);
digitalWrite(wav00002, HIGH);
pinMode(wav00003, OUTPUT);
digitalWrite(wav00003, HIGH);
pinMode(wav00004, OUTPUT);
digitalWrite(wav00004, HIGH);
pinMode(wav00005, OUTPUT);
digitalWrite(wav00005, HIGH);
pinMode(LED, OUTPUT);
pinMode(sensor, INPUT); // Motion Sensor Pin
IRIS.attach(IrisPin, IrisMaxClosed, IrisMaxOpen); // attaches the Iris
EyeLids.attach(LidsPin); // attaches the Eyelid Servo
EyeRL.attach(RLPin); // attaches the Right-Left Servo
EyeUD.attach(UDPin); // attaches the Up-Down Servo
SLED.attach(SledPin); // attaches the Sled
// Setup Start Condition outside LOOP
SLED.write(0); // Make sure SKLED is fully retracted before closing Iris
delay(1000);
IRIS.write(0); // tell servo to go to ClosedPosition
EyeLids.write(ClosedPosition); // tell servo to go to Middle
EyeRL.write(90); // tell servo to go to Middle
EyeUD.write(90); // Basically center the Eye
digitalWrite(LED, LOW); // turn LED OFF
if (DEBUG == 1) {
Serial.println("End of Setup, pausing 5 seconds");
} //debug
delay(5000);
}
// End Setup -----------------------------------------------------------------------
// main section-------------------------------------------------------------------
void loop() {
if (DEBUG == 1) {
Serial.println("Top of Main Section"); //debug
}
// Start of main loop--------------
// The first Section is the MOTION DETECTION followed by the Main routine
value = digitalRead(sensor); // read sensor value
if (value == HIGH) // check if the sensor is HIGH/Motion
{ //run main routine
//Main Routine ------------------
if (DEBUG == 1) {
Serial.println("Motion detected!"); //debug
}
digitalWrite(LED, HIGH); // turn LED ON
digitalWrite(wav00001, LOW); // start first sound byte
delay(50);
digitalWrite(wav00001, HIGH);
// delay to let wav00001 play
delay(4000);
//Open IRIS
//THEN Move Sled
if (DEBUG == 1) {
Serial.println("Starting Open Iris section"); //debug
}
IRIS.write(180);
delay(750); // wait for iris to open
SLED.write(270);
delay(1500); // wait for sled to finish moving
if (DEBUG == 1) {
Serial.println("Starting Open Eye section"); //debug
}
OpenEyeSlow();
//Eye Should be OPEN, this is after Iris Open and Sled Forword
// Total Eye Open/forward time should be around 10 seconds
// With an Eye-BLINK around the middle of the time
digitalWrite(wav00003, LOW); // start second sound byte
delay(50);
digitalWrite(wav00003, HIGH);
delay(1000);
//Swing Right
for (eyeXpos = 90; eyeXpos <= 130; eyeXpos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
EyeRL.write(eyeXpos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15 ms for the servo to reach the position
}
// Swing Left past center
for (eyeXpos = 130; eyeXpos >= 45; eyeXpos -= 1) { // goes from 180 degrees to 0 degrees
if (eyeXpos == 90) {
BlinkEye();
}
EyeRL.write(eyeXpos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15 ms for the servo to reach the position
}
delay(500);
//Swing back to center FAST
for (eyeXpos = 45; eyeXpos <= 90; eyeXpos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
EyeRL.write(eyeXpos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15 ms for the servo to reach the position
}
delay(3500);
// Close Eye pull back sled and close Iris
if (DEBUG == 1) {
Serial.println("Starting Close Eye section"); //debug
}
CloseEyeSlow();
SLED.write(0);
delay(1100); // wait for sled to finish moving
IRIS.write(0);
EyeRL.write(90); // tell servo to go to position in variable 'pos'
EyeUD.write(90); // Basically center the Eye
digitalWrite(wav00004, LOW); // start forth sound byte
delay(50);
digitalWrite(wav00004, HIGH);
}
// End MOTION Sensed Routine
else
// Motion stopped routine
{
digitalWrite(LED, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
if (state == HIGH) {
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
delay(5000); //Delay so it won't immediatly re-trigger
}
//End of main loop, indivicual functions follow ----------------------------------------------------------------------------------------------------------------------------------------------------
void OpenEye() {
EyeLids.write(OpenPosition); // tell servo to go to position in variable 'pos'
}
void CloseEye() {
EyeLids.write(ClosedPosition); // tell servo to go to position in variable 'pos' // waits 15ms for the servo to reach the position
}
void BlinkEye() {
ClosedPosition = ClosedPosition - 7; // so the lids to crash TOO HARD
CloseEye();
delay(300);
ClosedPosition = ClosedPosition + 7; // and back so they close propperly at the end
OpenEye();
}
void OpenEyeSlow() // goes from ClosedPosition to OpenPosition at Speed OpenSpeed
{
for (pos = ClosedPosition; pos >= OpenPosition; pos -= 1) {
// goes from 0 degrees to 180 degrees
// in steps of 1 degree
EyeLids.write(pos); // tell servo to go to position in variable 'pos'
delay(OpenSpeed); // waits for the servo to reach the position
}
digitalWrite(LED, HIGH); // Show EyeLids OPEN/ON
}
// end OpenEyeSlow
void CloseEyeSlow() // goes from OpenPosition to ClosedPosition at Speed OpenSpeed
{
for (pos = OpenPosition; pos <= ClosedPosition; pos += 1) { // goes from 180 degrees to 0 degrees
// in steps of 1 degree
EyeLids.write(pos); // tell servo to go to position in variable 'pos'
delay(CloseSpeed); // waits for the servo to reach the position
}
digitalWrite(LED, LOW); // Show EyeLids CLOSED/OFF
}
// end CloseEyeSlow