Some Clowning Around with an Arduino

in STEMGeeks3 years ago

I was recently in a nearby Goodwill where I came upon these really neat clown paintings. I am well aware that the words "neat," "clown," and "painting" might not enter most people's vocabulary but it certainly entered mine. Honestly, my very first thought upon seeing these was, "Neat! But I can make them better."

So I bought them. $3.00 each. $6.00 total. Perhaps the best $6.00 purchase I have made in the recent past.

Clown One

20210630_202009.jpg

Now, I'm not an artist, but I do like to dabble. I am a techno-nerd and have a strong belief that technology can be used to better ourselves and, in this case, can be used to improve our art. Both of these clowns were in dire need of some Arduino assistance.

This particular elegant, serene looking clown has the nicest almond shaped eyes was my starting point. I could do something with those eyes. I was thinking something like a Scooby Doo painting, where the eyes look back and forth at you.

What I wanted to do was rig up an arduino and stepper motors so that, when triggered, the eyes would shift around. To accomplish this I needed a few items:

Requirements

  • An arduino to run the code
  • Two stepper motors - one for each eye
  • Spherical eyes
  • External power to run the stepper's
  • Some sort of trigger to initiate the eye movement

Luckily for me, all of this is easy to come by. I happened to have everythign I needed already in my workshop:

  • An arduino nano - this would be the brains of the painting
  • Two spherical eyes (these used to be frozen ice-alternatives, but they have since lost their iciness).
  • External AA battery pack - this is a necessity. An arduino can somewhat drive one servo motor for testing purposes, but cannot supply enough power to drive two.
  • A button - ideally I would use a motion detector but, I am shamed to admit, I do not have any motion detection sensors in the house, so I'm making do with a button.
  • Breadboard - this will connect all the various wires together
  • Power supply module - this will distribute power to where it is needed; it will power both the servo motors and the arduino.

Each servo would be attached to an eye. When the button is pressed the servos would shift and, in turn, cause the eyes to shift. I could probably do something with only one servo and rig it up to move both the eyes, but servo's are cheap and I am lazy; it's easier to drive each eye with one servo each.

The nice thing about the Arduino Nano and the power distribution piece is that they both plug very nicely onto a breadboard. The back of my painting now looks like this. It's difficult to tell in the picture, but the power (red wires) are all connected to the power distribution module, which in turn is powered by the external battery pack. The only exception is the usb cable from the power distributer to the arduino itself.

20210705_152801.jpg

The button uses a 10k resistor, because it simply does not need to draw 5volts of power.

The front now looks like this. There, this is better.

20210703_230001.jpg

I have noticed that the eyes move in different degrees; I've since corrected this in the code

(animated gif)

20210705_155025.gif

The code for this particular project is pretty straightforward. I've attached the button to pin 6 and the eyes to pins 2 and 4. These are the digital pins so, in the case of the button at least, it's simply ON or OFF (or HIGH/LOW using the correct parlance).

#include <Servo.h>


Servo lefteye;
Servo righteye;
const int button = 6;
int buttonState = 0;


void setup() {
  // put your setup code here, to run once:
  // set up the eyes
  lefteye.attach(2);
  righteye.attach(4);
  lefteye.write(90);             
  righteye.write(90);   
  // set up the button
  pinMode(button, INPUT);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
  // Check for button press
  buttonState = digitalRead(button);

  if (buttonState == HIGH) {
    lefteye.write(90);
    righteye.write(90);
    delay(500);
    lefteye.write(135);
    righteye.write(135);
    delay(1000);
    lefteye.write(90);
    righteye.write(90);
    delay(1000);
    lefteye.write(45);
    righteye.write(45);
    delay(1000);
    lefteye.write(90);
    righteye.write(90);
    delay(1000);
    lefteye.write(130);
    righteye.write(130);
    delay(1000);
    lefteye.write(90);
    righteye.write(90);
    delay(1000);
    lefteye.write(60);
    righteye.write(60);
    delay(1000);
    lefteye.write(90);
    righteye.write(90);
    delay(1000);
    lefteye.write(90);
    righteye.write(90);

  }

}

This is pretty straightforward code. If I was going to do anything more with the eyes I would write methods for them and call the methods with incremental degrees of shifting, but I don't need to get fancy for this.

Clown Two: Devil Clown

For my second clown I wanted something a little bit different than the first and, figuring that this clown was a sad clown, I felt that he might be hiding something; behind that sad, puppy dog face lies the soul of a dark creature.

20210705_205833.jpg

For this clown I felt that what I wanted was for the eyes to glow red. LEDs shine right through the canvas, and red ones are perfect, so I was able to rig up some tape on the back to hold the LED's where I wanted them to be.

But I did not want them to just be on. I wanted them to pulse, slowly on to full brightness, then slowly off. This required treating a digital port like an analogue one; thankfully, the Arduino's PWM (Pulse-Width Modulation) pins allow the digital device attached to be written to as if it was analogue with the analogWrite function. Pretty cool!

In the case of an LED, the LED can be assigned a brightness value of 0 (for "off") up through 255 (for "full brightness"). Anything in between acts as a dimmer.



#define LEFTEYE 3
#define RIGHTEYE 5
int brightness = 0;
int fadeAmount = 1;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LEFTEYE, OUTPUT);
  pinMode(RIGHTEYE, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {

  analogWrite(LEFTEYE, brightness);
  analogWrite(RIGHTEYE, brightness);

  brightness = brightness + fadeAmount;

  //delay(5);

  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount;
  }

  delay(30);
                       
}

The code above shows that the brightness level increases by a value of 1 every 30 cycles. I had to play with both these numbers to get the fade in/out the way I wanted; it is now a slow, steady pulse that shows up when you're not expecting it, then slowly fades away. No animated gif of the effect, but this is what the clown looks like with full brightness:

20210705_213913.jpg

The setup on the back of this painting is much more simple than the other. It turns out I did not have an additional AA battery pack, but a 9v works just as well with this simple solution:

20210705_213854.jpg

Seriously, Halloween can't come soon enough. I need some more clown paintings.

(p.s., I have since received a set of motion sensors, so I will be able to refit these paintings to kick off when they sense motion)


(c) All images and photographs, unless otherwise specified, are created and owned by me.
(c) Victor Wiebe


About Me

Amateur photographer. Wannabe author. Game designer. Nerd. 
General all around problem-solver and creative type.

My Favourite Tags

IUR5Qh1mwwwiebe.gif

Sort:  

This is so creatively AMAZING!
I have an Arduino that I've yet to use, it came in a beginner starter kit and I'm actually very much looking forward to playing around with it.
I have all the time in the world with a ton of projects and just haven't gotten around to it yet 😄

I know who to come to if I have any questions when I start..

If you can find any 18650 LI ION cells either in your old electronics laying around or can get some from anyone you might know, they make a very nice replacement to standard AA batteries, given that they can be recharged :)

Can't wait to see what else you make. Have you incorporated any of the 3D printing in with your Arduino projects, or planning to?

Ooooh, I hadn't even thought of digging through old electronics for those batteries. Great idea! That might end up being my weekend project! 😁

I have a couple other projects in various stages, though the next one is likely going to be raspberry pi based instead so it can perform some more functions, like a camera.

No, nothing with the 3d printer yet. I'm still in the embryonic stages of learning how to best use it, and my 3d modelling skills are still in the 2d stage. 😂. But I do definitely want to do something. I've had in my mind for some time building a candy dispensing machine, and I think an arduino and a 3d printed contraption would be a neat fit. I just need to learn Blender.