Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
/*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! 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 = 24; 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 = 255; //PWM value for the NPN charging transistor. 255 is off and 0 is full on. int lchrgrte = 0; //last charge rate. 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. //if (vltlmt > 0){ 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; } 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; } 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); } Serial.print("temp value is:"); //says the temp value. ltval = tval; //updates the last temperature. Serial.println(tval); 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*42450)/9700); //reads the voltage. Serial.print("voltage is: "); Serial.println(volts); //tells you the voltage. vampin = (((analogRead(ain)/1023.0)*5*42320)/9720); //reads the voltage in. vampout = (((analogRead(aout)/1023.0)*5*42890)/9890); //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 > 0){ chrgrte --; Serial.print("increasing "); } } } else if (((amps - crntlmt) > .05) || ((volts - vampout) > .05)){//if the current or voltage is higher than the specified limit decrease the charge rate. if (chrgrte < 255){ chrgrte ++; Serial.print("decreasing "); } } if (chrgrte != lchrgrte){ //writes the PWM to the transistor. analogWrite(batchrg, chrgrte); lchrgrte = chrgrte; } 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. }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
25 min ago | 11.91 KB
Christmas Gift
53 min ago | 0.84 KB
December smells like money (Release)
CSS | 53 min ago | 0.82 KB
Untitled
2 hours ago | 12.54 KB
Patch: Get available spaces
4 hours ago | 0.52 KB
Untitled
4 hours ago | 15.20 KB
GAINAX
5 hours ago | 3.57 KB
Untitled
10 hours ago | 22.81 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!