Hi everyone,
first I wanted to say "Hello". I am Darian and pretty new to everything. I hope that I chose the correct forum (General electronics).
What I would like to do is use a simple setup to create a alarm.
30 seconds after the programme has been started an alarm should go off.
Code-wise everything seems fine:
int counter = 0; // Variable to count the seconds
int pin = 12; // My preferred digital PIN
void setup() {
Serial.begin(9600);
pinMode(pin, OUTPUT); // Setting pin 12 as output
}
void loop() {
delay (1000);
counter ++; // every second the counter gets increased
if (counter > 30) {
// after 30 seconds the beeper goes off
Serial.println ("Beep"); // control message
digitalWrite(pin, HIGH); // beep!
delay (4000); // wait 4 seconds
digitalWrite(pin, LOW); // turn beep off
delay (2000); // wait another 2 seconds
}
}
I uploaded the sketch to my Arduino Nano. The sketch arrived savely on the Nano.
The programme started. After 30 seconds the message "Beep" was printed to the Serial Monitor.
Apparently the code seems to work.
I have a 95db alarm module speaker.
(https://www.amazon.de/gp/product/B01MT5V0FM)
Having connected it to a 9V battery it started to make a loud noise. Apparently it is working.
But now I am sort of clueless how to attach the speaker to the Nano.
I connected D12 to one cable of the speaker and one to GND.
I assume that the voltage of the Nano are too weak.
Alternatively I already used the 5V pin - which is probably too weak, too.
Is it possible to simply "add" another battery to my circuit?
D12 connected to speaker connected to 9 Volt battery connected to GND
Or will this fry the Nano??
Can I use one of the digital PINs just to "open" an close an "external" circuit with its own battery supply?
Maybe I am completely on the wrong track.
I hope that I submitted everything you need to know to help me.
And really would like to apologize in advance, because the question is most likely very basic and probably even stupid. But I couldn't find a proper answer so far. So I hope this is the proper place for my question.
Thanks for your help,
best,
Darian