Hi every body:
I asked questions on this sketch before, and got some great help. I have continued developing my project, and now have a new problem. This project is basically a skeleton that (when an IR Remote is pressed) turns his head, says an MP3 file, and turns his head back. The attached sketch works almost all of the time. Once in a while, the MP3 player just plays a second of the MP3, but if I reload the sketch, it works fine again. The phase I am working on now is to have the skeleton’s jaw move in sync to the MP3. I am using some of Mike North’s Jawduino method. He uses a KA2284 LED sound meter module, with three of the LEDs connected to three analog pins in the Arduino. This is a relatively common method to do this.
My current sketch does not yet address the KA2284 LED sound meter module. However, when I plug just the ground wire of the KA2284 LED sound meter module into the common ground of the rest of the project, the MP3 then only plays a second of the message. If I disconnect the KA2284 LED sound meter module ground wire, and re-load the sketch, it works fine again.
So it looks like my sketch is OK, but something happens when I touch the KA2284 LED sound meter module ground wire to the project’s common ground. Should I power the KA2284 LED sound meter module with its own isolated power supply? Could the KA2284 LED sound meter module be defective? Do I have an issue with interrupts in the libraires? This is outside my expertise.
I am using a Arduino Uno R3, and a DFRobot DFPlayer Mini. I will attach the sketch in question, which seems to work, but does not yet address the KA2284 LED sound meter module. I wired in the module and started writing the sketch that will use it to move the skeleton’s jaw when it all went downhill.
#include <SoftwareSerial.h> //Allows us to assign different pins for serial use
#include <DFRobotDFPlayerMini.h>
#include <IRremote.h>
#include <Servo.h>
//This sketch is an upgraded sketch that adds the IR Remote triggering the MP3 player
//It tries some ideas form DeBaros video, substituting the IR remote for the PIR
//THIS WORKS - EACH BUTTON PRESS PLAYS TRACK FOR THAT BUTTON
int rxPin = 3;
int txPin = 2; //Sets up the send/receive from the Mp3 player
int track = 0001; //This is the track number on the micro SD card
SoftwareSerial fxSerial(rxPin, txPin); //calls the Mp3 player fxSerial
DFRobotDFPlayerMini fxPlayer;
int remoteStatus= 0; //This sets the trigger to start the talking as zero (no talking, just shoveling).
int remoteState= 0; //This is the label of the current remote status (on or off)
int IRPin = 11; //for the ir remote
Servo HeadTurnServo;
int servoHeadPin = 12; //This is the servo that rotates the head. Does this need to be a squiggly pin? NO it does not
void setup() {
// put your setup code here, to run once:
HeadTurnServo.attach(servoHeadPin);
HeadTurnServo.write (90);//Zeroes the head to straight ahead.
pinMode (IRPin, INPUT);//sets the pin from the IR Remote to input
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT); // Tells Arduino what the Mp3 pins are doing
fxSerial.begin(9600); //Sets up the serial function for the Mp3 player
fxPlayer.begin(fxSerial); //this tells Arduino that the serial path for the Mp3 player is fxSerial (the name of the MP3 player)
Serial.begin(9600); // Do I need this?
fxPlayer.volume(20);// Volume can be 10 to 30). Set this to 20 to use less power
Serial.println("Enabling IRin"); //for the IR remote
IrReceiver.begin(IRPin, ENABLE_LED_FEEDBACK);//for the IR remote
Serial.println("Enabled IRin");//for the IR remote
delay (1000); //Gives things a chance to stabilize
}
void loop() {
// put your main code here, to run repeatedly:
//remoteStatus = digitalRead(IRPin);// Checks what the current status of the IR output is
//if (remoteStatus == HIGH) { //If high, it means a button was pressed at some time.
//if (remoteState == LOW) { //If remoteStatus is now High, and remoteState was Low, it means a new button press occured.
//This prevents rapid repeats.
//Serial.println ("A button was pressed");
// remoteState = HIGH;
//}
//}
//else {
//if (remoteState == HIGH) {
// Serial.println ("Button press has ended");
// remoteState = LOW; //This flps the remoteState back to Low for the next button press
// Serial.println (remoteState);
// }
//}
if (IrReceiver.decode()){ //TRUE if an IR button was pressed, FALSE if not //for the IR remote
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);/*prints the decoded raw IR data to the serial monitor in hexadecimal format. The decodedRawData field holds the raw, unprocessed IR signal. */
if (IrReceiver.decodedIRData.decodedRawData == 0xBA45FF00){//add the next rows to try other buttons
Serial.println ("Button 1 was pressed");
HeadTurnServo.write(170); //turns the head to the right
fxPlayer.play(1);// plays message 1 because button 1 was pressed
delay(10000); //gives the head a short pause before turning back.
HeadTurnServo.write(90); //turns the head back to straight ahead
}//end of IF statement
//
if (IrReceiver.decode()){ //TRUE if an IR button was pressed, FALSE if not //for the IR remote
if (IrReceiver.decodedIRData.decodedRawData == 0xB946FF00){//add the next rows to try other buttons
Serial.println ("Button 2 was pressed");
//fxplayer.play(2)// plays message 2 because button 2 was pressed
}//end of IF statement
}
//fxPlayer.play(2);// Plays track 2
//delay(10000); //this plays track for 10 seconds. The speech must be less than 10 seconds long -Does this need to be in the loop?
IrReceiver.resume();/*prepares the IR receiver to start listening for the next IR signal. It essentially tells the IR receiver to reset its internal state and prepare for a new incoming signal.*/
}
} //End of void loop
I don't think the following sketch is of value to this post, but this is a draft of the portion of the sketch to use the KA2284 LED sound meter module:
// to make a servo move in sync with audio.
//This is a bare bones test of the HiLetgo 5pcs KA2284 Level Indicator Module
#include <DFRobotDFPlayerMini.h>
#include <Servo.h>
#include <SoftwareSerial.h> //For the MP# player
#include <IRremote.h>
int rxPin = 3; //Sets up the send/receive from the Mp3 player
int txPin = 2; //Sets up the send/receive from the Mp3 player
int track = 0001; //This is the track number on the micro SD card
SoftwareSerial fxSerial(rxPin, txPin); //calls the Mp3 player fxSerial
DFRobotDFPlayerMini fxPlayer;
Servo JawServo;
int servoJawPin = 10; //This is the servo that moves the jaw
int IRPin = 11; //for the ir remote
int val; //This will be the mapped value for the Jawservo to move
int audio_value; //This will be the value from the KA2284 Level Indicator Module
int MP3BusyPin;
void setup()
{
JawServo.attach(servoJawPin);
JawServo.write (15);//Guessing that this is the correct degrees to close the jaw
pinMode (IRPin, INPUT);//sets the pin from the IR Remote to input
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT); // Tells Arduino what the Mp3 pins are doing
fxSerial.begin(9600); //Sets up the serial function for the Mp3 player
fxPlayer.begin(fxSerial); //this tells Arduino that the serial path for the Mp3 player is fxSerial (the name of the MP3 player)
Serial.begin(9600); // Do I need this?
fxPlayer.volume(20);// Volume can be 10 to 30). Set this to 20 to use less power
Serial.println("Enabling IRin"); //for the IR remote
IrReceiver.begin(IRPin, ENABLE_LED_FEEDBACK);//for the IR remote
Serial.println("Enabled IRin");//for the IR remote
delay (1000); //Gives things a chance to stabilize
}
void loop()
{
if (IrReceiver.decode()){ //TRUE if an IR button was pressed, FALSE if not //for the IR remote
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);/*prints the decoded raw IR data to the serial monitor in hexadecimal format. The decodedRawData field holds the raw, unprocessed IR signal. */
if (IrReceiver.decodedIRData.decodedRawData == 0xBA45FF00){//add the next rows to try other buttons
Serial.println ("Button 1 was pressed");
//Add head trun here if this works
audio_value = 0;
fxPlayer.play(1);// plays message 1 because button 1 was pressed
//delay(10000); //gives the head a short pause before turning back.
if (MP3BusyPin = HIGH) { //this will be HIGH as long as the MP3 is playing
Serial.println(MP3BusyPin);
//While (fxPlayer.isPlaying());
if(analogRead(A0) < 341) audio_value += 60;
if(analogRead(A1) < 341) audio_value += 60;
if(analogRead(A2) < 341) audio_value += 60;
//val = map(audio_value, 72, 92, 0, 180); // scale it to use it with the servo (value between 0 and 160)
JawServo.write(audio_value); // sets the servo position according to the scaled value
Serial.println(audio_value);
//JawServo.write (audio_value);
} //this closes the busy pin IF loop
//HeadTurnServo.write(90); //turns the head back to straight ahead
}//end of IF statement
}
}
Thanks for your help, I know I sent a lot here, but did not know what you folks would need to help me.
Here's the wiring: