Bali Mynah Nature Sound [Magnetic Switch]
by marcusayay in Circuits > Arduino
153 Views, 0 Favorites, 0 Comments
Bali Mynah Nature Sound [Magnetic Switch]
Connecting the Magnetic Switch
This projects uses a magnetic switch (obtained online) and is connected to the board to [P0] and [GND].
Both of ends of the wire can be connected in either direction.
Connecting the LED
Power can be connected to the breadboard power rails if required.
But for this setup, Power is connected directly to one column of the breadboard with Ground connected to another row of the breadboard.
A 100k resistor is used and connected to the ground side of the breadboard for the LED.
Connect the LED to the breadboard with the Power and Ground setup.
Connecting the MP3 Player
Power can be connected to the breadboard power rails if required.
But for this setup, Power is connected directly to the VCC and Ground is connected directly to the GRD of MP3 Player. TX is connected to [P10] while RX is connect to [P11].
The Arduino Code
The arduino code has been included in the file. Or provided below.
You will also need the Serial MP3 library.
#include "SerialMP3Player.h" #define TX 11 #define RX 10 <b>SerialMP3Player</b> mp3(RX,TX); // the setup function runs once when you press reset or power the board void setup() { pinMode(8, OUTPUT); pinMode(0, OUTPUT); <b>Serial</b>.begin(9600); mp3.begin(9600); // start mp3-communication delay(500); // wait for init mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card delay(500); // wait for init } // the loop function runs over and over again forever void loop() { int status = digitalRead(0); // digitalWrite(8, LOW); if(status==HIGH){ <b>Serial</b>.println("I AM OPEN"); delay(500); digitalWrite(8, HIGH); mp3.play(); // Play "hello.mp3". You must hear "Hello World" delay(200); // wait 3 seconds } else{ mp3.reset(); // Play "hello.mp3". You must hear "Hello World" delay(200); // wait 3 seconds <b>Serial</b>.println("I AM CLOSED"); digitalWrite(8, LOW); } // digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level) // digitalWrite(1, LOW); // turn the LED off by making the voltage LOW }