G'day everyone,
I'm a new guy on the Arduino topic and keen to learn, but I seem to have run into a stop sign with my project.
Overview:
I built a Star Wars inspired Rocking Speeder bike Instructables Link for my son, which has two On/Off Buttons wich shall do different things.
Button 1
Play mp3 file from SD card (blaster sound) using DFplayer and Flash 1 LED while that button is pressed
Button 2
Play mp3 file from same SD card (turbine sound) using DFplayer and make my little dc motor spin my 3D printed turbine.
I tried to search for individual codes that do each trick and somehow merge them into one functional frankensteins monster, but for a beginners project, this seems to be a little over my head.
I hope you can help me out and make that rocking speeder bike a little more awesome.
Here come(s) the code(s) pieces so far
**Flashing LED when Button (not one of those push buttons on a breadboard) is pressed ** (source )
int switch_pin = 4;
int led_pin = 5;
byte leds = 0;
void setup() {
pinMode(switch_pin, INPUT);
pinMode(led_pin, OUTPUT);
}
void loop() {
if(digitalRead(switch_pin) == HIGH){
digitalWrite(led_pin, HIGH);
}
if(digitalRead(switch_pin) == LOW){
digitalWrite(led_pin, LOW);
}
}
edit 2: example circuit deleted
Play mp3 from DFplayer when On/Off switch is turned on German Source
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
int taster=7;
int tasterstatus=0; //Das Wort „tasterstatus“ steht jetzt zunächst für den Wert 0. Später wird unter dieser Variable gespeichert, ob der Taster gedrückt ist oder nicht.
void setup()
{
mySoftwareSerial.begin(9600);
myDFPlayer.volume(30);
pinMode(taster, INPUT);
}
void loop()
{
tasterstatus=digitalRead(taster);
if (tasterstatus == HIGH) {
myDFPlayer.play(1);
}
}
My combination so far:
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
int turbine_switch = 4;
int blaster_switch = 5;
int blaster_led = 6;
int motorin2 = 7;
int motorin1 = 8;
int enA = 9;
void setup()
{
mySoftwareSerial.begin(9600);
myDFPlayer.volume(30);
pinMode(turbine_switch, INPUT);
pinMode(blaster_switch, INPUT);
pinMode(blaster_led, OUTPUT);
pinMode(enA, OUTPUT);
pinMode(motorin1, OUTPUT);
pinMode(motorin2, OUTPUT);
}
void loop()
{
if (digitalRead(blaster_switch) == HIGH) {
myDFPlayer.play(1);
digitalWrite(blaster_led, HIGH);
delay(100);
digitalWrite(blaster_led, LOW);
}
else {
digitalWrite(blaster_led, LOW);
}
if (digitalRead(turbine_switch) == HIGH) {
myDFPlayer.play(2);
digitalWrite(motorin1, HIGH);
digitalWrite(motorin2, LOW);
analogWrite(enA, 200);
}
}
Then comes moving the motor. Do I need a shield for this? I don't get it. I saw its possible without, but a lot of tutorials seem to love these things. Can somebody enlighten me please?
edit1
Alright, I found a tutorial about the L298N here and included the move-my-dc-motor-code. I'm curious about your comments.
cheers