/*this is controlling my powerbox, 3050, 3090 and fans W/PWM.takes the temp of 3050/3090 to enable auto fan speed. fan1 is a small computer fan, fan2 is the xbox fans.(no longer connected)remote cox universal aux 0820. monitors the voltage and current has a selector for high current and low current (changes the resistance to calculate with) can constant current charge a battery with different voltages and different amperages will slow down/turn off once voltage is reached. ABSOLUTE MAX OF 21.5v ON ALL INPUTS! now more accurate. button panel is a direct tv satellite box put together by SuperBrainAK */ #include //includes libraries. //const pin assignments const byte irin = 27; const byte temp = 45; const byte vlts = 38; const byte ain = 39; const byte aout = 40; const byte pbox = 0; const byte red = 17; const byte green = 13; const byte v5 = 21; const byte v9 = 22; const byte fan1 = 26; //const byte fan2 = 25; const byte batchrg = 25; const byte Button1 = 1; //power (power) const byte Button2 = 2; //5v power (guide) const byte Button3 = 3; //9v power (menu) const byte Button4 = 4; //change amperage resistance (active) const byte Button5 = 5; //raise the output voltage (up) const byte Button6 = 7; //lower the output voltage (down) const byte Button7 = 8; //reset the current and voltage (select) const byte Button8 = 9; //raises the output current (right) const byte Button9 = 10; //lowers the output current (left) IRrecv irrecv(irin); //ir recv stuff. decode_results results; int16_t adc_read_vcc(){ //"reset" the ADMUX ADMUX = 0b01000000; ADMUX |=(1< 1000) { //only recieves an input every second. if (irrecv.decode(&results)) { //recieves the ir signal. if (results.value == 0xd87245ba) { //power button. Serial.println("power button"); pbutton = !pbutton; } else if (results.value == 0xffc03f){ Serial.println("display/setup"); } else if (results.value == 0xff807f){ Serial.println("zoom"); } else if (results.value == 0xff609f){ Serial.println("SUB"); } else if (results.value == 0xff906f){ Serial.println("back"); } else if (results.value == 0xfff807){ Serial.println("skip"); } else if (results.value == 0xffb04f){ Serial.println("A-B"); } else if (results.value == 0xffa857){ //changes the current ranges. Serial.println("1/all"); crnt = !crnt; } else if (results.value == 0xd872748b){ Serial.println("up"); speed1 += 5; //fan1 speed +5. } else if (results.value == 0xd872b44b){ Serial.println("down"); speed1 -= 5; //fan1 speed -5. } else if (results.value == 0xd872f807){ Serial.println("left"); //speed2 -= 5; //fan2 speed -5. } else if (results.value == 0xd87204fb){ Serial.println("right"); //speed2 += 5; //fan2 speed +5. } else if (results.value == 0xd8720cf3){ Serial.println("select"); } else if (results.value == 0xffe817){ Serial.println("play/pause"); } else if (results.value == 0xff6897){ Serial.println("stop"); } else if (results.value == 0xffb24d){ Serial.println("menu"); } else if (results.value == 0xd872649b){ Serial.println("input"); } else if (results.value == 0xff58a7){ Serial.println("angle"); } else if (results.value == 0xff40bf){ Serial.println("lcd mode"); } else if (results.value == 0xffa05f){ Serial.println("title"); } else if (results.value == 0xd872d02f){ Serial.println("1"); } else if (results.value == 0xd872906f){ Serial.println("2"); } else if (results.value == 0xd872f00f){ Serial.println("3"); } else if (results.value == 0xd872b04f){ Serial.println("4"); } else if (results.value == 0xd87252ad){ //5v power button. Serial.println("5"); p5 = !p5; } else if (results.value == 0xd872d02f){ Serial.println("6"); } else if (results.value == 0xd872708f){ Serial.println("7"); } else if (results.value == 0xd872609f){ Serial.println("8"); } else if (results.value == 0xd872a05f){ //9v power button. Serial.println("9"); p9 = !p9; } else if (results.value == 0xd87240bf){ Serial.println("0"); } else { //tells you any unknown signal. if (results.decode_type == NEC) { Serial.print("Decoded NEC: "); } else if (results.decode_type == SONY) { Serial.print("Decoded SONY: "); } else if (results.decode_type == RC5) { Serial.print("Decoded RC5: "); } else if (results.decode_type == RC6) { Serial.print("Decoded RC6: "); } Serial.println(results.value, HEX); } } irrecv.resume(); if (digitalRead(Button1) == LOW){ //reads the button1 state. Serial.println("button1"); pbutton = !pbutton; } if (digitalRead(Button2) == LOW){ //reads the button2 state. Serial.println("button2"); p5 = !p5; } if (digitalRead(Button3) == LOW){ //reads the button3 state. Serial.println("button3"); p9 = !p9; } if (digitalRead(Button4) == LOW){ //reads the button4 state. Serial.println("button4"); crnt = !crnt; } if (digitalRead(Button5) == LOW){ //reads the button4 state. Serial.println("button5: volt limit up"); vltlmt += .1; } if (digitalRead(Button6) == LOW){ //reads the button4 state. Serial.println("button6: volt limit dowm"); vltlmt -= .1; } if (digitalRead(Button7) == LOW){ //reads the button4 state. Serial.println("button7: volt and current limits reset"); vltlmt = 0; //shuts off the voltage and current parameters. crntlmt = 0; } if (digitalRead(Button8) == LOW){ //reads the button4 state. Serial.println("button8: current limit up"); crntlmt += .1; } if (digitalRead(Button9) == LOW){ //reads the button4 state. Serial.println("button9: current limit down"); crntlmt -= .1; } tval = analogRead(temp); //updates the temperature. if (tval > 450){ //cold temperature turns fan off if not already off. if (speed1 != 0){ speed1 = 0; } } if (450 >= tval && tval >= 300){ //medium temperature auto equalize the fan. if (tval > ltval){ //if the temp. falls slow down the fan. speed1 --; } if (tval < ltval){ speed1 ++; //if the temp. rises speed up the fan. } } if (tval < 300){ //rather hot turns fan to max. speed1 = 70; } if (tval < 250){ //hot and hotter tells you so. Serial.println("heat sink is hot!"); digitalWrite(red, HIGH); digitalWrite(green, HIGH); p5v = 1 , p5 = 1 , p9v = 1 , p9 = 1; //turns off the regulators. chrgrte = 0; //stops any charging. crntlmt = -0.1 //resets the current limit. speed1 = 70; //makes sure the fan is running. } Serial.print("temp value is:"); //says the temp value. ltval = tval; //updates the last temperature. Serial.println(tval); if (pbutton == 1){ //toggles my power outputs. Serial.println("power"); power = !power; if (power){ Serial.println("on"); } else { Serial.println("off"); } digitalWrite(pbox, power ? LOW : HIGH); digitalWrite(green, power ? HIGH : LOW); digitalWrite(v5, power ? HIGH : LOW); digitalWrite(v9, power ? HIGH : LOW); digitalWrite(red, power ? LOW : HIGH); } if (p5 == 1){ //toggles my 5V output. Serial.println("5v power"); p5v = !p5v; if (p5v){ Serial.println("on"); } else { Serial.println("off"); } digitalWrite(v5, p5v ? HIGH : LOW); } if (p9 == 1){ //toggles my 9V output. Serial.println("9v power"); p9v = !p9v; if (p9v){ Serial.println("on"); } else { Serial.println("off"); } digitalWrite(v9, p9v ? HIGH : LOW); } if (crnt == 1){ //changes the resistance to use for current calculation. Serial.println("changed resistance"); amp = !amp; } if (speed1 < 0){ //limits range of speeds. Serial.println("fan1 low"); speed1 = 0; } if (speed1 > 70){ Serial.println("fan1 high"); speed1 = 70; } /*if (speed2 < 0){ Serial.println("fan2 low"); speed2 = 0; } if (speed2 > 100){ Serial.println("fan2 high"); speed2 = 100; }*/ if (speed1 != lspeed1){ //writes the speed of fan1 if change. lspeed1 = speed1; if (speed1 <= 14){ //puts start1 if fan1 gets to slow to run. start1 = 0; } if (start1 != 2){ if (start1 == 0){ //notices when to startup the fan. if (37 > speed1 && speed1 > 14){ start1 = 1; } } } if (start1 == 1){ //starts the fan to access low speeds. Serial.println("starting fan1"); analogWrite(fan1, 70); start1 = 2; delay (100); } } if (speed1 > 14){ analogWrite(fan1, speed1); Serial.print("fan1 speed is:"); //says the fan1 speed. Serial.println(speed1); } else { Serial.print("fan1 speed is slow: "); Serial.println(speed1); analogWrite(fan1, 0); } /*if (speed2 != lspeed2){ //writes the speed of fan2 if change. delay (100); lspeed2 = speed2; analogWrite(fan2, speed2); Serial.print("fan2 speed is:"); //says the fan2 speed. Serial.println(speed2); }*/ Vcc = adc_read_vcc(); //updates the Vcc voltage for correct measurements. volts = (((analogRead(vlts)/1023.0)*5*42620)/9800); //reads the voltage. Serial.print("voltage is: "); Serial.println(volts); //tells you the voltage. vampin = (((analogRead(ain)/1023.0)*5*42390)/9770); //reads the voltage in. vampout = (((analogRead(aout)/1023.0)*5*43060)/9940); //reads the voltage out. Serial.print("voltage in is: "); Serial.println(vampin); //tells you the voltage in. Serial.print("voltage out is: "); Serial.println(vampout); //tells you the voltage out. Serial.print("voltage drop is: "); Serial.println(vampin - vampout); //tells you the voltage drop.*i will comment this out as it is just for debugging if (amp){ //calculates for high current. amps = ((vampin - vampout)/.22); } else { amps = ((vampin - vampout)/.47); //calculates for low current. } Serial.print("amperage is "); if (amp){ Serial.print("high: "); } else { Serial.print("low: "); } Serial.println(amps); //tells you the amperage. if ((crntlmt - amps) > .05){ //the current is lower than the specified limit move on to voltage check. if ((vltlmt - vampout) > .05){ //if the voltage is lower than the specified value go ahead and decrease the PWM. if (chrgrte < 255){ chrgrte ++; Serial.print("increased "); } } } if ((vampout - vltlmt) > .05){//if the current or voltage is higher than the specified limit decrease the charge rate. if (chrgrte > 0){ chrgrte --; Serial.print("high voltage decreasing "); } } if ((amps - crntlmt) > .05){ if (chrgrte > 0){ chrgrte --; Serial.print("high current decreasing "); } } if (chrgrte != lchrgrte){ analogWrite(batchrg, chrgrte); lchrgrte = chrgrte; Serial.print("changed PWM "); } Serial.print("charge rate: "); //tells you the charge rate. Serial.println(chrgrte); Serial.print("voltage limit: "); //tells you the voltage limit. Serial.println(vltlmt); Serial.print("current limit: "); //tells you the current limit. Serial.println(crntlmt); last = millis(); } //end of every second things. }