Fountain PWM

Views: 2666 Difficulty: 2 Status: Development

Precise analog control of a fountain or any 12V motor with this simple board.

A Tip120 NPN Transistor and attiny microcontroller combine to give precise control over a power 12V pump motor. The on board potentiometer lets you control the pulse width modulation (PWM) that is driving the motor. You can also plug your own analog sensors into the broken out pins. We use this pump from sparkfun. The is also a nice tutorial on this type of circuit on NYU's ITP site.


The front and back of the fountain PCB. If you look close you can see quadruple reflection.

Fountain Video

Watch the precision PWM control of the fountain.

Soldering Video

This time-lapse video shows the soldering process and the assembly of the board. The actual process takes about 30 minutes but here you can watch it in 45 seconds.

AVR Code

Yikes raw AVR code! If you love arduino (and hate data sheets) like us then the sight of this raw AVR code might make you shudder. Don't fear its just annoying arbitrary keywords for all the comfy and meaningful arduino functions. Like instead of saying analogWrite you have to actually set the PWM register by assigning it some value as in:
OCR0A = value;
Now there is a nice library to control Attiny's from arduino's IDE environment, but we didn't know of it when we wrote this code.
 * LucidTronix PWM Fountain -
 * PWM control of a TIP120 transistor controlling a pump
 * analog fountain code

// If clock speed isn't set in the project settings then it is set here
#ifndef F_CPU
#define F_CPU 1000000UL // 1 MHz
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>

//PWM on (OCR0A)
#define LED 0

// Potentiometer at PB2, (ADC1)
#define POT 2
int main(void)
	// PB2 in, others out
	DDRB = 0b11011;
	PORTB = 0x00;	
	// Value for the register
	// "value" equals power of the pump
	// 0 = off | 255 = full brightness
	uint8_t value = 0;
	// Initialize PWM
	// 8-bit PWM, Phase correct
	// 8 bits give us 256 levels of brightness
	TCCR0A |= (1<<WGM00);
	// Clear OC0A/OC0B on Compare Match
	// Set OC0A/OC0B at BOTTOM (non-inverting mode)
	TCCR0A |= (1<<COM0A1);
	// Set prescaler to 8
	// 1 MHz / 8*256 = ~490 Hz PWM frequency
	TCCR0B |= (1<<CS01);

	// Initialize ADC
	// Enable ADC
	ADCSRA = (1<<ADEN);	
	// Select ADC1
	ADMUX |= (1<<MUX0);
	// The program reads the ADC value from the potentiometer
	// all the time and updates the PWM register with that value so
	// the motor power is controlled with the potentiometer.
		// Start ADC conversion
		ADCSRA |= (1<<ADSC);		
		// Wait until the conversion is ready
		loop_until_bit_is_set(ADCSRA, ADSC);
		// Read the ADC value and scale it to 8-bit value
		// because the ADC is 10-bit (1024 values) and the
		// PWM register is only 8-bit (256 values), 1024/256 = 4
		value = (uint8_t)(ADCW/4);
		OCR0A = value;
		// Wait for 2 ms
	return 0;

Download MakeFile and HEX

Download the source code, make file, and the hex code if you want to load it onto your ATTINY. We used an ATTINY85 but should definitely work on ATTINY45 and maybe on other tinys. We use avrdude to upload code, and the href="" >USBtiny programmer from adafruit to connect the computer to our PCB.
Click Here to Download: Download MakeFile and HEX


Title Description # Cost Link Picture
Pump 12V water pump Value: 12V 1 $14.95 Link 10455-01
Fountain PCB Water droplet shaped PCB. Holds the TIP120 transistor to control 12V DC pump. 1 $7.0 Link Screen_shot_2013-02-15_at_6.34.23_pm
Attiny85 AVR MCU 8K 20MHZ 8DIP 1 $1.29 Link 8-dip
Potentiometer POT ROTARY, Linear 10K OHM 9MM SNAPIN Value: 10k 1 $0.76 Link Screen_shot_2012-12-28_at_7.41.04_pm
Transistor Transitor NPN Darlington 60V 5A TO-220 Value: NPN 1 $0.66 Link To-220-3__to-220ab
TIP120 Transistor NPN Darlington 60V 5A TO-220 Value: NPN 1 $0.66 Link To-220-3__to-220ab
Button 6mm Through Hole Tactile Switch Through Hole SPST-NO 0.05A 12V Value: 0.05A @ 12VDC 1 $0.1 Link Screen_shot_2012-12-28_at_7.41.40_pm
Resistor RES 10K OHM 1/4W 5% CF MINI Value: 10k 1 $0.08 Link Screen_shot_2012-12-28_at_7.28.15_pm
Resistor RES 100 OHM 1/4W 5% CARBON FILM Value: 100 1 $0.08 Link Screen_shot_2012-12-28_at_7.27.43_pm
Think of it like a shift register for Pulse Width Modulation (PWM)....
RGB Flashlight, wearable sound art, rainbow lamp....
Rainbow flower necklace using the TLC5940....
The MCP79410 breakout board gives easy access to this cute little timekeeper....
Play pong on a little LCD screen with two big joysticks....
Control a 120v outlet with a 5V arduino....
From simple rules emerge mysterious and intricate patterns....
Make an interactive light show using a proximity sensor, and a bunsh of shift registers and LEDs....