Hello, before you say anything, this is not a project PRIMARILY on a LED. I just need project guidance. How do I get the LED on the Arduino Mega 2560 to stop blinking every time I run this program:
I suspect you mean the LEDs connected to pin 10 and 11. They are hardwired to those pins and you are using the pins for your software serial. You can try to use other pins or use a soldering iron and remove them.
Have a look at the schematic. Which you can download from the following link under Documentation.
Klaus_K:
I suspect you mean the LEDs connected to pin 10 and 11. They are hardwired to those pins and you are using the pins for your software serial.
The pins 10 and 11 the LEDs are wired to are physical pins 10 and 11 on the ATmega16U2. That's different from the Arduino pins 10 and 11 on the ATmega2560 UptownKitten is using for software serial. There are no LEDs connected to those pins. It would be more correct to say the RX and TX LEDs are connected to Arduino pins 0 and 1 because they blink when there is serial communication via those pins.
UptownKitten:
How do I get the LED on the Arduino Mega 2560 to stop blinking every time I run this program:
Which LED? There are four LEDs on the Mega. They have markings next to each on the silkscreen to identify them: ON, L, TX, RX.
I found the problem, the L LED was blinking because it wasn't a constant variable. But, I still can't figure out why the LED isn't turning on after I put my hand in front of the sensor. Any suggestions?
I found the problem, the L LED was blinking because it wasn't a constant variable.
Just a correction, it was more than likely blinking because you did not set the pin to output. If you remove pinMode(ledPin, OUTPUT);, does it blink again?
Yes, the LED blinks without the pinMode(ledPin, OUTPUT);, but now it is blinking again for some reason. even with the pinMode(ledPin, OUTPUT);. I also placed some Serial.println(""); statements and found out that the code will not even go inside the function or I can't see that it is inside the function. Very strange, this was half way working earlier, but not now. Hmm, maybe I bumped into a wire. I don't know. Updated code:
#include <DFPlayerMini_Fast.h>
DFPlayerMini_Fast myMP3;
const int pirPin = 7; // Input for HC-S501
const int ledPin = 13; // LED on Pin 13 of Arduino
const byte delayTime = 20;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial1.begin(9600);
myMP3.volume(30);
pinMode(pirPin, INPUT);
}
void takeAction() {
Serial.println("This is inside a function");
int pirValue = digitalRead(pirPin);
if (pirValue == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Gotcha!");
myMP3.play(2);
}
else {
digitalWrite(ledPin, LOW);
}
}
void loop() {
takeAction();
delay(delayTime);
}
UptownKitten:
I am talking about the L LED. I don't know how to use the code without using the SoftwareSerial library.
Arduino Uno has 1 serial port. Arduino Serial is the software object (code+data where the data is the port variables and the code is for all serial) that runs the first port. Serial.begin(), Serial.read(), etc, all refer to that one port. Arduino Mega has 4 serial ports named Serial, Serial1, Serial2, and Serial3. You use Serial1 through Serial3 the same way you use Serial.
Serial.begin( 115200 ); // initialize the 1st port
Serial1.begin( 115200 ); // initialize the 2nd port ~~~ use software serial when your Mega needs 5 serial ports!
......
Serial1.println( F( "On an Uno, you have to use software serial to print this." ));
and BTW, the F( "text" ) is a macro that makes the compiler keep the text in flash instead of copying it to RAM on startup. It stays in flash and prints from flash and doesn't use up precious RAM.