1

I am making a triac-controlled light dimmer. To control the triac I want to use pins A4 or A5, because others are occupied. I have tried the following functions and methods, but nothing seems to put the pins to HIGH state:

 1. pinMode(A4, OUTPUT);    
    digitalWrite(A4, HIGH);
 2. pinMode(18,OUTPUT);  
    digitalWrite(18,HIGH);
 3. DDRC |= (1 << DDC4);  
    PORTC |= (1 << PC4);

I have tried the same things with A5 and other A# pins to no avail. The only pin that works is A0. Only when the triac is connected to it, the lamp lights on.

Is this a valid way to set analog pins?

void setup(){  
  pinMode(A4, OUTPUT);  
}

void loop(){  
  digitalWrite(A4, HIGH);
}
  • Edit: My code was quite messy, it appears that some other functions prevented from using pins A4 or A5. It is working now.
  • It was the DS1307Emulator library. After initialization I had to use DS1307Emulator.busDisconnect(); Didn't know it uses I2C.

Schematic

10
  • I feel that the code is ok. How can you be sure that the pin is not in high state? Only with the triac? Can you post the schematic here?
    – frarugi87
    Sep 27, 2017 at 7:19
  • Do you use a Atmega328p chip and not an Arduino board ? Did you forget to apply 5V to all the VCC and AVCC pins ? and GND to all the GND pins ? If you have done everything right, then the Atmega32p is broken.
    – Jot
    Sep 27, 2017 at 8:08
  • @fra Actually the pin is in high state when measuring with voltmeter, but when it is connected to the triac, the lamp does not light up, however, it does when it is connected to A0.
    – flowian
    Sep 27, 2017 at 12:55
  • 1
    Got it to work, it appears that there were some things in code which prevented A4 and A5 to set output as high. I am still not sure what it was.
    – flowian
    Sep 28, 2017 at 5:48
  • 1
    @flowian Can you add " Edit: My code was quite messy, it appears that some other functions prevented from using pins A4 or A5. It is working now. It was the DS1307Emulator library. After initialization I had to use DS1307Emulator.busDisconnect(); Didn't know it uses I2C." as a answer and close this question?
    – MatsK
    Sep 28, 2017 at 11:21

1 Answer 1

0

My code was quite messy, it appears that some other functions prevented from using pins A4 or A5. It is working now. It was the DS1307Emulator library. After initialization I had to use DS1307Emulator.busDisconnect(); Didn't know it uses I2C.

2
  • DS1307 is an I2C device indeed. When I saw you were using A4/A5, an I2C issue was my first thought... Why are you using this library? Do you have an RTC connected to your board?
    – dda
    Sep 28, 2017 at 12:47
  • @dda RTC is not connected to the board, the library is used for internal real-time keeping, which is then displayed on LCD. So there is no need of external RTC module.
    – flowian
    Sep 29, 2017 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.