--- /dev/null
+# -*- Makefile -*-
+
+PROJECT := fan_control
+DEVICE := attiny85
+F_CPU := 8000000UL
+INC := -I.
+AVRDUDE := avrdude -c usbasp -p $(DEVICE)
+
+CSRCS = $(PROJECT).c
+OBJS = $(CSRCS:.c=.o)
+
+CC := avr-gcc
+LD := avr-gcc
+OBJCOPY := avr-objcopy
+RM := del >NUL
+CFLAGS :=-Wall -Wmissing-prototypes -Wcast-align -Wshadow \
+ -std=gnu99 -fshort-enums -pedantic-errors -Os -mcall-prologues \
+ -mmcu=$(DEVICE) -DF_CPU=$(F_CPU)
+LDFLAGS := -Wall -mmcu=$(DEVICE)# -Wl,-v
+LIBS :=
+
+V := @
+Q := $(V:1=)
+QUIET_CC = $(Q:@=@echo CC $@ &)$(CC)
+QUIET_LD = $(Q:@=@echo LD $@ &)$(LD)
+QUIET_OBJCOPY = $(Q:@=@echo OBJCOPY $@ &)$(OBJCOPY)
+QUIET_AVRDUDE = $(Q:@=@echo AVRDUDE $@ &)$(AVRDUDE)
+
+all: $(PROJECT).hex
+
+%.hex: %.elf
+ $(QUIET_OBJCOPY) -j .text -j .data -O ihex $< $@
+
+%.elf: $(OBJS)
+ $(QUIET_LD) $(LDFLAGS) $^ $(LIBS) -o $@
+
+%.o: %.c
+ $(QUIET_CC) $(CFLAGS) $(INC) -c $<
+
+flash: $(PROJECT).hex
+ $(QUIET_AVRDUDE) -U flash:w:$<:i
+
+clean:
+ -@$(RM) $(addprefix $(PROJECT), .elf .hex)
+
+.PHONY: clean
+.SECONDARY: $(addsuffix .elf, $(PROJECT)) $(OBJS)
+
+# Fuse high byte:
+# 0xdd = 1 1 0 1 1 1 0 1
+# ^ ^ ^ ^ ^ \-+-/
+# | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
+# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
+# | | | +-------------- WDTON (watchdog timer always on -> disable)
+# | | +---------------- SPIEN (enable serial programming -> enabled)
+# | +------------------ DWEN (debug wire enable)
+# +-------------------- RSTDISBL (disable external reset -> enabled)
+#
+# Fuse low byte:
+# 0xe1 = 1 1 1 0 0 0 0 1
+# ^ ^ \+/ \--+--/
+# | | | +------- CKSEL 3..0 (clock selection -> HF PLL)
+# | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
+# | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
+# +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
+# For 16.5MHz internal: -U hfuse:w:0xdd:m -U lfuse:w:0xe1:m
+# For 12MHz crystal: -U hfuse:w:0xdd:m -U lfuse:w:0b11111111:m
+# For 8MHz internal: -U hfuse:w:0xd7:m -U lfuse:w:0xe2:m
+fuse:
+ $(AVRDUDE) -U hfuse:w:0xd7:m -U lfuse:w:0xe2:m
--- /dev/null
+Fan Control Board
+
+This is a board to control a small 24V, 33mA computer cooling fan.
+The requirement is to toggle the fan every 15 minutes.
+
+The curcuit is an ATtiny85 with 78L05 to drop the 12V input to regulated
+5V and the microcontroller counts seconds then asserts the gate of a
+2N7000 MOSFET to turn the fan on or off. MOSFET is on PB3 and an LED is on
+PB2. The other pins are unused.
+
--- /dev/null
+/* fan_control - Copyright (c) 2016 Pat Thoyts <patthoyts@users.sourceforge.net>
+ *
+ * ATtiny85 with LED on pin PB2 and a 2N7000 MOSFET on PB3 which controls
+ * a computer fan run off 12V supply. Toggle the fan every 15 minutes.
+ * Start with the fan ON
+ *
+ */
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/power.h>
+#include <avr/sleep.h>
+#include <avr/wdt.h>
+#include <util/delay.h>
+
+#define LED_PIN PB2
+#define FAN_PIN PB3
+
+int
+main(void)
+{
+ unsigned long seconds = 0;
+ uint8_t counter = 0;
+
+ wdt_enable(WDTO_1S);
+
+ power_adc_disable();
+
+ /* set all unused pins high-z, led and fan pins output and low */
+ DDRB = _BV(DDB2) | _BV(DDB3);
+ PORTB = ~(_BV(PB2));
+
+ while (1)
+ {
+ _delay_ms(250);
+ wdt_reset();
+ PORTB ^= _BV(PB2); /* toggle led */
+ if (++counter == 4)
+ {
+ if (++seconds == (60 * 15)) /* every 15 mins */
+ {
+ PORTB ^= _BV(PB3); /* toggle fan */
+ seconds = 0;
+ }
+ counter = 0;
+ }
+ }
+}