Selasa, 25 Oktober 2022

Rangkaian remote sepeda motor (Kunci kontak, Suara Car lock, Hazard, dan Suara Bep dari buzzer)

Baca Disclaimer sebelum membaca / menonton video.

Halo Rek! Kali ini Ruang Teknik akan sharing skema rangkaian remote sepeda motor buatan sendiri, ide awal sebenarnya simple pingin bisa menyalakan lampu hazard pada sepeda motor dengan remote kontrol tujuannya jika kita parkir malem hari di tempat pasar malem yang kurang penerangan, maka dengan menyalakan hazard akan mempermudah menemukan sepeda motor kita ditempat parkir. Karna sangat bersemangat membuatnya tidak terasa saya tambah beberapa fitur sekalian jadi lebih lengkap. Oke silahkan cek gambar skema dibawah ini dan ikuti langkah dan keterangan yang diberikan.







Disini kita membutuhkan:
  • Modul remote + receiver
  • Arduino nano
  • Resistor 10K 4 pcs
  • Modul relay 4 pcs
  • Buzzer
  • Modul MP3 player (untuk memainkan suara Car Lock)

Rangkai sesuai skema diatas dan ikuti penjelasan dibawah ini:
  • Relay kunci kontak digunakan untuk menyambung jalur listrik kunci kontak jadi kita harus memotong kabel dan menyambungkannya melalui relay
  • Relay Car Lock, disini kita menggunakan modul Mp3 player/DF player jadi kita hanya perlu menyambung sumber 5V pada modul melalui relay
  • Relay Hazard, kita akan mengabungkan kedua jalur lampu Sein menjadi satu kemudian menyambungkannya melalui relay
  • Relay piezo buzzer kita sambungkan melalui relay

  1. Kunci kontak: disini relay digunakan untuk menyambung jalur kelistrikan kunci kontak sepeda motor. Jadi walaupun kunci kontak sudah dinyalakan tetapi jika tombol remote A belum ditekan maka sepeda motor tidak akan bisa distarter. Untuk menyalakan tekan tombol A satu kali untuk mematikan tekan tombol A satu kali. Catatan: Ketika relay menyala maka secara default koding di set untuk menyalakan suara car lock & hazard sekaligus
  2. Suara Car Lock: ketika tombol B ditekan maka suara car lock tidak berbunyi untuk menyalakan silahkan ditekan kembali. Tujuannya kadang ketika menyalakan Tombol A kita tidak mau suara car lock berbunyi jadi bisa dimatikan secara manual.
  3. Hazard: ketika tombol C ditekan maka lampu Hazard tidak menyala untuk menyalakan silahkan ditekan kembali.. Tujuannya kadang ketika menyalakan Tombol A kita tidak mau Hazard menyala jadi bisa dimatikan secara manual.
  4. Suara Bep ini hanyalah sebagai indikator saja (opsional tidak perlu juga tidak apa-apa), jadi ketika Tombol A, B atau C ditekan maka akan piezo buzzer akan berbunyi sehingga kita tahu bahwa remote telah bekerja. Khusus Tombol A suara buzzer baru berbunyi jika kondisi relay off
  5. Tombol D berfungsi untuk menyalakan Suara Car Lock dan Hazard, walaupun tombol A belum ditekan.

Berikut koding arduino, copy paste seluruh coding dan paste ke dalam software Arduino IDE kosongan tanpa void setup dan void loop:


#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <avr/io.h>
#include <avr/interrupt.h>

volatile uint8_t timerOF=0;
#define OVERSAMPLES 10
static volatile uint16_t adcData;
static volatile uint16_t ADCtotal;
static volatile uint8_t adcDataL;
static volatile uint8_t adcDataH;
static volatile uint8_t sample_count;
ISR(TIMER0_OVF_vect){timerOF=1;}
ISR(ADC_vect)
{
    adcDataL = ADCL;
    adcDataH = ADCH;
    adcData = 0;
    adcData = adcData | adcDataH;
    adcData = adcData << 8;
    adcData = adcData | adcDataL;
    ADCtotal = ADCtotal+adcData;
    sample_count ++;
}
int16_t do_math(int16_t A,int16_t B,char Operator)
{
    int32_t result = 0;
    if (Operator == '+'){result = A+B;}
    if (Operator == '-'){result = A-B;}
    if (Operator == '*'){result = A*B;}
    if (Operator == '/'){result = A/B;}
//    if (Operator == '='){result = A = B;}
    int16_t i =  ((result >> 0) & 0xffff);
   return i;
}
uint16_t read_adc(uint8_t channel)
{
    ADMUX = channel;// set channel
    ADMUX |=  (1<<REFS0);// sets ref volts to Vcc
    ADCSRA |= (1<<ADEN); // enable the ADC
    sample_count = 0; ADCtotal = 0;//clear sample count
    ADCSRA |= (1<<ADSC);//start conversion
    //read adcData done in interrupt
    while (sample_count < OVERSAMPLES){asm volatile ("nop"::);}//wait for completion
    ADCSRA &=~ (1<<ADEN); // stop the ADC
    return (ADCtotal/OVERSAMPLES); //mx osamples = 63  othewise will overflow total register with 10 bit adc results
}
int main()
{
//set up ADC
    ADCSRA |= ( (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) );//  sets adc clock prescaler to 128 //checked
    ADCSRA |= (1<<ADIE); // enable ADC conversion complete interrupt
    ADCSRA |= (1<<ADATE);// set to auto trigger (free running by default)
   DDRD |= (1<<5);
   DDRD |= (1<<6);
   DDRD |= (1<<7);
   DDRB |= (1<<0);
   DDRB |= (1<<3);
   DDRB |= (1<<4);
   DDRB |= (1<<5);

   PORTC |= (1<<4);
   PORTC |= (1<<5);
   PORTD |= (1<<2);
   PORTD |= (1<<3);
   PORTD |= (1<<4);

    //set up loop timer:
    TIMSK0 |= (1<<TOIE0);// overflow capture enable
    TCNT0 = 101;// start at this
    TCCR0B |= ((1<<CS10)|(1<<CS12));// timer started with /1024 prescaler
     sei();
    uint8_t cont_S1_NC = 1;
    uint8_t output_A1 = 0;
    uint8_t branch_1_0 = 0;
    uint8_t cont_A1_NO = 0;
    uint8_t branch_2_0 = 0;
    uint8_t cont_A2_NO = 0;
    uint8_t branch_1_2 = 0;
    uint8_t cont_A1_NC = 1;
    uint8_t branch_2_2 = 0;
    uint8_t cont_A3_NC = 1;
    uint8_t output_A2 = 0;
    uint8_t branch_3_0 = 0;
    uint8_t cont_A3_NO = 0;
    uint8_t branch_4_0 = 0;
    uint8_t output_A3 = 0;
    uint8_t output_K1 = 0;
    uint8_t cont_S2_NC = 1;
    uint8_t output_AA1 = 0;
    uint8_t branch_8_0 = 0;
    uint8_t cont_AA1_NO = 0;
    uint8_t branch_9_0 = 0;
    uint8_t cont_AA2_NO = 0;
    uint8_t branch_8_2 = 0;
    uint8_t cont_AA1_NC = 1;
    uint8_t branch_9_2 = 0;
    uint8_t cont_AA3_NC = 1;
    uint8_t output_AA2 = 0;
    uint8_t branch_10_0 = 0;
    uint8_t cont_AA3_NO = 0;
    uint8_t branch_11_0 = 0;
    uint8_t output_AA3 = 0;
    uint8_t output_K2 = 0;
    uint8_t cont_S3_NC = 1;
    uint8_t output_AAA1 = 0;
    uint8_t branch_15_0 = 0;
    uint8_t cont_AAA1_NO = 0;
    uint8_t branch_16_0 = 0;
    uint8_t cont_AAA2_NO = 0;
    uint8_t branch_15_2 = 0;
    uint8_t cont_AAA1_NC = 1;
    uint8_t branch_16_2 = 0;
    uint8_t cont_AAA3_NC = 1;
    uint8_t output_AAA2 = 0;
    uint8_t branch_17_0 = 0;
    uint8_t cont_AAA3_NO = 0;
    uint8_t branch_18_0 = 0;
    uint8_t output_AAA3 = 0;
    uint8_t output_K3 = 0;
    uint8_t branch_21_0 = 0;
    uint8_t cont_S4_NC = 1;
    uint8_t branch_22_0 = 0;
    uint8_t cont_K4_NO = 0;
    uint8_t cont_K5_NC = 1;
    uint8_t output_K4 = 0;

    uint8_t Timer_T1 = 0;
    uint16_t setpoint_Timer_T1 = 300;
    uint16_t reg_Timer_T1 = 0;

    uint8_t prev_rungstate_Timer_T1 = 0;
    uint8_t rungstate_Timer_T1 = 0;

    uint8_t run_Timer_T1 = 0;

    uint8_t output_K5 = 0;

    uint8_t Timer_T2 = 0;
    uint16_t setpoint_Timer_T2 = 300;
    uint16_t reg_Timer_T2 = 0;

    uint8_t prev_rungstate_Timer_T2 = 0;
    uint8_t rungstate_Timer_T2 = 0;

    uint8_t run_Timer_T2 = 0;

    uint8_t output_K6 = 0;
    uint8_t branch_26_0 = 0;
    uint8_t cont_Z1_NO = 0;
    uint8_t branch_27_0 = 0;
    uint8_t cont_Z2_NO = 0;
    uint8_t output_Piezo = 0;
    uint8_t branch_28_0 = 0;
    uint8_t branch_29_0 = 0;
    uint8_t output_Z1 = 0;
    uint8_t output_Z2 = 0;
    uint8_t branch_33_0 = 0;
    uint8_t cont_K1_NO = 0;
    uint8_t cont_K6_NC = 1;
    uint8_t cont_K7_NC = 1;
    uint8_t branch_34_0 = 0;
    uint8_t cont_K2_NC = 1;
    uint8_t output_Alarm = 0;
    uint8_t branch_35_0 = 0;
    uint8_t branch_36_0 = 0;
    uint8_t cont_K3_NC = 1;
    uint8_t cont_K8_NC = 1;
    uint8_t cont_K10_NC = 1;
    uint8_t output_Hazard = 0;
    uint8_t output_Starter = 0;

    uint8_t Timer_T3 = 0;
    uint16_t setpoint_Timer_T3 = 300;
    uint16_t reg_Timer_T3 = 0;

    uint8_t prev_rungstate_Timer_T3 = 0;
    uint8_t rungstate_Timer_T3 = 0;

    uint8_t run_Timer_T3 = 0;

    uint8_t output_K7 = 0;
    uint8_t cont_K9_NC = 1;

    uint8_t Timer_T4 = 0;
    uint16_t setpoint_Timer_T4 = 20;
    uint16_t reg_Timer_T4 = 0;

    uint8_t prev_rungstate_Timer_T4 = 0;
    uint8_t rungstate_Timer_T4 = 0;

    uint8_t run_Timer_T4 = 0;

    uint8_t output_K8 = 0;
    uint8_t cont_K8_NO = 0;

    uint8_t Timer_T5 = 0;
    uint16_t setpoint_Timer_T5 = 20;
    uint16_t reg_Timer_T5 = 0;

    uint8_t prev_rungstate_Timer_T5 = 0;
    uint8_t rungstate_Timer_T5 = 0;

    uint8_t run_Timer_T5 = 0;

    uint8_t output_K9 = 0;
    uint8_t cont_K11_NC = 1;

    uint8_t Timer_T6 = 0;
    uint16_t setpoint_Timer_T6 = 20;
    uint16_t reg_Timer_T6 = 0;

    uint8_t prev_rungstate_Timer_T6 = 0;
    uint8_t rungstate_Timer_T6 = 0;

    uint8_t run_Timer_T6 = 0;

    uint8_t output_K10 = 0;
    uint8_t cont_K10_NO = 0;

    uint8_t Timer_T7 = 0;
    uint16_t setpoint_Timer_T7 = 20;
    uint16_t reg_Timer_T7 = 0;

    uint8_t prev_rungstate_Timer_T7 = 0;
    uint8_t rungstate_Timer_T7 = 0;

    uint8_t run_Timer_T7 = 0;

    uint8_t output_K11 = 0;
    uint8_t W = 1;
    while (1)
    {
        if (timerOF == 1)
        {
           timerOF=0;//reset timer flag
           TCNT0 = 101;// start at this
           //inputs:
           cont_S1_NC = PINC &(1<<4);
             if(output_A1 == 1){
                cont_A1_NO=1;}
             else {
                cont_A1_NO=0;} //link name
             if(output_A2 == 1){
                cont_A2_NO=1;}
             else {
                cont_A2_NO=0;} //link name
             if(output_A1 == 0){
                cont_A1_NC=1;}
             else {
                cont_A1_NC=0;} //link name
             if(output_A3 == 0){
                cont_A3_NC=1;}
             else {
                cont_A3_NC=0;} //link name
             if(output_A1 == 1){
                cont_A1_NO=1;}
             else {
                cont_A1_NO=0;} //link name
             if(output_A3 == 1){
                cont_A3_NO=1;}
             else {
                cont_A3_NO=0;} //link name
             if(output_A1 == 0){
                cont_A1_NC=1;}
             else {
                cont_A1_NC=0;} //link name
             if(output_A2 == 1){
                cont_A2_NO=1;}
             else {
                cont_A2_NO=0;} //link name
             if(output_A2 == 1){
                cont_A2_NO=1;}
             else {
                cont_A2_NO=0;} //link name
           cont_S2_NC = PINC &(1<<5);
             if(output_AA1 == 1){
                cont_AA1_NO=1;}
             else {
                cont_AA1_NO=0;} //link name
             if(output_AA2 == 1){
                cont_AA2_NO=1;}
             else {
                cont_AA2_NO=0;} //link name
             if(output_AA1 == 0){
                cont_AA1_NC=1;}
             else {
                cont_AA1_NC=0;} //link name
             if(output_AA3 == 0){
                cont_AA3_NC=1;}
             else {
                cont_AA3_NC=0;} //link name
             if(output_AA1 == 1){
                cont_AA1_NO=1;}
             else {
                cont_AA1_NO=0;} //link name
             if(output_AA3 == 1){
                cont_AA3_NO=1;}
             else {
                cont_AA3_NO=0;} //link name
             if(output_AA1 == 0){
                cont_AA1_NC=1;}
             else {
                cont_AA1_NC=0;} //link name
             if(output_AA2 == 1){
                cont_AA2_NO=1;}
             else {
                cont_AA2_NO=0;} //link name
             if(output_AA2 == 1){
                cont_AA2_NO=1;}
             else {
                cont_AA2_NO=0;} //link name
           cont_S3_NC = PIND &(1<<2);
             if(output_AAA1 == 1){
                cont_AAA1_NO=1;}
             else {
                cont_AAA1_NO=0;} //link name
             if(output_AAA2 == 1){
                cont_AAA2_NO=1;}
             else {
                cont_AAA2_NO=0;} //link name
             if(output_AAA1 == 0){
                cont_AAA1_NC=1;}
             else {
                cont_AAA1_NC=0;} //link name
             if(output_AAA3 == 0){
                cont_AAA3_NC=1;}
             else {
                cont_AAA3_NC=0;} //link name
             if(output_AAA1 == 1){
                cont_AAA1_NO=1;}
             else {
                cont_AAA1_NO=0;} //link name
             if(output_AAA3 == 1){
                cont_AAA3_NO=1;}
             else {
                cont_AAA3_NO=0;} //link name
             if(output_AAA1 == 0){
                cont_AAA1_NC=1;}
             else {
                cont_AAA1_NC=0;} //link name
             if(output_AAA2 == 1){
                cont_AAA2_NO=1;}
             else {
                cont_AAA2_NO=0;} //link name
             if(output_AAA2 == 1){
                cont_AAA2_NO=1;}
             else {
                cont_AAA2_NO=0;} //link name
           cont_S4_NC = PIND &(1<<3);
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_K5 == 0){
                cont_K5_NC=1;}
             else {
                cont_K5_NC=0;} //link name
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_Z1 == 1){
                cont_Z1_NO=1;}
             else {
                cont_Z1_NO=0;} //link name
             if(output_Z2 == 1){
                cont_Z2_NO=1;}
             else {
                cont_Z2_NO=0;} //link name
             if(output_A3 == 1){
                cont_A3_NO=1;}
             else {
                cont_A3_NO=0;} //link name
             if(output_K1 == 1){
                cont_K1_NO=1;}
             else {
                cont_K1_NO=0;} //link name
             if(output_K6 == 0){
                cont_K6_NC=1;}
             else {
                cont_K6_NC=0;} //link name
             if(output_K7 == 0){
                cont_K7_NC=1;}
             else {
                cont_K7_NC=0;} //link name
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_K6 == 0){
                cont_K6_NC=1;}
             else {
                cont_K6_NC=0;} //link name
             if(output_K2 == 0){
                cont_K2_NC=1;}
             else {
                cont_K2_NC=0;} //link name
             if(output_K1 == 1){
                cont_K1_NO=1;}
             else {
                cont_K1_NO=0;} //link name
             if(output_K7 == 0){
                cont_K7_NC=1;}
             else {
                cont_K7_NC=0;} //link name
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_K3 == 0){
                cont_K3_NC=1;}
             else {
                cont_K3_NC=0;} //link name
             if(output_K8 == 0){
                cont_K8_NC=1;}
             else {
                cont_K8_NC=0;} //link name
             if(output_K10 == 0){
                cont_K10_NC=1;}
             else {
                cont_K10_NC=0;} //link name
             if(output_K1 == 1){
                cont_K1_NO=1;}
             else {
                cont_K1_NO=0;} //link name
             if(output_K1 == 1){
                cont_K1_NO=1;}
             else {
                cont_K1_NO=0;} //link name
             if(output_K1 == 1){
                cont_K1_NO=1;}
             else {
                cont_K1_NO=0;} //link name
             if(output_K1 == 1){
                cont_K1_NO=1;}
             else {
                cont_K1_NO=0;} //link name
             if(output_K1 == 1){
                cont_K1_NO=1;}
             else {
                cont_K1_NO=0;} //link name
             if(output_K7 == 0){
                cont_K7_NC=1;}
             else {
                cont_K7_NC=0;} //link name
             if(output_K9 == 0){
                cont_K9_NC=1;}
             else {
                cont_K9_NC=0;} //link name
             if(output_K1 == 1){
                cont_K1_NO=1;}
             else {
                cont_K1_NO=0;} //link name
             if(output_K7 == 0){
                cont_K7_NC=1;}
             else {
                cont_K7_NC=0;} //link name
             if(output_K9 == 0){
                cont_K9_NC=1;}
             else {
                cont_K9_NC=0;} //link name
             if(output_K8 == 1){
                cont_K8_NO=1;}
             else {
                cont_K8_NO=0;} //link name
             if(output_K8 == 1){
                cont_K8_NO=1;}
             else {
                cont_K8_NO=0;} //link name
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_K11 == 0){
                cont_K11_NC=1;}
             else {
                cont_K11_NC=0;} //link name
             if(output_K4 == 1){
                cont_K4_NO=1;}
             else {
                cont_K4_NO=0;} //link name
             if(output_K11 == 0){
                cont_K11_NC=1;}
             else {
                cont_K11_NC=0;} //link name
             if(output_K10 == 1){
                cont_K10_NO=1;}
             else {
                cont_K10_NO=0;} //link name
             if(output_K10 == 1){
                cont_K10_NO=1;}
             else {
                cont_K10_NO=0;} //link name

            //Start of Ladder:
            //rung at 0
             W = 1;
             if(cont_S1_NC == 0){W = 0;}
              output_A1 = W;
            //end rung

            //rung at 1
             W = 1;
             branch_1_0 = 1;
             if(cont_A1_NO == 0){branch_1_0 = 0;}
             branch_2_0 = 1;
             if(cont_A2_NO == 0){branch_2_0 = 0;}
             if( (branch_2_0 == 0) && (branch_1_0 == 0 )) {W = 0;} //node_[1, 0]
             if( (branch_2_0 == 2) || (branch_1_0 == 2 )) {W = 1;} //node_[1, 0] if is latching element
             branch_1_2 = 1;
             if(cont_A1_NC == 0){branch_1_2 = 0;}
             branch_2_2 = 1;
             if(cont_A3_NC == 0){branch_2_2 = 0;}
             if( (branch_2_2 == 0) && (branch_1_2 == 0 )) {W = 0;} //node_[1, 2]
             if( (branch_2_2 == 2) || (branch_1_2 == 2 )) {W = 1;} //node_[1, 2] if is latching element
              output_A2 = W;
            //end rung

            //rung at 3
             W = 1;
             branch_3_0 = 1;
             if(cont_A1_NO == 0){branch_3_0 = 0;}
             if(cont_A3_NO == 0){branch_3_0 = 0;}
             branch_4_0 = 1;
             if(cont_A1_NC == 0){branch_4_0 = 0;}
             if(cont_A2_NO == 0){branch_4_0 = 0;}
             if( (branch_4_0 == 0) && (branch_3_0 == 0 )) {W = 0;} //node_[3, 2]
             if( (branch_4_0 == 2) || (branch_3_0 == 2 )) {W = 1;} //node_[3, 2] if is latching element
              output_A3 = W;
            //end rung

            //rung at 5
             W = 1;
             if(cont_A2_NO == 0){W = 0;}
              output_K1 = W;
            //end rung

            //rung at 7
             W = 1;
             if(cont_S2_NC == 0){W = 0;}
              output_AA1 = W;
            //end rung

            //rung at 8
             W = 1;
             branch_8_0 = 1;
             if(cont_AA1_NO == 0){branch_8_0 = 0;}
             branch_9_0 = 1;
             if(cont_AA2_NO == 0){branch_9_0 = 0;}
             if( (branch_9_0 == 0) && (branch_8_0 == 0 )) {W = 0;} //node_[8, 0]
             if( (branch_9_0 == 2) || (branch_8_0 == 2 )) {W = 1;} //node_[8, 0] if is latching element
             branch_8_2 = 1;
             if(cont_AA1_NC == 0){branch_8_2 = 0;}
             branch_9_2 = 1;
             if(cont_AA3_NC == 0){branch_9_2 = 0;}
             if( (branch_9_2 == 0) && (branch_8_2 == 0 )) {W = 0;} //node_[8, 2]
             if( (branch_9_2 == 2) || (branch_8_2 == 2 )) {W = 1;} //node_[8, 2] if is latching element
              output_AA2 = W;
            //end rung

            //rung at 10
             W = 1;
             branch_10_0 = 1;
             if(cont_AA1_NO == 0){branch_10_0 = 0;}
             if(cont_AA3_NO == 0){branch_10_0 = 0;}
             branch_11_0 = 1;
             if(cont_AA1_NC == 0){branch_11_0 = 0;}
             if(cont_AA2_NO == 0){branch_11_0 = 0;}
             if( (branch_11_0 == 0) && (branch_10_0 == 0 )) {W = 0;} //node_[10, 2]
             if( (branch_11_0 == 2) || (branch_10_0 == 2 )) {W = 1;} //node_[10, 2] if is latching element
              output_AA3 = W;
            //end rung

            //rung at 12
             W = 1;
             if(cont_AA2_NO == 0){W = 0;}
              output_K2 = W;
            //end rung

            //rung at 14
             W = 1;
             if(cont_S3_NC == 0){W = 0;}
              output_AAA1 = W;
            //end rung

            //rung at 15
             W = 1;
             branch_15_0 = 1;
             if(cont_AAA1_NO == 0){branch_15_0 = 0;}
             branch_16_0 = 1;
             if(cont_AAA2_NO == 0){branch_16_0 = 0;}
             if( (branch_16_0 == 0) && (branch_15_0 == 0 )) {W = 0;} //node_[15, 0]
             if( (branch_16_0 == 2) || (branch_15_0 == 2 )) {W = 1;} //node_[15, 0] if is latching element
             branch_15_2 = 1;
             if(cont_AAA1_NC == 0){branch_15_2 = 0;}
             branch_16_2 = 1;
             if(cont_AAA3_NC == 0){branch_16_2 = 0;}
             if( (branch_16_2 == 0) && (branch_15_2 == 0 )) {W = 0;} //node_[15, 2]
             if( (branch_16_2 == 2) || (branch_15_2 == 2 )) {W = 1;} //node_[15, 2] if is latching element
              output_AAA2 = W;
            //end rung

            //rung at 17
             W = 1;
             branch_17_0 = 1;
             if(cont_AAA1_NO == 0){branch_17_0 = 0;}
             if(cont_AAA3_NO == 0){branch_17_0 = 0;}
             branch_18_0 = 1;
             if(cont_AAA1_NC == 0){branch_18_0 = 0;}
             if(cont_AAA2_NO == 0){branch_18_0 = 0;}
             if( (branch_18_0 == 0) && (branch_17_0 == 0 )) {W = 0;} //node_[17, 2]
             if( (branch_18_0 == 2) || (branch_17_0 == 2 )) {W = 1;} //node_[17, 2] if is latching element
              output_AAA3 = W;
            //end rung

            //rung at 19
             W = 1;
             if(cont_AAA2_NO == 0){W = 0;}
              output_K3 = W;
            //end rung

            //rung at 21
             W = 1;
             branch_21_0 = 1;
             if(cont_S4_NC == 0){branch_21_0 = 0;}
             branch_22_0 = 1;
             if(cont_K4_NO == 0){branch_22_0 = 0;}
             if( (branch_22_0 == 0) && (branch_21_0 == 0 )) {W = 0;} //node_[21, 0]
             if( (branch_22_0 == 2) || (branch_21_0 == 2 )) {W = 1;} //node_[21, 0] if is latching element
             if(cont_K5_NC == 0){W = 0;}
              output_K4 = W;
            //end rung

            //StateUser
            //connected to rung at 23
             W = 1;
             if(cont_K4_NO == 0){W = 0;}
             rungstate_Timer_T1 = W;
             if((prev_rungstate_Timer_T1 == 0) && (rungstate_Timer_T1 == 1)){
                run_Timer_T1=1;}
             if(run_Timer_T1 == 1){
                reg_Timer_T1++;
                if (reg_Timer_T1 == 65535) {reg_Timer_T1--;}//avoid overrun
                if (setpoint_Timer_T1 <= reg_Timer_T1) {Timer_T1=1;}
             }
             if((prev_rungstate_Timer_T1 == 1) && (rungstate_Timer_T1 == 0)){
                reg_Timer_T1=0; Timer_T1=0; run_Timer_T1=0;} //reset
             prev_rungstate_Timer_T1 = rungstate_Timer_T1;
            //end rung

            //rung at 23
             W = 1;
             if(cont_K4_NO == 0){W = 0;}
             if(Timer_T1 == 0){W = 0;}
              output_K5 = W;
            //end rung

            //StateUser
            //connected to rung at 24
             W = 1;
             if(cont_K4_NO == 0){W = 0;}
             rungstate_Timer_T2 = W;
             if((prev_rungstate_Timer_T2 == 0) && (rungstate_Timer_T2 == 1)){
                run_Timer_T2=1;}
             if(run_Timer_T2 == 1){
                reg_Timer_T2++;
                if (reg_Timer_T2 == 65535) {reg_Timer_T2--;}//avoid overrun
                if (setpoint_Timer_T2 <= reg_Timer_T2) {Timer_T2=1;}
             }
             if((prev_rungstate_Timer_T2 == 1) && (rungstate_Timer_T2 == 0)){
                reg_Timer_T2=0; Timer_T2=0; run_Timer_T2=0;} //reset
             prev_rungstate_Timer_T2 = rungstate_Timer_T2;
            //end rung

            //rung at 24
             W = 1;
             if(cont_K4_NO == 0){W = 0;}
             if(Timer_T2 == 0){W = 0;}
              output_K6 = W;
            //end rung

            //rung at 26
             W = 1;
             branch_26_0 = 1;
             if(cont_Z1_NO == 0){branch_26_0 = 0;}
             branch_27_0 = 1;
             if(cont_Z2_NO == 0){branch_27_0 = 0;}
             if( (branch_27_0 == 0) && (branch_26_0 == 0 )) {W = 0;} //node_[26, 0]
             if( (branch_27_0 == 2) || (branch_26_0 == 2 )) {W = 1;} //node_[26, 0] if is latching element
              output_Piezo = W;
            //end rung

            //rung at 28
             W = 1;
             branch_28_0 = 1;
             if(cont_S2_NC == 0){branch_28_0 = 0;}
             branch_29_0 = 1;
             if(cont_S3_NC == 0){branch_29_0 = 0;}
             if( (branch_29_0 == 0) && (branch_28_0 == 0 )) {W = 0;} //node_[28, 0]
             if( (branch_29_0 == 2) || (branch_28_0 == 2 )) {W = 1;} //node_[28, 0] if is latching element
              output_Z1 = W;
            //end rung

            //rung at 30
             W = 1;
             if(cont_A3_NO == 0){W = 0;}
             if(cont_S1_NC == 0){W = 0;}
              output_Z2 = W;
            //end rung

            //rung at 33
             W = 1;
             branch_33_0 = 1;
             if(cont_K1_NO == 0){branch_33_0 = 0;}
             if(cont_K6_NC == 0){branch_33_0 = 0;}
             if(cont_K7_NC == 0){branch_33_0 = 0;}
             branch_34_0 = 1;
             if(cont_K4_NO == 0){branch_34_0 = 0;}
             if(cont_K6_NC == 0){branch_34_0 = 0;}
             if( (branch_34_0 == 0) && (branch_33_0 == 0 )) {W = 0;} //node_[33, 2]
             if( (branch_34_0 == 2) || (branch_33_0 == 2 )) {W = 1;} //node_[33, 2] if is latching element
             if(cont_K2_NC == 0){W = 0;}
              output_Alarm = W;
            //end rung

            //rung at 35
             W = 1;
             branch_35_0 = 1;
             if(cont_K1_NO == 0){branch_35_0 = 0;}
             if(cont_K7_NC == 0){branch_35_0 = 0;}
             branch_36_0 = 1;
             if(cont_K4_NO == 0){branch_36_0 = 0;}
             if( (branch_36_0 == 0) && (branch_35_0 == 0 )) {W = 0;} //node_[35, 1]
             if( (branch_36_0 == 2) || (branch_35_0 == 2 )) {W = 1;} //node_[35, 1] if is latching element
             if(cont_K3_NC == 0){W = 0;}
             if(cont_K8_NC == 0){W = 0;}
             if(cont_K10_NC == 0){W = 0;}
              output_Hazard = W;
            //end rung

            //rung at 37
             W = 1;
             if(cont_K1_NO == 0){W = 0;}
             if(cont_K1_NO == 0){W = 0;}
              output_Starter = W;
            //end rung

            //StateUser
            //connected to rung at 38
             W = 1;
             if(cont_K1_NO == 0){W = 0;}
             rungstate_Timer_T3 = W;
             if((prev_rungstate_Timer_T3 == 0) && (rungstate_Timer_T3 == 1)){
                run_Timer_T3=1;}
             if(run_Timer_T3 == 1){
                reg_Timer_T3++;
                if (reg_Timer_T3 == 65535) {reg_Timer_T3--;}//avoid overrun
                if (setpoint_Timer_T3 <= reg_Timer_T3) {Timer_T3=1;}
             }
             if((prev_rungstate_Timer_T3 == 1) && (rungstate_Timer_T3 == 0)){
                reg_Timer_T3=0; Timer_T3=0; run_Timer_T3=0;} //reset
             prev_rungstate_Timer_T3 = rungstate_Timer_T3;
            //end rung

            //rung at 38
             W = 1;
             if(cont_K1_NO == 0){W = 0;}
             if(Timer_T3 == 0){W = 0;}
              output_K7 = W;
            //end rung

            //StateUser
            //connected to rung at 40
             W = 1;
             if(cont_K1_NO == 0){W = 0;}
             if(cont_K7_NC == 0){W = 0;}
             if(cont_K9_NC == 0){W = 0;}
             rungstate_Timer_T4 = W;
             if((prev_rungstate_Timer_T4 == 0) && (rungstate_Timer_T4 == 1)){
                run_Timer_T4=1;}
             if(run_Timer_T4 == 1){
                reg_Timer_T4++;
                if (reg_Timer_T4 == 65535) {reg_Timer_T4--;}//avoid overrun
                if (setpoint_Timer_T4 <= reg_Timer_T4) {Timer_T4=1;}
             }
             if((prev_rungstate_Timer_T4 == 1) && (rungstate_Timer_T4 == 0)){
                reg_Timer_T4=0; Timer_T4=0; run_Timer_T4=0;} //reset
             prev_rungstate_Timer_T4 = rungstate_Timer_T4;
            //end rung

            //rung at 40
             W = 1;
             if(cont_K1_NO == 0){W = 0;}
             if(cont_K7_NC == 0){W = 0;}
             if(cont_K9_NC == 0){W = 0;}
             if(Timer_T4 == 0){W = 0;}
              output_K8 = W;
            //end rung

            //StateUser
            //connected to rung at 42
             W = 1;
             if(cont_K8_NO == 0){W = 0;}
             rungstate_Timer_T5 = W;
             if((prev_rungstate_Timer_T5 == 0) && (rungstate_Timer_T5 == 1)){
                run_Timer_T5=1;}
             if(run_Timer_T5 == 1){
                reg_Timer_T5++;
                if (reg_Timer_T5 == 65535) {reg_Timer_T5--;}//avoid overrun
                if (setpoint_Timer_T5 <= reg_Timer_T5) {Timer_T5=1;}
             }
             if((prev_rungstate_Timer_T5 == 1) && (rungstate_Timer_T5 == 0)){
                reg_Timer_T5=0; Timer_T5=0; run_Timer_T5=0;} //reset
             prev_rungstate_Timer_T5 = rungstate_Timer_T5;
            //end rung

            //rung at 42
             W = 1;
             if(cont_K8_NO == 0){W = 0;}
             if(Timer_T5 == 0){W = 0;}
              output_K9 = W;
            //end rung

            //StateUser
            //connected to rung at 44
             W = 1;
             if(cont_K4_NO == 0){W = 0;}
             if(cont_K11_NC == 0){W = 0;}
             rungstate_Timer_T6 = W;
             if((prev_rungstate_Timer_T6 == 0) && (rungstate_Timer_T6 == 1)){
                run_Timer_T6=1;}
             if(run_Timer_T6 == 1){
                reg_Timer_T6++;
                if (reg_Timer_T6 == 65535) {reg_Timer_T6--;}//avoid overrun
                if (setpoint_Timer_T6 <= reg_Timer_T6) {Timer_T6=1;}
             }
             if((prev_rungstate_Timer_T6 == 1) && (rungstate_Timer_T6 == 0)){
                reg_Timer_T6=0; Timer_T6=0; run_Timer_T6=0;} //reset
             prev_rungstate_Timer_T6 = rungstate_Timer_T6;
            //end rung

            //rung at 44
             W = 1;
             if(cont_K4_NO == 0){W = 0;}
             if(cont_K11_NC == 0){W = 0;}
             if(Timer_T6 == 0){W = 0;}
              output_K10 = W;
            //end rung

            //StateUser
            //connected to rung at 45
             W = 1;
             if(cont_K10_NO == 0){W = 0;}
             rungstate_Timer_T7 = W;
             if((prev_rungstate_Timer_T7 == 0) && (rungstate_Timer_T7 == 1)){
                run_Timer_T7=1;}
             if(run_Timer_T7 == 1){
                reg_Timer_T7++;
                if (reg_Timer_T7 == 65535) {reg_Timer_T7--;}//avoid overrun
                if (setpoint_Timer_T7 <= reg_Timer_T7) {Timer_T7=1;}
             }
             if((prev_rungstate_Timer_T7 == 1) && (rungstate_Timer_T7 == 0)){
                reg_Timer_T7=0; Timer_T7=0; run_Timer_T7=0;} //reset
             prev_rungstate_Timer_T7 = rungstate_Timer_T7;
            //end rung

            //rung at 45
             W = 1;
             if(cont_K10_NO == 0){W = 0;}
             if(Timer_T7 == 0){W = 0;}
              output_K11 = W;
            //end rung

           //outputs:
         if(output_Piezo == 0){PORTB &=~ (1<<0);}
         else {PORTB |= (1<<0);}
         if(output_Alarm == 0){PORTD &=~ (1<<6);}
         else {PORTD |= (1<<6);}
         if(output_Hazard == 0){PORTD &=~ (1<<7);}
         else {PORTD |= (1<<7);}
         if(output_Starter == 0){PORTD &=~ (1<<5);}
         else {PORTD |= (1<<5);}

       }
   }
}