when i connect the supply to arduino , the port 7 is allways ON ( actived ) and i don't find why ?
can someone help me ?
i sazy to the setup the port 7 is output and low after but stay ON ....
where is the mistake ?
ihave this code very simply :
#include <SoftwareSerial.h>
SoftwareSerial HC06(11, 10); // liaison serie sur les port 11 et 10
String messageRecu;
void setup() {
Serial.begin(9600);
HC06.begin(9600);
pinMode(7, OUTPUT); //declaration du port 7 sortie
digitalWrite(7, LOW);
}
void loop()
{
while (HC06.available())
{
delay(5);
char c = HC06.read();
messageRecu += c;
}
if (messageRecu.length() > 0)
{
Serial.println(messageRecu);
if (messageRecu = "LED:1")
{
digitalWrite(7, HIGH);
}
if (messageRecu = "LED:2")
{
digitalWrite(7, LOW);
messageRecu = "";
}
}
}
the green LED on the relay say that the port 7 is allways ON .
I tested with the same electric , but only basic command ( replaced the void loop ) with blink . work perfectly . connected to the bluetooth and the relay blink ( the green led )
Something you need to watch out for is = sets a variable and == is the operator which compares. You would not normally do something like
if (messageRecu = "LED:1")
because that is setting the string messageRecu to the text "LED:1", and it always is true.
Instead you would do
if (messageRecu == "LED:1")
Also, with the logic you have in your sketch you check to see if the string matches one of the commands and if so you change the digital state of the pin and you clear the command string, but if the string matches the other command, you are not clearing the command string. Not sure if that's what you meant to do. You probably need to account for invalid commands received and clear the command string and wait for something valid, or clear the command string if you have an unexpected number of characters in it for too many seconds.
When I have a problem like this, I step back and simplify and break the project into smaller parts. I suggest use only the UNO without other things connected, and master the part where you read some characters over the USB serial connection from Serial Monitor, store the characters in a string. If the value of the string is set to some expected value, do something with the onboard UNO LED on pin 13, such as turn it on or turn it off.
Once you have that working, add one external device at a time, for example, add the relay board and get it working by sending commands via USB serial. Then finally, add the bluetooth module again and switch the serial input in your sketch from getting characters from USB serial to getting characters from the bluetooth module.
yes the comand " if " was with double = = .it is my mistake copy here ont the forum .
the project work with bluetooth . the buton on the smartphone work perfectly when i push it .
the only problem is at the start , the relay is closed ( alimentation on the port 7 )
on the setup i said port 7 low .
at the power start is the port 7 with with alimentation 5 volt , this is my big problem without connection bluetooth . need this port LOW at the start and i don't find how to do .
If you are talking about the brief period before your first "digitalWrite(7, LOW);" the line seems to be high, it is probably because the pin is floating before the processor starts running instructions. Google "floating pins arduino" to learn more about floating state of pins. You can fix that in hardware by pulling the pin low. Put a resistor between pin 7 and ground, and the output will then be held low when there is no specific command run to make it low. I think anything between 2K and 10K should be good for that.