moty
Published

Water Softener

Sweeping frequency magnetic hard water conditioner

BeginnerFull instructions provided38,903
Water Softener

Things used in this project

Story

Read more

Schematics

softener2

Code

Softener

C/C++
Timer2 in the Atmega is setup to output 50% duty cycle. The delay can be increased to slow the sweep. OCR2A sets the frequency, 10=25KHz and 255=1KHz. Frequencies can be changed.
/*
 *  Sweeping frequency water softener
 * Created: 15/01/2017 23:34:47
 *  Author: moty22.co.uk
 */ 


void setup() {
  // put your setup code here, to run once:

    //timer2
  OCR2A = 127;  //50% duty cycle 
  TCCR2A = _BV(COM2A0) | _BV(WGM21) | _BV(WGM20);  //toggle output, fast PWM mode 
  TCCR2B = _BV(WGM22) | _BV(CS21) | _BV(CS20); //   fast PWM mode, prescale 1:64
  pinMode(11, OUTPUT);

}

void loop()
{

  delay(200);   //duration of each frequency
  OCR2A += 10;    //step size of frequency change
  if(OCR2A >= 245){OCR2A = 10; }  //range of sweep, 245 is max. 
 
}

Credits

moty

moty

12 projects • 83 followers

Comments