Hal 9000 project

Hello.
I am struggling.
Can some kind person please design the circuit required for me to run a DY-SV5W Voice Playback module?
My complication is I desire to run a 12v LED while the PCB is playing audio.
The DY-SV5W has a 3.3v busy circuit but I am at a loss on what to do since I've been told a simple relay alone won't work.
This project is a gift for a retiring work colleague that needs to be completed by the end of June.
So I need to use components I can get shipped to regional QLD in under 2 weeks or products stocked by Jaycar.
The 12v LED is part of a big red button (https://core-electronics.com.au/massive-arcade-button-with-led-100mm-red.html).
I already have the button delivered but am still waiting for the delivery of the PCB.
As you can tell, I am well over my head and would truly appreciate a solution.
Thank you.

This has nothing to do with Arduino, I would use the 3.3V busy to activate a MOSFET for the 12V LED.

I doubt you will find anyone to design such a circuit for free, post in the #community:gigs-and-collaborations section with a budget.

Original Hal 9000 had light on all the time, you can hook it up to 12v supply and use the same supply to power Arduino

Hi.
Could anyone explain why this coding causes the same audio sample to be played first everytime?
There are 21 audio files loaded on with naming from 00001.mp3 ~ 00021.mp3. All saved in the SD card root directory.

#include <Arduino.h>
#include "DYPlayerArduino.h"

DY::Player player;

#define TRIGGER_COUNT 1
int triggerPins[TRIGGER_COUNT] = {12};
unsigned long lastTrigger = 0; // This variable keeps track of which tune is playing
int randomNumber=0;
const int SONGLENGTH=100;
int analogPin = A3; // analog pin 3
int val = 0;  // variable to store the A3 value read

void setup() {
  Serial.begin(9600);
  for (int i=0; i<TRIGGER_COUNT; i++)
  {
    pinMode(triggerPins[i], INPUT_PULLUP); // D12 moment button
  }
  pinMode(13, OUTPUT); // Builtin LED 5v out
  pinMode(8, OUTPUT); // MOSFET/LED 5v out
  player.begin();
  player.setVolume(27); // 90% Volume
  delay(1000);
  digitalWrite(13, LOW); // Builtin LED off
  }

void loop()
{
  for (int i=0; i<TRIGGER_COUNT; i++)
  {
    if ((digitalRead(triggerPins[i]) == LOW) && ((millis()-lastTrigger)>SONGLENGTH))    {
      lastTrigger = millis(); // Update lastTrigger variable to current trigger
       randomNumber=random(21);
      player.playSpecified((i*21)+randomNumber);
    }
  }
  val = analogRead(analogPin);
  if (val <400) { //player playing
    digitalWrite(8, HIGH);} // MOSFET/LED on
  else digitalWrite(8, LOW);{ // MOSFET/LED off
  }
}

Hi,
I'm not familiar with the audio module but I assume this line selects the mp3 file?

player.playSpecified((i*21)+randomNumber);

What values are you expecting to send.
Why are you doing (i*21) ?

Why not just the random number, it will be between 0 and 21?

Is the button connected to analog Pin A3.
If it is a switch, why not declare A3 as a digital pin, rather than look for an analog value.

Can you please post a circuit diagram.
Please include the power supply?

Thanks.. Tom... :smiley: :+1: :australia:

Hi,
Did you try the random play code in the DV library examples?

Tom... :smiley: :+1: :coffee: :australia:

Hi Tom.
To be honest, no I haven't tried the library examples.
I cannot see an example in the default options and am not sure which library to load.

This is my first attempt at Arduino so I have no idea why the (i21) command is there.
I copied then modified the code from another. Originally it was (i
10).
The original coder had 10 buttons to trigger the audio and I think it may have been related to that function.

The module is a DY-SV5W and the random audio play coding does work except for the fact that the same audio sample plays first everytime you restart the module.

The button is connected to digital 12.
I am working on a circuit diagram.

Thanks.
Dan :australia:

Hi,
Get this example from the Examples..


This is the example.

#include <Arduino.h>
#include "DYPlayerArduino.h"

// Initialise the player, it defaults to using Serial.
DY::Player player;

// Alternatively initialise on another serial port.
// DY::Player player(&Serial2);

void setup() {
  player.begin();
  player.setVolume(15); // 50% Volume
  player.setCycleMode(DY::PlayMode::Random); // Play all randomly and repeat.
  player.play();
}

void loop() {
  /* Nothing to do.. */
  delay(5000);
}

This should be a good beginning, look at the other examples.

Tom.... :smiley: :+1: :coffee: :australia:

Hi.
Ohh, yer thanks. I did look at the DYPlayer examples.
But that function doesn't suit the project as the DYplayer.random plays all audio files repeatedly.

I need a random play of a single track per button press.

FYI, I did try removing the (i*21) function but it didn't resolve the issue.

:+1: :australia:

Hi,
Try this code.
Connect your switch between gnd and A3.

#include <Arduino.h>
#include "DYPlayerArduino.h"
int bigredbuttonPin = A3; // analog pin 3
bool bigredbuttonState = true;
int randomNumber;
int LEDPin = 8;
// Initialise the player, it defaults to using Serial.
DY::Player player;

// Alternatively initialise on another serial port.
// DY::Player player(&Serial2);

void setup()
{
  pinMode(bigredbuttonPin, INPUT_PULLUP);
  pinMode(LEDPin, OUTPUT);
  player.begin();
  player.setVolume(15); // 50% Volume
}

void loop()
{
  bigredbuttonState = digitalRead(bigredbuttonPin);
  if (bigredbuttonState == false)
  {
    randomNumber = random(21);
    player.playSpecified(randomNumber);
    digitalWrite(LEDPin, HIGH);
  }
  else
  {
    digitalWrite(LEDPin, LOW);
  }
}

It can also be modified not to consecutively repeat a track.
This is compiled, but untried code.

Tom... :smiley: :+1: :coffee: :australia:

Hi,
What is A3 connected to?
I have edited my code to use pin 12 for button.

#include <Arduino.h>
#include "DYPlayerArduino.h"
int bigredbuttonPin = 12; // analog pin 3
bool bigredbuttonState = true;
int randomNumber;
int LEDPin = 8;
// Initialise the player, it defaults to using Serial.
DY::Player player;

// Alternatively initialise on another serial port.
// DY::Player player(&Serial2);

void setup()
{
  pinMode(bigredbuttonPin, INPUT_PULLUP);
  pinMode(LEDPin, OUTPUT);
  player.begin();
  player.setVolume(15); // 50% Volume
}

void loop()
{
  bigredbuttonState = digitalRead(bigredbuttonPin);
  if (bigredbuttonState == false)
  {
    randomNumber = random(21);
    player.playSpecified(randomNumber);
    digitalWrite(LEDPin, HIGH);
  }
  else
  {
    digitalWrite(LEDPin, LOW);
  }
}

Tom... :smiley: :+1: :coffee: :australia:

random numbers are not random, in computers. random numbers are chosen from a list of pseudorandom numbers. if you use randomNumber, you start at the start of the pseodorandom number list, and you get the same numbers in the same series.

if you want randomer randomness, you have to use randomSeed to randomly select from a later number in the list. you can use randomSeed in Setup, or in the function that plays the tune.

Thanks for the guidance mate.

A3 is connected to the busy signal circuit from the audio module.
I am using the busy circuit to close a MOSFET to light a LED.

Dan :+1: :australia:

Cheers Geek_Emeritus :partying_face:

Seems that has fixed my issue.

#include <Arduino.h>
#include "DYPlayerArduino.h"

DY::Player player;

#define TRIGGER_COUNT 1
int triggerPins[TRIGGER_COUNT] = {12}; // Button pin
unsigned long lastTrigger = 0; // keep track of how long since last play
int randomNumber=0; // Variable to store a random number
const long SONGLENGTH = 1000; // Continuous button pressing limiter
int analogPin = A3; // Busy circuit from DY-SV5W
int val = 0;  // variable to store the A3 value read (0v or 3.3v)
int lastPlayed = 20; // Record which audio is lastplayed

void setup() {
  Serial.begin(9600);
  for (int i=0; i<TRIGGER_COUNT; i++)
  {
    pinMode(triggerPins[i], INPUT_PULLUP); // D12 moment button
  }
  pinMode(13, OUTPUT); // Builtin LED -> 5v out
  pinMode(8, OUTPUT); // MOSFET/LED -> 5v out
  player.begin(); // DY-SV5W on
  player.setVolume(27); // 90% Volume
  digitalWrite(13, LOW); // Builtin LED off
  delay(1000);
  randomSeed(analogRead(1)); // First song number-true random
  player.playSpecified(20); // Plays on device startup
  }

void loop()
{
  for (int i=0; i<TRIGGER_COUNT; i++)
  {
  unsigned long currentMillis = millis();
    if ((digitalRead(triggerPins[i]) == LOW) && ((currentMillis - lastTrigger > SONGLENGTH)))    { // Button pressed - don't play if under time limit
      lastTrigger = millis(); // Update lastTrigger variable to current trigger
        long randomNumber=random(1,21); // Choose a random song between 1-21
        if (randomNumber == lastPlayed) { // check if current track is the same as the last played
          // digitalWrite(13, HIGH);
          randomNumber++;
          player.playSpecified(randomNumber); // play random file
          }
        else {player.playSpecified(randomNumber); // play random file
        }
    randomNumber=lastPlayed; //record last played track 
    }
  }
  val = analogRead(analogPin); // A3 pin coding shortcut
  if (val <400) { // 0V in busy circuit - identification that player is playing
    digitalWrite(8, HIGH);} // MOSFET/LED on
  else digitalWrite(8, LOW);{ // player on standby - MOSFET/LED off
  }
}

Thank Guys :+1: