Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
83 views
in Technique[技术] by (71.8m points)

Electric line plug activate Arduino alarm

Good afternoon and thanks in advance. I have made a small alarm with an Arduino Uno board which in simulation with Proteus and in real execution works correctly but fails when I plug anything into another socket in the electric line of the house.

For example, the circuit works normally connected to the household current but if I turn on a nightstand or plug in the soldering iron, the circuit takes this event as an intrusion of the alarm.

Tried all sorts of things, changed the source, plugged it into another outlet, etc. but the error keeps happening.

Schematic:

enter image description here

Application code:

#define LED_AMARILLO 1
#define SIRENA 2
#define LED_ROJO 3
#define LED_VERDE 4
#define SENSOR_GALPON 13
#define SENSOR_PANICO 12
#define SENSOR_COMEDOR 11
#define TIEMPO_SONANDO 60000
#define TIEMPO_ESPERANDO_VOLVER_A_SONAR 30000

///////////////////////////////////////////////////

boolean calibrado = false;

///////////////////////////////////////////////////

  void setup()
  {
    pinMode(SENSOR_GALPON,INPUT_PULLUP);
    pinMode(SENSOR_PANICO,INPUT_PULLUP);
    pinMode(SENSOR_COMEDOR,INPUT);
 
    pinMode(SIRENA,OUTPUT);
    pinMode(LED_AMARILLO,OUTPUT);
    pinMode(LED_ROJO,OUTPUT);
    pinMode(LED_VERDE,OUTPUT);

    digitalWrite(SIRENA,LOW);
    digitalWrite(LED_AMARILLO,LOW);
    digitalWrite(LED_ROJO,LOW);
    digitalWrite(LED_VERDE,LOW);
  }

///////////////////////////////////////////////////
  
  void loop()
  {
    
    if (calibrado == false)
    {
      calibrando(60000);
    }
    else
    {
      /*--------------------------------*/
      /*--VIGILANDO--*/
      
      ledVerdeOn();
      
      if(digitalRead(SENSOR_PANICO)==HIGH) 
      { 
        sirenaOn();
      }
      else
      {
        sirenaOff();
      }
  
      /*--------------------------------*/
      
      if(digitalRead(SENSOR_GALPON)==HIGH) 
      { 
        sirenaOn();
        ledVerdeOff();
        ledRojoOn();
        delay(TIEMPO_SONANDO);
        sirenaOff();
        delay(TIEMPO_ESPERANDO_VOLVER_A_SONAR);
        resonar(3);
      }
     
  
      /*--------------------------------*/
      
      if(digitalRead(SENSOR_COMEDOR)==HIGH) 
      { 
        sirenaOn();
        ledVerdeOff();
        ledRojoOn();
        delay(TIEMPO_SONANDO);
        sirenaOff();
        delay(TIEMPO_ESPERANDO_VOLVER_A_SONAR);
        resonar(3);
      }
  
      /*--------------------------------*/
    }//calibrado
    
  }//loop

///////////////////////////////////////////////////

  void sirenaOn() 
  { 
     digitalWrite(SIRENA, HIGH);
  }

///////////////////////////////////////////////////


  void sirenaOff() 
  { 
     digitalWrite(SIRENA, LOW);
  }

///////////////////////////////////////////////////

  void resonar(int veces)
  {
    int i = 0;
    while (i < veces)
    {
      sirenaOn();
      delay(TIEMPO_SONANDO);
      sirenaOff();
      delay(TIEMPO_ESPERANDO_VOLVER_A_SONAR);
      i++;
    }
    
  }

///////////////////////////////////////////////////

  void calibrando(long milisegundos)
  {
    
      ledAmarilloOn();
      delay(milisegundos);
      calibrado = true;
      ledAmarilloOff();

  }

///////////////////////////////////////////////////

  void ledAmarilloOn() 
  { 
    digitalWrite(LED_AMARILLO, HIGH);
  }

///////////////////////////////////////////////////

  void ledAmarilloOff() 
  { 
    digitalWrite(LED_AMARILLO, LOW);
  }

///////////////////////////////////////////////////

  void ledRojoOn() 
  { 
    digitalWrite(LED_ROJO, HIGH);
  }

///////////////////////////////////////////////////

  void ledRojoOff() 
  { 
    digitalWrite(LED_ROJO, LOW);
  }

///////////////////////////////////////////////////

  void ledVerdeOn() 
  { 
    digitalWrite(LED_VERDE, HIGH);
  }

///////////////////////////////////////////////////

  void ledVerdeOff() 
  { 
    digitalWrite(LED_VERDE, LOW);
  }

///////////////////////////////////////////////////
question from:https://stackoverflow.com/questions/65892508/electric-line-plug-activate-arduino-alarm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It looks like your circuit is a victim of electrical noise. If you run long wires, they should be terminated properly. Have you tried adding small caps, around 100nF near the arduino inputs to these long wires? I'd also add a 10K resistor in series, and, VERY IMPORTANT two diodes to limit the voltage input to gound and +5V. (between the resistor and the arduino)

Protection diodes can be signal diodes, 1N914 or 1N4148 should be fine, since they are protected by the 10K resistor.

If you have any other long wires, they should have at minimum the diode protection. Even the outputs. Never connect a micro-processor, or any CMOS to long wires without this diode protection. Electrical noise can fry your chip.

I have shown basic protection on two of your inputs. You should do the same for the input running to B1 as well, if that's a long wire.

All long wires should be twisted pairs as well, again to reduce noise.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...