After finishing Robo-dentures V1, i realized the poor fellow couldn’t see the horror i had created, therefore i decided to make a version 2 with eyes. Since lock-down was still underway the upgrades were still sources from the 2dollar store and supermarket. And yeah i know it looks more like it came out of a 5-year old’s nightmare than a adult person trying to learn electronics, but i don’t care, i had fun 😝
I removed the eyeballs, and this time instead of attaching the servo inside of the mouth and pushing the top up, i glued the top to a rigid frame of pop-sickle sticks, and instead attached a metal wire to the bottom part that would pull it open and push it back closed (bit hard to see from the image maybe). Next i got some cheap mechano box and made a little frame for the ping-pong balls, put a screw through the balls and attached some tie wraps to the top of the balls. Now the metal frame i connected so that the servos move them on the horizontal plane, and the tie wraps push and pulled the eyes on the vertical plane, make semi-3D movements.
The parts were wired up as follows (to the best of my recollection). This time a button was used for the mouth, and a little joystick unit is used for the x and y movement of the eyes. The x-axis was just used for both servo’s as they rotate at the same angle at the same time, since the tie wraps were secured it wouldn’t be able to make it go cross-eyed anyway, that would require a different setup. Since the joystick and servo’s claim to work better on 5V, i used a cheap elegoo breadboard power adapter, it provides a 5v (left) and 3v (right) line.
And the following code was used to run everything.
#include <Servo.h>
Servo myservo_mouth; // create servo object to control a servo
Servo myservo_eyes_x; // create servo object to control a servo
Servo myservo_eyes_y; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos_mouth = 0; // variable to store the servo position for mouth
int pos_eyes_x = 45; // variable to store the servo position for eyes (left-right)
int pos_eyes_y = 45; // variable to store the servo position for eyes (up-down)
int val_y = 0;
int val_x = 0;
const int joystick_y = 14; //pin for the joystick, only X is attached
const int joystick_x = 34; //pin for the joystick, only X is attached
// Joystick min max = x[0,4095],y[0,4095]
const int buttonPin = 35; // the number of the pushbutton pin
int buttonState = 0;
char foo [64];
void setup() {
myservo_mouth.attach(13); // attaches the servo on pin 13 to the servo object
myservo_mouth.write(pos_mouth);
myservo_eyes_x.attach(27);
myservo_eyes_x.write(pos_eyes_x);
myservo_eyes_y.attach(26);
myservo_eyes_y.write(pos_eyes_y);
pinMode(joystick_y, INPUT);
pinMode(joystick_x, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
// read analog value from the potentiometer
// int val = analogRead(joystick);
val_y = analogRead(joystick_y);
val_x = analogRead(joystick_x);
buttonState = digitalRead(buttonPin);
sprintf(foo,"val_y: %i val_x: %x",val_y,val_x);
Serial.println(foo);
if (val_y > 3250) {
for (pos_eyes_y = pos_eyes_y; pos_eyes_y <= 160; pos_eyes_y += 1) { // goes from 0 degrees to 180 degrees
myservo_eyes_y.write(pos_eyes_y); // tell servo to go to position in variable 'pos'
delay(2);
}
}
if (val_y < 1950) {
for (pos_eyes_y = pos_eyes_y; pos_eyes_y > 30; pos_eyes_y -= 1) { // goes from 0 degrees to 180 degrees
myservo_eyes_y.write(pos_eyes_y); // tell servo to go to position in variable 'pos'
delay(2);
}
}
if (val_x > 3250) {
for (pos_eyes_x = pos_eyes_x; pos_eyes_x <= 120; pos_eyes_x += 1) { // goes from 0 degrees to 180 degrees
myservo_eyes_x.write(pos_eyes_x); // tell servo to go to position in variable 'pos'
delay(2);
}
}
if (val_x < 1950) {
for (pos_eyes_x = pos_eyes_x; pos_eyes_x > 40; pos_eyes_x -= 1) { // goes from 0 degrees to 180 degrees
myservo_eyes_x.write(pos_eyes_x); // tell servo to go to position in variable 'pos'
delay(2);
}
}
if (buttonState == HIGH) {
for (pos_mouth = pos_mouth; pos_mouth <= 160; pos_mouth += 1) { // goes from 0 degrees to 180 degrees
myservo_mouth.write(pos_mouth); // tell servo to go to position in variable 'pos'
delay(2);
}
}
if (buttonState == LOW) {
for (pos_mouth = pos_mouth; pos_mouth >= 0; pos_mouth -= 1) { // goes from 0 degrees to 180 degrees
myservo_mouth.write(pos_mouth); // tell servo to go to position in variable 'pos'
}
}
}
Since i got cheap joysticks, their neutral state didn’t give a fixed value. The joystick is supposed to have a range of 0-4095, therefore the center should be ~2047, however i found that mine hovered more around the 2500 mark and swinging 500 up and down, so i set the threshold a bit wider (1950 before going negative, and 3250 before going positive). The end result was kinda funny and creepy and i think for a V2 it was a success, learned a lot, and a lot of points to improve on for sure 😃