I’m working on an ac dimmer circuit using Arduino and Hc - 05 bt module but the bulb stops glowing for a brief sec I’m assuming the interrupt stop working here for a brief sec rest is working fine I saw that when I disconnect the bt interrupt stop working more frequently. I have also seen that it happens when the Arduino RX led glows maybe it try to receive something while stopping the interrupt. I’m using the hardware serial.
volatile int detectado = 0;
volatile int valor=0;
volatile int last_CH1_state = 0;
int pinValue;
#include <BlynkSimpleSerialBLE.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "i8GfxSLhfmCF6QKjdqWtr5JvGh7ro0AU";
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1)
{
pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
valor = map(pinValue,90,255,7000,10);
// process received value
}
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
Serial.begin(38400);
Blynk.begin(auth, Serial);
}
void loop()
{
Blynk.run();
if (detectado)
{
delayMicroseconds(valor); //This delay controls the power
digitalWrite(3,HIGH);
delayMicroseconds(50);
digitalWrite(3,LOW);
detectado=0;
}
}
//This is the interruption routine
//----------------------------------------------
ISR(PCINT0_vect){
///////////////////////////////////// //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
}
}