pleasedontcode

# Plasma Controller rev_01

Jan 17th, 2026
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: # Plasma Controller
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2026-01-17 16:26:07
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* buat progres THC_rotary bisa di kontrol dengan web */
  21.     /* server */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24.  
  25. /*
  26.   Last update 24.08.2025
  27.  
  28.   Project:  THC for Plasma CNC controller
  29.   Platform: Arduino UNO R3
  30.   Created:  April 2015
  31.   Version:  02.00
  32.   By:       Pham Duy Anh - [email protected]
  33.  
  34.   Update and changes
  35.   By: Mehmet İbrahim - [email protected]
  36.   Youtube: https://www.youtube.com/c/MehmetIbrahim
  37.  
  38.   Adaptation to esp32 24.08.2025  Mehmet İbrahim
  39.  
  40.   Require:
  41.   -> input
  42.   <- output
  43.  
  44.   -> serial Tx
  45.   -> serial Rx
  46.   -> reset
  47.  
  48.   -> rotary encoder      digital - interrupt
  49.   -> rotary encoder      digital - interrupt
  50.   -> totary button       digital
  51.  
  52.   -> plasma Torch on     digital
  53.   -> plasma Arc Ok       analog or digital)
  54.   -> plasma arc voltage  analog 0-5V
  55.  
  56.   <- Arc Ok              optocoupler
  57.   <- torch Up            optocoupler
  58.   <- torch Down          optocuopler
  59.  
  60.   <- LCD
  61.   <- LCD
  62.   <- LCD
  63.   <- LCD
  64.   <- LCD
  65.   <- LCD
  66. */
  67.  
  68. #include <esp_timer.h>  // ESP32 Timer library
  69.  
  70. #define encoderPinA 13  //PORTD 2 - INT0
  71. #define encoderPinB 16  //PORTD 3 - INT1
  72. #define buttonPin 17    //PORTD 4
  73.  
  74. #define outputOkPin 23  //PORTD 7
  75. #define outputUpPin 25  //PORTD 6
  76. #define outputDnPin 26  //PORTD 5
  77.  
  78. #define arcVoltPin 34  //PORTC 0
  79.  
  80. #define defaultLCDtime 500  // s * 100
  81.  
  82.  
  83. #define PWM_CHANNEL 0
  84. esp_timer_handle_t timer_handle;
  85. double espV_value = 3.3;  // voltage value
  86.  
  87. /*
  88.   Parameter
  89.    DT  - Delay time - Delay time of output closed despite no supply voltage, when the system detects the main (cutting) arc, 0.1~19.9s.
  90.    HyS - Hysreresis - The hysteresis voltage - a rangge in which the voltage is measured, in which ther are signals controlling Up/Down, (+-1V ~ +-15V)
  91.    StV - Started Voltage - Value of the off load voltage detection in the plasma cutter - uesd to detect the main (cutting) arc: 50~300V.
  92.    +
  93.  
  94. */
  95.  
  96. int SetVa = 0, DTa = 1, HySa = 2, StVa = 3;
  97.  
  98. int SetV, DT, HyS, StV;
  99.  
  100. //(divRato) It is a value that varies depending on the voltage divider you use, a low value increases Arc.V, a high value decreases it.
  101. //The welding machine gives continuous output. Comparison can be made by connecting the voltage divider to the welding machine :)
  102. //int divRato = 43 ;
  103. int divRato = 39;
  104.  
  105. unsigned long ArcV;
  106. int oldValue;
  107.  
  108.  
  109. //Taking Average read voltage (values)
  110. bool takingAverage = false;  //Read the voltage with a few examples true or false
  111. //10 samples readings will be taken and averaged to arch voltage read
  112. int sampleReadV = 10;               //10 samples
  113. unsigned int millisdelayReadV = 3;  // Waiting time for between samples readings  [ms]
  114. int counterVo = 0;
  115. unsigned long readVMillis;
  116. unsigned long prevReadVMillis = 0;
  117. unsigned long readingsV = 0;
  118.  
  119.  
  120. int program;
  121.  
  122. // Array of Param
  123. //              SetV, DT, HYS, StV, divRato,
  124. // Param Address   0,  1,   2,   3,       4,
  125. int Param[4] = { SetV, DT, HyS, StV };  //, divRato};
  126. byte ParamItem = 4;
  127.  
  128. // Enable to do THC
  129. boolean Do;
  130. // Encoder, menu, pos
  131. int encoderVal;
  132. byte menu = 0;
  133. byte pos = 0;
  134. byte show = 0;
  135. unsigned int LCDtime = 0;
  136.  
  137. void setup() {
  138.  
  139.   //Set ADC resolution to 12 bits (0-4095)
  140.   analogSetWidth(12);
  141.   // Set the pin's voltage attenuation (11dB for 0-3.3V)
  142.   analogSetPinAttenuation(arcVoltPin, ADC_11db);
  143.  
  144.   Setup_Encoder();
  145.   Setup_LCD();
  146.   Setup_THC();
  147.   Setup_Timer2();
  148.  
  149.   //Read parameter from EEPROM
  150.   ReadProg();
  151.   if (program == 255) {  // Configure eeprom defaults on first boot
  152.     Default();
  153.     ReadProg();  //Now read the parameters again
  154.   }
  155.   switch (program) {
  156.     case 1:
  157.       ReadDataProg_1();
  158.       break;
  159.     case 2:
  160.       ReadDataProg_2();
  161.       break;
  162.     case 3:
  163.       ReadDataProg_3();
  164.       break;
  165.   }
  166.  
  167.   //Set value for all parameter
  168.   SetV = Param[SetVa];
  169.   DT = Param[DTa];
  170.   HyS = Param[HySa];
  171.   StV = Param[StVa];
  172.   //Preset value for encoder
  173.   encoderVal = SetV;
  174.   //Serial.begin(9600);
  175. }
  176.  
  177. void loop() {
  178.   //Read voltage
  179.   if (takingAverage) {
  180.     // Read Average voltage value from ADC
  181.     readVMillis = millis();
  182.     if (readVMillis - prevReadVMillis >= millisdelayReadV) {
  183.       prevReadVMillis = readVMillis;
  184.       counterVo++;
  185.       double rawAnalogValue = analogRead(arcVoltPin);
  186.       ArcV = (rawAnalogValue * double(espV_value / 4095.0)) * double(100.00 / divRato);
  187.       //readingsV += double(analogRead(arcVoltPin)) * double(100.00 / divRato);
  188.     }
  189.     if (counterVo == sampleReadV) {
  190.       ArcV = readingsV / sampleReadV;
  191.       counterVo = 0;
  192.       readingsV = 0;
  193.     }
  194.  
  195.   } else {
  196.     // Read voltage value from ADC
  197.     double rawAnalogValue = analogRead(arcVoltPin);
  198.     ArcV = (rawAnalogValue * double(espV_value / 4095.0)) * double(100.00 / divRato);
  199.     //ArcV = double(analogRead(arcVoltPin)) * double(100.00 / divRato);
  200.   }
  201.  
  202.  
  203.   checkButton();
  204.   checkMenu();
  205.   doTHC();
  206.   doLCD();
  207.  
  208.   //RS232();
  209. }
Advertisement
Add Comment
Please, Sign In to add comment