Hola mi nombre es francisco, saludos a fodos. Os escribo por aquí a ver si alguien puede ayudarme. Os cuento, tengo un detector de rayos AS3935 ya configurado en mi placa Arduino Uno y la cosa es que quiero que cada vez que detecte un rayo, este altavoz emita un sonido. Tengo un buzzer activo que he probado y funciona lo que no se como incluirlo en el programa del detector de rayos. Muchas gracias.
Veo que esto no me deja adjuntar ni archivo ni me deja pegar aquí el código, dificilmente me podrán ayudar si no lo ven… ![]()
Que raro...
Deberías pulsar en </> y deberia aparecerte este texto
escribe o pega el código aquí
Por otro lado si el buzzer es activo lo puedes manejar con cualquier pin digital, solo pon en la sección donde haces la detección algo como
digitalWrite(pin_del_buzzer, HIGH); // enciende buzzer
y fuera de esa sección
digitalWrite(pin_del_buzzer, LOW; // apaga buzzer
Saludos
PD: Edita el título del tema, elimina la palabra "ayuda" (alho como "Duda con buzzer activo" va mejor), porque te van a llamar la atención.
/*
This example code will walk you through the rest of the functions not
mentioned in the other example code. This includes different ways to reduce
false events, how to power down (and what that entails) and wake up your
board, as well as how to reset all the settings to their factory defaults.
By: Elias Santistevan
SparkFun Electronics
Date: July, 2019
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
*/
#include <SPI.h>
#include <Wire.h>
#include "SparkFun_AS3935.h"
#define INDOOR 0x12
#define OUTDOOR 0xE
#define LIGHTNING_INT 0x08
#define DISTURBER_INT 0x04
#define NOISE_INT 0x01
// SPI
SparkFun_AS3935 lightning;
// Interrupt pin for lightning detection
const int lightningInt = 4;
// Chip select pin
int spiCS = 10;
// Values for modifying the IC's settings. All of these values are set to their
// default values.
byte noiseFloor = 2;
byte watchDogVal = 2;
byte spike = 2;
byte lightningThresh = 1;
// This variable holds the number representing the lightning or non-lightning
// event issued by the lightning detector.
byte intVal = 0;
void setup()
{
// When lightning is detected the interrupt pin goes HIGH.
pinMode(lightningInt, INPUT);
Serial.begin(115200);
Serial.println("AS3935 Franklin Lightning Detector");
SPI.begin(); // For SPI
if( !lightning.beginSPI(spiCS) ) {
Serial.println ("Lightning Detector did not start up, freezing!");
while(1);
}
else
Serial.println("Schmow-ZoW, Lightning Detector Ready!\n");
// "Disturbers" are events that are false lightning events. If you find
// yourself seeing a lot of disturbers you can have the chip not report those
// events on the interrupt lines.
lightning.maskDisturber(true);
int maskVal = lightning.readMaskDisturber();
Serial.print("Are disturbers being masked: ");
if (maskVal == 1)
Serial.println("YES");
else if (maskVal == 0)
Serial.println("NO");
// The lightning detector defaults to an indoor setting (less
// gain/sensitivity), if you plan on using this outdoors
// uncomment the following line:
lightning.setIndoorOutdoor(INDOOR);
int enviVal = lightning.readIndoorOutdoor();
Serial.print("Are we set for indoor or outdoor: ");
if( enviVal == INDOOR )
Serial.println("Indoor.");
else if( enviVal == OUTDOOR )
Serial.println("Outdoor.");
else
Serial.println(enviVal, BIN);
// Noise floor setting from 1-7, one being the lowest. Default setting is
// two. If you need to check the setting, the corresponding function for
// reading the function follows.
lightning.setNoiseLevel(noiseFloor);
int noiseVal = lightning.readNoiseLevel();
Serial.print("Noise Level is set at: ");
Serial.println(noiseVal);
// Watchdog threshold setting can be from 1-10, one being the lowest. Default setting is
// two. If you need to check the setting, the corresponding function for
// reading the function follows.
lightning.watchdogThreshold(watchDogVal);
int watchVal = lightning.readWatchdogThreshold();
Serial.print("Watchdog Threshold is set to: ");
Serial.println(watchVal);
// Spike Rejection setting from 1-11, one being the lowest. Default setting is
// two. If you need to check the setting, the corresponding function for
// reading the function follows.
// The shape of the spike is analyzed during the chip's
// validation routine. You can round this spike at the cost of sensitivity to
// distant events.
lightning.spikeRejection(spike);
int spikeVal = lightning.readSpikeRejection();
Serial.print("Spike Rejection is set to: ");
Serial.println(spikeVal);
// This setting will change when the lightning detector issues an interrupt.
// For example you will only get an interrupt after five lightning strikes
// instead of one. Default is one, and it takes settings of 1, 5, 9 and 16.
// Followed by its corresponding read function. Default is zero.
lightning.lightningThreshold(lightningThresh);
uint8_t lightVal = lightning.readLightningThreshold();
Serial.print("The number of strikes before interrupt is triggerd: ");
Serial.println(lightVal);
// When the distance to the storm is estimated, it takes into account other
// lightning that was sensed in the past 15 minutes. If you want to reset
// time, then you can call this function.
//lightning.clearStatistics();
// The power down function has a BIG "gotcha". When you wake up the board
// after power down, the internal oscillators will be recalibrated. They are
// recalibrated according to the resonance frequency of the antenna - which
// should be around 500kHz. It's highly recommended that you calibrate your
// antenna before using these two functions, or you run the risk of schewing
// the timing of the chip.
//lightning.powerDown();
//delay(1000);
//if( lightning.wakeUp() )
// Serial.println("Successfully woken up!");
//else
//Serial.println("Error recalibrating internal osciallator on wake up.");
// Set too many features? Reset them all with the following function.
lightning.resetSettings();
}
void loop()
{
if(digitalRead(lightningInt) == HIGH){
// Hardware has alerted us to an event, now we read the interrupt register
// to see exactly what it is.
intVal = lightning.readInterruptReg();
if(intVal == NOISE_INT){
Serial.println("Noise.");
}
else if(intVal == DISTURBER_INT){
Serial.println("Disturber.");
}
else if(intVal == LIGHTNING_INT){
Serial.println("Lightning Strike Detected!");
AQUI ES CUANDO HA DETECTADO EL RAYO Y ME GUSTARIA QUE EMITIESE UN PITIDO
// Lightning! Now how far away is it? Distance estimation takes into
// account previously seen events.
byte distance = lightning.distanceToStorm();
Serial.print("Approximately: ");
Serial.print(distance);
Serial.println("km away!");
// "Lightning Energy" and I do place into quotes intentionally, is a pure
// number that does not have any physical meaning.
long lightEnergy = lightning.lightningEnergy();
Serial.print("Lightning Energy: ");
Serial.println(lightEnergy);
}
}
}
Muchas gracias, he conseguido pegar el codigo como me decías.
Bien, tal como te dije, pon donde dices que quieres que emita el pitido la primer línea de código que te pasé, pon el número de pin que corresponde. Así emite el pitido.
Luego antes de la ultima llave pon
else {
digitalWrite(pin_del_buzzer, LOW);
}
Así cuando lightningInt es LOW (no hay detección) lo apaga.
Saludos
Muchisimas gracias lo probaré entre esta noche y mañana que hay previsión de tormentas. Ya contare que tal, lo he dejado encendido jeje
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.