I have designed and built a transformer driver board for my spot welder. It is powered from mains electricity (230 V) and consists of the following segments: triac drive and protection, zero cross detection, controller input, connections. The board operates correctly when voltage is manually applied. However, I'm not able to make it work with Arduino.

Main board shematic. What I want it to do is:

  1. Read the potentiometer(R10), and assign to it value a phase angle, at which triac is going to receive pulse to turn on.
  2. Read Potentiometer (R9), and assigned to it value number of pulses(1-100) for a triac,
  3. Read switch (Power_pulse) that when high start triac firing procedure (angle and duration determined by pots)
  4. I have an I2C display 16x4 that(can be driven directly from SCL and SDA on Leonardo) I might use to display welding parameters(optional goal) The code I found on "electronoobs.com"

       int detectado = 0;
        int valor=0;
         int last_CH1_state = 0;
       void setup() {
      PCICR |= (1 << PCIE0);    //enable PCMSK0 scan                                                 
      PCMSK0 |= (1 << PCINT0);  //Set pin D8 trigger an interrupt on state change. Input from optocoupler
      pinMode(3,OUTPUT);        //Define D3 as output for the DIAC pulse
    void loop() {
       //Read the value of the pot and map it from 10 to 10.000 us. AC frequency is 50Hz, so period is 20ms. We want to control the power
       //of each half period, so the maximum is 10ms or 10.000us. In my case I've maped it up to 7.200us since 10.000 was too much
       valor = map(analogRead(A0),0,1024,7200,10);
        if (detectado)
          delayMicroseconds(valor); //This delay controls the power
    //This is the interruption routine
      /////////////////////////////////////               //Input from optocoupler
      if(PINB & B00000001){                               //We make an AND with the pin state register, We verify if pin 8 is HIGH???
        if(last_CH1_state == 0){                          //If the last state was 0, then we have a state change...
          detectado=1;                                    //We haev detected a state change!
      else if(last_CH1_state == 1){                       //If pin 8 is LOW and the last state was HIGH then we have a state change      
        detectado=1;                                      //We haev detected a state change!
        last_CH1_state = 0;                               //Store the  current state into the last state for the next loop

Finally the question: What do I need to add to this code to make it work in my application?

PS. Issues regarding safety are addressed by another board that have fuse and over voltage protection.

PPS. I have 5V supply dedicated to driving the board and Arduino.

enter code here
void setup() {


 int faza=0;
 int cykle=1;
 bool wcisniety;

  void loop() {

    faza=20000 * analogRead(2) / 255;// Pot 1
    cykle=100 * analogRead(3) / 255; //Pot2

  if(digitalRead(4) && (! wcisniety))// if cheacks for button pres to activate function



 void zgrzewaj(){

   while (digitalRead(0)){


  for (int i=0; i < cykle;i++){




digitalWrite(1,LOW);// fireing TRIAC 

This is what i come up with. While it looks simple and proprly build still dont hav any output. All coments appreciated.

  • Link to project page at electronoobs: electronoobs.com/eng_circuitos_tut20.php @Pioter, the arduino leonardo has an other microcontroller than the arduino uno and at electronoobs they use an arduino uno. – Jot Jan 22 at 19:48
  • The higher level functions do the same, for example digitalWrite( 13, HIGH). Everything below that is different. – Jot Jan 22 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.