Hello Arduino community !
I’m Lily and I am a complete beginner with programming. It would be awesome if I could benefit from some guidance to finish my ongoing project: a lion head I made with resin, with animatronic eyes and eyelid (see pictures).
I took inspiration from other projects and tried to adapt it to mine. I went as far as I could in the process of programming and creating a circuit, and having my work checked would be truly great (I don't want to burn or break something...).
PROJECT DESCRIPTION
The eyes mechanism is 3D printed and uses 2 servos (picture above), that allow the eyes to move in all directions (x and y axis simultaneously, one servo per axis). It is controlled by a small joystick. The goal:
- Pushing the joystick forward makes the lion look upward
- Pushing the joystick backward makes the lion look downward
- Pushing the joystick on the left (respectively right) makes the lion look on the left (respectively right).
For the eyelids, each eyelid has its own servo and are controlled by the same joystick used for the eyes. The goal:
- Pressing once on the joystick closes both eyelids simultaneously, and then those eyelids reopen directly after that (without pushing on the joystick again)
- If that is possible, when the joystick remains pressed, the eyelids remain closed as long as the joystick is being pressed on (if too complicated code-wise, never mind)
I did not build the eyelid mechanism yet, but I can make the respective servos move without being attached to it. I will personally have to adjust the angles of rotation of the servos later on for both eyes and eyelids to match with the expected range of movement of the mechanisms.
Finally, there is a switch to turn the circuit off/on.
WHAT WOULD BE HELPFUL FOR ME
- My code: is it correct? Can it be optimized (= rewrite in a more effective way)?
- My circuit: is it proper? Are they components that need to be added or moved? Are the connections in the right place?
- The battery to use: is my calculation to find that out correct?
COMPONENT INFOS
Arduino Nano (A000005)
- Operating voltage: 5 V
- Input voltage: 7-12 V
- Power consumption: 19 mA
- DC current per O/I pins: 40 mA
Micro servo (9g) SG90
- Voltage: 4,8-6V
- Limit angle: 120°
- Work speed (empty): 0,12 s/60° (4,8 V) and 0,13 s/60° (6 V)
- Idle current: 5 mA (4,8 V) or 6 mA (6 V)
- No load running current : 100 mA (4,8 V) or 120 mA (6 V)
- Stall current: 700 mA (4,8 V) or 800 mA (6 V)
THE CIRCUIT
To make it "visually easier", I took a shot of one component individually then the full circuit (PDF normally attached to this post)
Circuit pictures.pdf (683.4 KB)
.
MY BATTERY CALCULATION
Arduino (x 1): max voltage of 5, or 12 V? (not sure of this)
Current: 19 mA
Servo (x 4): max voltage 6 V
Current: 800 mA
Thus 800 x 4 + 19 = 3219 mA = 3,2 A
Battery: 6 V with 3,2 A. Is a 6V battery good to use?
CODE
//add the servo library
#include <Servo.h>
//define our servos
Servo servo1; //EYES horizontal movement
Servo servo2; //EYES vertical movement
Servo servo3; //LEFT EYELID
Servo servo4; //RIGHT EYELID
//define joystick pins
int joyX = 0; //analog pin connected to X output
int joyY = 1; //analog pin connected to Y output
int SWpin = 2; //digital pin connected to switch output
//variable to read the values from the analog pins (X et Y)
int joyVal;
//variable to read the values from the digital pin (switch)
int SWval;
void setup()
{
//attaches our servos for EYES on pins PWM 3-5
servo1.attach(3);
servo2.attach(5);
//attaches our servos for EYELIDS on pins 6-7
servo3.attach(6);
servo4.attach(7);
pinMode(SWpin, INPUT);
}
void loop()
{
//read the value of joystick (between 0-1023) for EYES
joyVal = analogRead(joyX);
joyVal = map(joyVal, 0, 1023, 0, 180); //servo value between 0-180
servo.write(joyVal); //set the servo position according to the joystick value
joyVal = analogRead(joyY);
joyVal = map(joyVal, 0, 1023, 0, 180);
servo2.write(joyVal);
//read the value of joystick for EYELIDS
SWval = digitalRead(SWpin);
if (SWval == 1) // or while?
{
servo3.write(90); //angle to run to close the eyelid: to be adjusted once connected to the mechanism
servo4.write(90);
}
else
{
servo3.write(0);
servo4.write(0);
}
delay(15);
}
I can’t wait to learn more and I hope that this project will look interesting for some. Thanks a lot!