Battery Soldering Iron - Code
13/08/2021 | Views: 4607 | Arduino | by: ELECTRONOOBS      


Get the code from below and maybe consider supporting my work as well. You will aslo need the library for the OLED screen so download taht as well and go to sketch, include library adn add .zip library and there select the zip file you have just downloaded. Compile, connect the FTDI mdoule to the PCB and uplaod the code. Read the comments in the code for more.







/* Battery portable soldering iron by Andrei Gabriel from ELECTRONOOBS
 * Tutorial: http://electronoobs.com/eng_arduino_tut157.php
 * Schematic: http://electronoobs.com/eng_arduino_tut157_sch1.php
*/

//Variables
bool SW1_state = true;
bool SW2_state = true;
bool SW3_state = true;
float ON_counter = 0;
float min_ON_time =  2.0;
float max_ON_time =  15.0;
unsigned long previousMillis,currentMillis, sleepMillis;  
int refresh_rate = 100;
bool after_hot = false;
float on_time = 10;
float max_power = 20;
float min_power = 5;
float pid_power = 10;
bool no_tip = false;
bool after_hot_beep = false;
int PWM_value = 30;
bool sleepMode = false;
int sleep_time = 10000; //in ms

unsigned long SW2_UP_counter, SW2_DOWN_counter, SW2_counter, SW3_UP_counter, SW3_DOWN_counter, SW3_counter; 
bool change_time = false;
bool change_power = false;


static const unsigned char PROGMEM  battery_1[] =
{ 
B00111100, 
B10000001, 
B10000001, 
B10000001, 
B10000001, 
B10000001,
B10000001, 
B10000001,
B10000001, 
B10000001, 
B10000001,
B10000001, 
B10111101, 
B10111101,
B10000001, 
B11111111
};


static const unsigned char PROGMEM  nulo[] =
{ 
B00000000,B00111100,B00000000, 
B00000001,B11000011,B10000000, 
B00000010,B00000000,B01000000, 
B00001100,B00000000,B00110000, 
B00001000,B00000000,B00010000, 
B00110000,B00000000,B00111100, 
B00100000,B00000000,B01100100, 
B01000000,B00000000,B11000010,
B01000000,B00000001,B10000010, 
B01000000,B00000011,B00000010, 
B10000000,B00000110,B00000001, 
B10000000,B00001100,B00000001, 
B10000000,B00011000,B00000001, 
B10000000,B00110000,B00000001, 
B01000000,B01100000,B00000010,
B01000000,B11000000,B00000010, 
B01000001,B10000000,B00000010, 
B00100011,B00000000,B00000100, 
B00110110,B00000000,B00001100,  
B00001100,B00000000,B00010000,  
B00001100,B00000000,B00110000, 
B00000010,B00000000,B01000000,  
B00000001,B11000011,B10000000, 
B00000000,B00111100,B00000000
};


static const unsigned char PROGMEM  hot_iron[] =
{ 
B00000000,B00000000,B00100100,  
B00000000,B00000000,B01001001,
B00000000,B00000000,B01010010,
B00000000,B00000000,B10010100,
B00000000,B00000000,B10101000,
B11111111,B11111100,B00000000,
B11111111,B11111111,B11111000,
B11111111,B11111100,B00000000
};

static const unsigned char PROGMEM  exclamation[] =
{ 
B00000000,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00111100,
B00000000,
B00000000,
B00000000,
B00111100,
B00111100,
B00111100,
B00000000,
B00000000,
};


static const unsigned char PROGMEM  battery_2[] =
{ 
B00011111, B11111000,
B00011111, B11111000,
B11111111, B11111111,
B11111111, B11111111,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11000000, B00000011,
B11001111, B11110011,
B11001111, B11110011,
B11001111, B11110011,
B11000000, B00000011,
B11000000, B00000011,
B11001111, B11110011,
B11001111, B11110011,
B11001111, B11110011,
B11000000, B00000011,
B11000000, B00000011,
B11111111, B11111111,
B11111111, B11111111
};

static const unsigned char PROGMEM  ohm[] =
{ 
B01110000,
B10001000,
B10001000,
B10001000,
B01010000,
B01010000,
B11001100
};



#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>         //download here: https://www.electronoobs.com/eng_arduino_Adafruit_GFX.php
#include <Adafruit_SSD1306.h>     //downlaod here: https://www.electronoobs.com/eng_arduino_Adafruit_SSD1306.php
#define OLED_RESET 2
Adafruit_SSD1306 display(OLED_RESET);

//Inputs/Outputs
#define MOSFET 3
#define BUZZER 5
#define RES_DIVIDER 4
#define BAT_IN A0
#define ACS_IN A2
#define LM358_1 A1
#define LM358_2 A3
#define SW1 8
#define SW2 10
#define SW3 9



void setup() { 
  pinMode(MOSFET, OUTPUT);
  digitalWrite(MOSFET, LOW);

  TCCR2B = TCCR2B & B11111000 | B00000001;    // pin 3 and 11 PWM frequency of 31372.55 Hz
  
  pinMode(BUZZER, OUTPUT);
  digitalWrite(BUZZER, LOW);
  pinMode(RES_DIVIDER, OUTPUT);
  digitalWrite(RES_DIVIDER, LOW);
  
  pinMode(SW1, INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
  pinMode(SW3, INPUT_PULLUP);  
  digitalWrite(BAT_IN, INPUT);
  digitalWrite(ACS_IN, INPUT);
  digitalWrite(LM358_1, INPUT);
  digitalWrite(LM358_2, INPUT);
  
  
  Serial.begin(9600); 
  analogReference(INTERNAL); 
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32 or 64 from eBay)
  delay(100);
  display.clearDisplay();
  display.setTextSize(1); 
  display.setTextColor(WHITE);
  display.setCursor(15,6);
  display.print("ELECTRONOOBS"); 
  display.setCursor(15,14); 
  display.setTextSize(2); 
  display.print("IRON V1.0");   
  display.display();
  delay(1000);

  
  currentMillis = millis();
  previousMillis = currentMillis;
  sleepMillis = currentMillis;
}

void loop() {
  
  
  currentMillis = millis();
  if(!sleepMode){
    if(currentMillis - previousMillis > refresh_rate){
      previousMillis = currentMillis;
      
      
      if(!digitalRead(SW1) && !no_tip){
        SW1_state = false;       
        sleepMillis = millis();   
        if( (ON_counter < on_time) && !after_hot){
          ON_counter = ON_counter + 0.1;
          
          
         
          analogReference(INTERNAL); 
          float battery_val = analogRead(BAT_IN)*(5.18/1024.0); //5.18 = 1.1 x 4.709 (voltage divider)     
          analogReference(DEFAULT);     
          float ACS712_voltage = analogRead(ACS_IN)*(battery_val/1024.0); //1.1 x 4.4         
          float ACS712_current =(ACS712_voltage- ((battery_val/2)+0.42))/0.1; //is not 2.5 but 2.89 after tests
          float power = battery_val * ACS712_current;
  
  
          if(power > pid_power){
            PWM_value --;
          }
          else{
            PWM_value ++;
          }
          analogWrite(MOSFET, PWM_value);
          
          display.clearDisplay();  
          display.drawBitmap(0, 3,  exclamation, 8, 32, 1);
                    
          display.setTextSize(3);
          display.setCursor(13,7); 
          display.print(ON_counter,1);
          display.setTextSize(1); 
          display.print("s");
  
          display.setTextSize(2); 
          display.setCursor(92,6);  
          display.print(power,0);        
          display.setTextSize(1);
          display.print("W"); 
  
          display.setTextSize(1);     
          display.setCursor(92,24);  
          display.print(battery_val,1);
          display.println("V");
     
          display.display();
          
        }
        else {        
          digitalWrite(MOSFET, LOW);
          after_hot = true;
          if(!after_hot_beep){
            analogWrite(BUZZER, 200);
            delay(100);
            after_hot_beep = true;
            analogWrite(BUZZER, LOW);
          }
          display.clearDisplay();
          display.drawBitmap(5, 3,  exclamation, 8, 32, 1);
          display.setTextSize(2);
          display.setCursor(20,11);
          display.print("Over ");
          display.print(on_time,0);
          display.print("s");
          display.display();        
        }
            
      }
      else if(digitalRead(SW1)){
        digitalWrite(MOSFET, LOW);
        delay(2);
        after_hot = false;
        after_hot_beep = false;
        ON_counter = 0;
        analogReference(INTERNAL); 
        float battery_val = analogRead(BAT_IN)*(5.18/1024.0); 
      
        digitalWrite(RES_DIVIDER, HIGH);
        delay(10);
        float LM358_2_out = analogRead(LM358_2)*(1.1/1024.0);
        digitalWrite(RES_DIVIDER, LOW);
        
        display.clearDisplay();
        display.setTextSize(1);        
        
        if(LM358_2_out < 1){
          no_tip = false;
          LM358_2_out = LM358_2_out/30.4;
          float res = 150/((battery_val/LM358_2_out)-1);
          
          display.drawBitmap(0, 3,  battery_2, 16, 29, 1);        
          
          display.setCursor(18,9);
          display.print(battery_val,2);
          display.print("v");  
          if(change_time && !change_power){
            display.setTextSize(2);            
            display.setCursor(65,1);         
            display.print(on_time,1);           
            display.print("s");
            
            display.setCursor(70,17);                     
            display.print("TIME");
          }
          else if(!change_time && change_power){
            display.setTextSize(2);  
            display.setCursor(74,1);                      
            display.print("PWR");
                        
            display.setCursor(65,17); 
            display.print(pid_power,1);           
            display.print("w");
          }
  
          else if(!change_time && !change_power){
            display.setTextSize(2);  
            display.setCursor(65,1);         
            display.print(on_time,1);           
            display.print("s");
            display.setTextSize(2);            
            display.setCursor(65,17); 
            display.print(pid_power,1);           
            display.print("w");
          }        
                         
          display.setTextSize(1); 
          display.setCursor(18,17);
          display.print(res,2);     
          display.drawBitmap(42, 17,  ohm, 5, 7, 1);
  
          
        }
        else{
          display.drawBitmap(0, 3,  battery_2, 16, 29, 1);        
          no_tip = true;        
          display.setCursor(17,9);
          display.print(battery_val,2);
          display.println("v");  
  
          display.setTextSize(2);            
          display.setCursor(17,17);
          display.print("No Tip");  
  
          display.drawBitmap(97, 7,  nulo, 24, 24, 1); 
          
        }             
        display.display();
      }
  
  
      if(!digitalRead(SW2) && SW2_state){
        SW2_state = false;
        SW2_UP_counter = millis();
      }   
  
      if(!digitalRead(SW2) && !SW2_state){      
        SW2_counter = millis();
        if(SW2_counter - SW2_UP_counter > 1000){
          change_time = true;
        }
        if(change_time){
          on_time = on_time + 0.1;
          if(on_time > max_ON_time){
            on_time = min_ON_time;
          }
        }
      } 
      
      if(digitalRead(SW2) && !SW2_state){
        SW2_state = true;  
        SW2_UP_counter = millis();      
      }
      else if(digitalRead(SW2) && SW2_state){
        SW2_counter = millis();
        if(SW2_counter - SW2_UP_counter > 2000){
          change_time = false;
        }
      }
      
     
          
      
      
  
  
      if(!digitalRead(SW3) && SW3_state){
        SW3_state = false;
        SW3_UP_counter = millis();
      }   
  
      if(!digitalRead(SW3) && !SW3_state){      
        SW3_counter = millis();
        if(SW3_counter - SW3_UP_counter > 1000){
          change_power = true;
        }
        if(change_power){
          pid_power = pid_power - 0.1;
          if(pid_power < min_power){
            pid_power = max_power;
          }
        }
      } 
      
      if(digitalRead(SW3) && !SW3_state){
        SW3_state = true;  
        SW3_UP_counter = millis();      
      }
      else if(digitalRead(SW3) && SW3_state){
        SW3_counter = millis();
        if(SW3_counter - SW3_UP_counter > 2000){
          change_power = false;
        }
      }
  
      
    }//end of refresh rate
  }//end of !sleepMode

  else{
    if(!digitalRead(SW1)){
      sleepMode = false;
      sleepMillis = millis();
    }    
    display.clearDisplay();    
    display.display(); 
    analogWrite(MOSFET, LOW);  
  }
  if((currentMillis - sleepMillis > sleep_time) && !sleepMode){
    sleepMode = true;  
    analogWrite(BUZZER, 200);
    display.clearDisplay();    
    display.setTextSize(2);
    display.setCursor(40,11);
    display.print("SLEEP");    
    display.display(); 
    delay(400);
    digitalWrite(BUZZER, LOW); 
    delay(600);
   }

  
  

  

}













Last tutorials

Halloween 3D Printed Skull with Smoke Machine
TL431 undervoltage protection
TL431 Current Limiter Circuit - Fixed Value
TL431 Variable Zener + Examples
Shocking Game - Lie detector | 3D printed

ADVERTISERS



ADVERTISERS

PCBWAY PCB service

PCBWAY PCB service





Curso Arduino Online nivel bajo