Hardware components | ||||||
| × | 1 |
what it is and does
this is a project in the works and has no specific goal other than suit my needs when i need them. the program is in arduino format running on my Teensy++ 2.0 What it currently does now is control voltages i do have a plan for it to control a sound processor to my pc speakers but i have to get it a proper display first, it is currently saying things to the serial monitor on my pc.
it has 3 voltage inputs the first is for general purpose and the other 2 are for monitoring output current and voltage for adjusting the PWM of the power transistor to match the user inputed values for voltage and current. the transistor is powered by the teensy via a transistor transformer (commonly found in tv's) wich can turn say 12v and drop the voltage to about 3 volts with a higher amperage for the base (or gate) of a transistor. this transformer is powered by a smaller transistor hooked to the teensy via 470ohm resistor.
it also controls 2 linear voltage regulators (a 3050 and 3090) they are turned on and off by the teesny directly via their enable pin (a 78R05 has the same feature for example) and for the teensy's 5v it has a 78RA05 that can be finely tuned via a pot, that then goes to a cap and a diode to the teensy so that i dont have to turn off the 78RA05 when i plug in the teensy to usb, i then fine tuned the regulator to output an almost perfect 5v because the usb is about 5.2 or 5.3 volts that way the regulator is lower and power doesnt go back into the PC.
these regulators and transistor are cooled with a thick heatsink from a computer PSU and a small 1.5" fan PWM'd automatically when it detects it heating up, the thermistor isnt calibrated to any form of degrees just the ADC values directly, it will speed up the fan when it sees the ADC value lower (thermistor getting hotter) and it will set the fan to max (70 because there is no need to go any higher) if it goes below a certain value (hot enough to hurt when touched) it will turn off the regulators and will also turn off the transistor when it gets hot it says so in the serial and turns the light to orange (more about the dual led in a bit).
the button board is from a direct tv cable box with 11 buttons and SMT pullup resistors so all i have to do is plug the pins in and write the code. the board also has an ir demodulator so that my teensy can recieve commands from a remote, though i havent needed to use the remote much so i have just left the code there incase i do (wich means you wont see alot of the new functions controlled by it).
it has a red+green led for power status (both on for orange) and the blue led on the button board connected to the pin i originally used to control a computer PSU but am no longer using it. it also has a led on each of the regulators rail and i tried to put one on the transistor transformer but it isnt working currently.
the switch mode power supply is from a wii rated 12v@3.7A it has short protection and a nice clean output.
there are plenty of filters and caps strewn everywhere; small inductor and 1000µF on 12v, 6600µF on 9v, 8800µF on 5v, 1500µF on stb5v, 100µF on µc5v, 1µF on the voltage divider inputs, 10µF on thermister input, 470µF on the transistors out and current meters input also have a power diode on the input of the transistor, and 47µF on the fans terminals.
i hope you all can understand this as it sure is a lot to say in words :) im sure there are alot of areas for improvement and i would love it if anybody had some cool ideas i could add in! i am currently working on making a computer interface for it but i am having trouble with the serial communication among other things.
in the pics it is charging my 6v@4.5AH lead acid battery @ 200mA to 6.5v (later found out the max is 6.3v :P )
in 0_5 i have updated the code to make more sense on the serial monitor, and am showing it charging an 18650 battery it works fine when i have it limited to 4.1v as it will go over 4.2v which is bad for a li-ion, it isnt the most accurate and jumps around alot which i think is from the internal reference portion so i will have to see what i can do. it can also receive a float which goes to the voltage limit so i dont have to wait for it to get there.
incase i dont put pics here i have them here http://postimg.org/gallery/6q30jf8u/
pictures
0_5 code
0_5 code
Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).
/*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.
voltage can be set by sending it over the serial port.
ABSOLUTE MAX OF 21.5v ON ALL INPUTS! now more accurate.
button panel is a direct tv satellite box
put together by SuperBrainAK
version 0_5
*/
#include <IRremote.h> //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<<REFS0) | (1<<MUX4) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
//REFS0 - VCC as reference
//mux - measurment on the 1.11V internal
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);//ADEN - enable ADC. ADPS - 1,1,1 = F_CPU/128 prescalar (should work for 8MHz - 16MHz)
delay(5);//ehh...
ADCSRA|=(1<<ADSC);//we start conversion
while(!(ADCSRA & (1<<ADIF)));//Wait for conversion to complete
ADCSRA|=(1<<ADIF);//just making sure it's 0
return (1125300L/ADC);//to get it in mV (to not to loose to many decimals) - (1100mV*1023)
}
void setup () {
pinMode(pbox, OUTPUT); //pin modes
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(v5, OUTPUT);
pinMode(v9, OUTPUT);
pinMode(fan1, OUTPUT);
//pinMode(fan2, OUTPUT);
pinMode(batchrg, OUTPUT);
pinMode(temp, INPUT);
pinMode(vlts, INPUT);
pinMode(ain, INPUT);
pinMode(aout, INPUT);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
pinMode(Button5, INPUT);
pinMode(Button6, INPUT);
pinMode(Button7, INPUT);
pinMode(Button8, INPUT);
pinMode(Button9, INPUT);
Serial.begin(9600);
irrecv.enableIRIn();
}
unsigned long last = millis(); //declares millis var?
byte startup = 0; //runs startup sequence if=0.
byte power = 0; //main power state.
byte p5v = 0; //5V power state.
byte p9v = 0; //9V power state.
byte start1 = 0; //startup for fan1.
int speed1 = 0; //speed of fan1.
//int speed2 = 0; //speed of fan2.
int lspeed1 = 0; //last speed of fan1.
//int lspeed2 = 0; //last speed of fan2.
int tval = 0; //temperature value.
int ltval = 0; //last temperature value.
float Vcc = 0; //stores the Vcc voltage. in mV
float volts = 0; //voltage metering.
float vampin = 0; //voltage before the current resistor.
float vampout = 0; //voltage after the current resistor.
byte amp = 0; //0=low current, 1=high current.
float amps = 0; //calculated amps.
float crntlmt = 0; //max current the transistor will source.
float vltlmt = 0; //max voltage the transistor will get to.
int chrgrte = 0; //PWM value for the NPN to a PNP charging transistor via a small transformer.(reminder set a PWM limit to prevent overheat and maintain efficiency)
int lchrgrte = 1;
void loop() {
if (startup == 0){ //sets the states of my sensitive outputs.
digitalWrite(red, HIGH);
digitalWrite(pbox, HIGH);
digitalWrite(v5, LOW);
digitalWrite(v9, LOW);
startup = 1;
}
byte pbutton = 0; //temporary power variable state.
byte p5 = 0; //temporary 5V variable state.
byte p9 = 0; //temporary 9V variable state.
byte crnt = 0; //temporary current variable state.
if (Serial.available()){ //will set the voltage to the recieved value.
vltlmt = Serial.parseFloat(); //use Serial.parseFloat() for grabbing floats over serial.
}
if (millis() - last > 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");
chrgrte = 0; //shuts off the transistor resets the voltage and current parameters.
vltlmt = 0;
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.print("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.print("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.
}
if (amp){
Serial.print("high ");
}
else {
Serial.print("low ");
}
Serial.print("amperage is: ");
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){ //changes the PWM of the transistor.
analogWrite(batchrg, chrgrte);
lchrgrte = chrgrte;
Serial.print("PWM change");
}
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.
}
0_4_9 code
0_4_9 code
Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).
/*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 <IRremote.h> //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<<REFS0) | (1<<MUX4) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
//REFS0 - VCC as reference
//mux - measurment on the 1.11V internal
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);//ADEN - enable ADC. ADPS - 1,1,1 = F_CPU/128 prescalar (should work for 8MHz - 16MHz)
delay(5);//ehh...
ADCSRA|=(1<<ADSC);//we start conversion
while(!(ADCSRA & (1<<ADIF)));//Wait for conversion to complete
ADCSRA|=(1<<ADIF);//just making sure it's 0
return (1125300L/ADC);//to get it in mV (to not to loose to many decimals) - (1100mV*1023)
}
void setup () {
pinMode(pbox, OUTPUT); //pin modes
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(v5, OUTPUT);
pinMode(v9, OUTPUT);
pinMode(fan1, OUTPUT);
//pinMode(fan2, OUTPUT);
pinMode(batchrg, OUTPUT);
pinMode(temp, INPUT);
pinMode(vlts, INPUT);
pinMode(ain, INPUT);
pinMode(aout, INPUT);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
pinMode(Button5, INPUT);
pinMode(Button6, INPUT);
pinMode(Button7, INPUT);
pinMode(Button8, INPUT);
pinMode(Button9, INPUT);
Serial.begin(9600);
irrecv.enableIRIn();
}
unsigned long last = millis(); //declares millis var?
byte startup = 0; //runs startup sequence if=0.
byte power = 0; //main power state.
byte p5v = 0; //5V power state.
byte p9v = 0; //9V power state.
byte start1 = 0; //startup for fan1.
int speed1 = 0; //speed of fan1.
//int speed2 = 0; //speed of fan2.
int lspeed1 = 0; //last speed of fan1.
//int lspeed2 = 0; //last speed of fan2.
int tval = 0; //temperature value.
int ltval = 0; //last temperature value.
float Vcc = 0; //stores the Vcc voltage. in mV
float volts = 0; //voltage metering.
float vampin = 0; //voltage before the current resistor.
float vampout = 0; //voltage after the current resistor.
byte amp = 0; //0=low current, 1=high current.
float amps = 0; //calculated amps.
float crntlmt = 0; //max current the transistor will source.
float vltlmt = 0; //max voltage the transistor will get to.
int chrgrte = 0; //PWM value for the PNP to a NPN charging transistor.
int lchrgrte = 1;
void loop() {
if (startup == 0){ //sets the states of my sensitive outputs.
digitalWrite(red, HIGH);
digitalWrite(pbox, HIGH);
digitalWrite(v5, LOW);
digitalWrite(v9, LOW);
startup = 1;
}
byte pbutton = 0; //temporary power variable state.
byte p5 = 0; //temporary 5V variable state.
byte p9 = 0; //temporary 9V variable state.
byte crnt = 0; //temporary current variable state.
if (millis() - last > 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.
}
/*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.
voltage can be set by sending it over the serial port.
ABSOLUTE MAX OF 21.5v ON ALL INPUTS! now more accurate.
button panel is a direct tv satellite box
put together by SuperBrainAK
version 0_5
*/
#include <IRremote.h> //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<<REFS0) | (1<<MUX4) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
//REFS0 - VCC as reference
//mux - measurment on the 1.11V internal
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);//ADEN - enable ADC. ADPS - 1,1,1 = F_CPU/128 prescalar (should work for 8MHz - 16MHz)
delay(5);//ehh...
ADCSRA|=(1<<ADSC);//we start conversion
while(!(ADCSRA & (1<<ADIF)));//Wait for conversion to complete
ADCSRA|=(1<<ADIF);//just making sure it's 0
return (1125300L/ADC);//to get it in mV (to not to loose to many decimals) - (1100mV*1023)
}
void setup () {
pinMode(pbox, OUTPUT); //pin modes
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(v5, OUTPUT);
pinMode(v9, OUTPUT);
pinMode(fan1, OUTPUT);
//pinMode(fan2, OUTPUT);
pinMode(batchrg, OUTPUT);
pinMode(temp, INPUT);
pinMode(vlts, INPUT);
pinMode(ain, INPUT);
pinMode(aout, INPUT);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
pinMode(Button5, INPUT);
pinMode(Button6, INPUT);
pinMode(Button7, INPUT);
pinMode(Button8, INPUT);
pinMode(Button9, INPUT);
Serial.begin(9600);
irrecv.enableIRIn();
}
unsigned long last = millis(); //declares millis var?
byte startup = 0; //runs startup sequence if=0.
byte power = 0; //main power state.
byte p5v = 0; //5V power state.
byte p9v = 0; //9V power state.
byte start1 = 0; //startup for fan1.
int speed1 = 0; //speed of fan1.
//int speed2 = 0; //speed of fan2.
int lspeed1 = 0; //last speed of fan1.
//int lspeed2 = 0; //last speed of fan2.
int tval = 0; //temperature value.
int ltval = 0; //last temperature value.
float Vcc = 0; //stores the Vcc voltage. in mV
float volts = 0; //voltage metering.
float vampin = 0; //voltage before the current resistor.
float vampout = 0; //voltage after the current resistor.
byte amp = 0; //0=low current, 1=high current.
float amps = 0; //calculated amps.
float crntlmt = 0; //max current the transistor will source.
float vltlmt = 0; //max voltage the transistor will get to.
int chrgrte = 0; //PWM value for the NPN to a PNP charging transistor via a small transformer.(reminder set a PWM limit to prevent overheat and maintain efficiency)
int lchrgrte = 1;
void loop() {
if (startup == 0){ //sets the states of my sensitive outputs.
digitalWrite(red, HIGH);
digitalWrite(pbox, HIGH);
digitalWrite(v5, LOW);
digitalWrite(v9, LOW);
startup = 1;
}
byte pbutton = 0; //temporary power variable state.
byte p5 = 0; //temporary 5V variable state.
byte p9 = 0; //temporary 9V variable state.
byte crnt = 0; //temporary current variable state.
if (Serial.available()){ //will set the voltage to the recieved value.
vltlmt = Serial.parseFloat(); //use Serial.parseFloat() for grabbing floats over serial.
}
if (millis() - last > 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");
chrgrte = 0; //shuts off the transistor resets the voltage and current parameters.
vltlmt = 0;
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.print("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.print("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.
}
if (amp){
Serial.print("high ");
}
else {
Serial.print("low ");
}
Serial.print("amperage is: ");
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){ //changes the PWM of the transistor.
analogWrite(batchrg, chrgrte);
lchrgrte = chrgrte;
Serial.print("PWM change");
}
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.
}
/*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 <IRremote.h> //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<<REFS0) | (1<<MUX4) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
//REFS0 - VCC as reference
//mux - measurment on the 1.11V internal
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);//ADEN - enable ADC. ADPS - 1,1,1 = F_CPU/128 prescalar (should work for 8MHz - 16MHz)
delay(5);//ehh...
ADCSRA|=(1<<ADSC);//we start conversion
while(!(ADCSRA & (1<<ADIF)));//Wait for conversion to complete
ADCSRA|=(1<<ADIF);//just making sure it's 0
return (1125300L/ADC);//to get it in mV (to not to loose to many decimals) - (1100mV*1023)
}
void setup () {
pinMode(pbox, OUTPUT); //pin modes
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(v5, OUTPUT);
pinMode(v9, OUTPUT);
pinMode(fan1, OUTPUT);
//pinMode(fan2, OUTPUT);
pinMode(batchrg, OUTPUT);
pinMode(temp, INPUT);
pinMode(vlts, INPUT);
pinMode(ain, INPUT);
pinMode(aout, INPUT);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
pinMode(Button5, INPUT);
pinMode(Button6, INPUT);
pinMode(Button7, INPUT);
pinMode(Button8, INPUT);
pinMode(Button9, INPUT);
Serial.begin(9600);
irrecv.enableIRIn();
}
unsigned long last = millis(); //declares millis var?
byte startup = 0; //runs startup sequence if=0.
byte power = 0; //main power state.
byte p5v = 0; //5V power state.
byte p9v = 0; //9V power state.
byte start1 = 0; //startup for fan1.
int speed1 = 0; //speed of fan1.
//int speed2 = 0; //speed of fan2.
int lspeed1 = 0; //last speed of fan1.
//int lspeed2 = 0; //last speed of fan2.
int tval = 0; //temperature value.
int ltval = 0; //last temperature value.
float Vcc = 0; //stores the Vcc voltage. in mV
float volts = 0; //voltage metering.
float vampin = 0; //voltage before the current resistor.
float vampout = 0; //voltage after the current resistor.
byte amp = 0; //0=low current, 1=high current.
float amps = 0; //calculated amps.
float crntlmt = 0; //max current the transistor will source.
float vltlmt = 0; //max voltage the transistor will get to.
int chrgrte = 0; //PWM value for the PNP to a NPN charging transistor.
int lchrgrte = 1;
void loop() {
if (startup == 0){ //sets the states of my sensitive outputs.
digitalWrite(red, HIGH);
digitalWrite(pbox, HIGH);
digitalWrite(v5, LOW);
digitalWrite(v9, LOW);
startup = 1;
}
byte pbutton = 0; //temporary power variable state.
byte p5 = 0; //temporary 5V variable state.
byte p9 = 0; //temporary 9V variable state.
byte crnt = 0; //temporary current variable state.
if (millis() - last > 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.
}
Comments
Please log in or sign up to comment.