Introduction: Moon With the Bat Silhouette

About: I work as software engineer in one of Bay Area (California) companies. Whenever I have a time I like to program micro controllers, build mechanical toys, and make some home improvement projects.

Everybody knows that full Moon attracts all supernatural forces. This project about the Bat flying in front of Moon, while Moon changes its phases. Eyes of the Bat accrue red accent when Moon is full.

Step 1: Components

Some of the project components you can see on the photo:

  • Twelve Backlight White LED modules (Adafruit Industrries)
  • Two RED super bright LEDs (SparkFun electronics)
  • Atmega328 micro controller (Mouser Electronics)
  • Fourteen resistors 270 Ohm, 1/4 Watt (Fry's)
  • Six pins header (Fry's)

In addition to this components project utilizes:

  • Two Plexiglas sheets 6*6*1/16" (I cut it out of old picture frame glass).
  • RadioShack Multipurpose PC Board Catalog #: 2760150.
  • Two fourteen pin sockets (not to solder micro controller directly, Fry's).
  • Some wires.
  • Heat shrinks.
  • A lot of Velcro self adhesive strips.

Step 2: Making the Moon Screen

  • Peel out reflective covers from the LED modules: it may loose some brightness, but becomes half transparent and obtains gloomy lights which suites Halloween decor well.
  • Cut Velcro strip, peel out adhesive protection form the hook part, put it alone the edge of Plexiglass sheet. Put six LED modules as shown on the photo.
  • Repeat the same for the bottom line of modules.
  • Attach loop strips to hook strips securing LED modules.
  • Put two more Velcro strips on the sides.

Step 3: Making the Moon Screen (2)

  • Peel out adhesive protection from the loop part of strips.
  • Put second Plexiglass sheet on top making the sandwich with LED modules inside.

Now there is sturdy LED screen. It is time to start wiring. Solder together all white LED cathodes.

Step 4: Circuit Diagram

Here is circuit diagram of the project. It is fairly simple.

Step 5: Assembling

Picture above shows assembled circuit.

Now is time to program it. Comment for the next step contains custom part of C source code of the project. In addition to custom code there are three header files included. Files io.h and interrupt.h comes with Atmel studio. File pt.h is protothread implementation taken form this source: It makes real time programming easy. Complied program written into the micro controller memory with the help of AVRISP unit (Atmel).

Step 6: Programming

/* moon.c */

#include <avr/io.h>
#include <avr/interrupt.h>
#include "./pt-1.4/pt.h" //

typedef enum {OUT_LOW, OUT_HIGH} OutputLevel;
volatile uint16_t pulses;

#define pinOut(port, bit, outLevel) \
(DDR##port |= (1 << ( DD##port##bit)));\
switch(outLevel) \
	case OUT_LOW: (PORT##port &= ~(1 << (PORT##port##bit))); break;\
	case OUT_HIGH: (PORT##port |= (1 << (PORT##port##bit))); break;\
void clearAll()
{	// set all outputs low
	DDRB = 0xFF;	PORTB = 0;
	DDRC = 0xFF;	PORTC = 0;
	DDRD = 0xFF;	PORTD = 0;
void activateTimer0()
	pulses = 0;
	TCCR0A=0;	// Normal operation
	TCCR0B=2;	// f divider 64  : about 2 ms for interrupt ...
	TIMSK0 = 1;	// for system clock f= 1Mhz (CKDIV8 set)
struct pt wpt; // protothread descriptor

int moonlight(struct pt* mlpt)
	PT_BEGIN(mlpt); 	// New Moon 
			pinOut(C,5,OUT_HIGH);	pinOut(B,1,OUT_HIGH);
			pinOut(D,0,OUT_HIGH);	pinOut(B,2,OUT_HIGH);
			pinOut(D,1,OUT_HIGH);	pinOut(B,0,OUT_HIGH);
		PT_YIELD(mlpt);	// First Quarter 		
			pinOut(D,2,OUT_HIGH);	pinOut(D,7,OUT_HIGH);
			pinOut(D,3,OUT_HIGH);	pinOut(D,6,OUT_HIGH);
			pinOut(D,4,OUT_HIGH);	pinOut(D,5,OUT_HIGH);
			pinOut(C,0,OUT_HIGH);	pinOut(C,1,OUT_HIGH);
		PT_YIELD(mlpt); 	// Full Moon + Red Eyes
			pinOut(C,0,OUT_LOW);	pinOut(C,1,OUT_LOW);
			pinOut(C,5,OUT_LOW);	pinOut(B,1,OUT_LOW);
			pinOut(D,0,OUT_LOW);	pinOut(B,2,OUT_LOW);
			pinOut(D,1,OUT_LOW);	pinOut(B,0,OUT_LOW);
		PT_YIELD(mlpt);		// Third Quarter
			pinOut(D,2,OUT_LOW);	pinOut(D,7,OUT_LOW);
			pinOut(D,3,OUT_LOW);	pinOut(D,6,OUT_LOW);
			pinOut(D,4,OUT_LOW);	pinOut(D,5,OUT_LOW);
		PT_RESTART(mlpt);	// New Moon
	uint16_t mod =pulses%750;
	if (mod == 0){
int main(void)
	PT_INIT(&wpt); // initiate protothread structure...
    while(1) { }

Step 7: Making the Front and Back Panels

I cut front and back cardboard panels with round opening and attached it to LED screen (again with Velcro). Cardboard strip on the back panel keeps red LEDs on the places where Bat eyes will be.

Step 8: Cutting the Bat Silhouette

There are a lot of tips online how to draw the Bat. In particular I found this link really useful:

Step 9: Done

Here the Bat (painted in black color) attached to the front of the Moon (with Velcro, of course). It is done now. Hang the Moon in your window to greet your Halloween guests.

Circuits Contest 2016

Participated in the
Circuits Contest 2016

Halloween Decor Contest 2016

Participated in the
Halloween Decor Contest 2016