how use pin rx tx to on off ( high low ) an relay or led

Hellow

how use pin 0 and pin 1 ( rx tx ) to be pin 0 and 1 to power on an relay or led ?

I want transforme it pin rx tx in pin digital 1 and 2.

I want put an button in rx and relay in tx.

do you can send an basic code to test here ?

not have other board, not have other pins available.

tx rx arduino with relay e button - pin 0 pin 1 digital.png

How would you then upload a sketch?

Hello there!

You can indeed use the Rx and Tx pins as digital pins. Rx is defaulted as pin 0 and Tx as pin 1. You can indeed change the pins to default as 1 and 2 by modifying the "pins_arduino" header file for your specific board, but you may run into unexpected problems trying to access other pins correctly.

In addition, you may have a hard time uploading code when circuitry is connected to Rx and Tx. Make sure to disconnect anything before uploading.

Without modifying any files yet, all you would have to do is use the standard digitalRead() or digitalWrite() functions on pins 0 or 1, making sure to assign them as inputs or outputs properly.

YES, work good.

i used it code, and work good.

void setup()
{
pinMode(A4, INPUT);
pinMode(A5, OUTPUT);
pinMode(0, INPUT);
pinMode(A0, INPUT);
pinMode(7, OUTPUT);
pinMode(4, INPUT);
}

void loop()
{

if (digitalRead(A4)) {
digitalWrite(A5, HIGH);
} else {
digitalWrite(A5, LOW);

}
if (digitalRead(0)) {
digitalWrite(A5, HIGH);

} else {
digitalWrite(A5, LOW);

}
if (digitalRead(A0)) {
digitalWrite(7, HIGH);

} else {
digitalWrite(7, LOW);

}
if (digitalRead(4)) {
digitalWrite(7, HIGH);

} else {
digitalWrite(7, LOW);

}}