Serial read/ write. Easy fix I hope

Hello!
using a nano and two rfm32bp modules. simply want to the led on pin 13 to come on when the number 44 is received. here is my non working code to the receive :

int led =13;
 
 

void setup() 
{
 Serial.begin(9600);
}

void loop() 
{  
 int Serial.read = (datain());
   if (datain) = 44;
 digitalwrite(led, HIGH);
  if(datain) = 33;
 digitalwrite(led, HIGH);

Thank you very much.

Spend some time reading this:
https://www.arduino.cc/reference/en/language/functions/communication/serial/read/

It looks like you tried to make up your own syntax for those if statements. Please go look at a couple of the example codes that come with your IDE and see if you can't see how one is supposed to look.

You should probably also look at one of the Serial examples and see if you can't fix this line as well.

int Serial.read = (datain());

That's not even close to close. Go have a look at how it is done in the examples.

How is this number being entered? You are typing '4' and '4' on the keyboard? Do you want it to reject 444 as the wrong number? Then you need to tell it to actually look for '4' '4' and '\n' (the newline or 'enter' character.)

Remember Serial is slow. The Arduino can do millions of things between two serial characters arriving. So it's like you saw a '4' in your email last week and then this week the same person emailed you another '4'. Think about how the Arduino might remember that it saw the '4' last week and now it has another '4' it needs to wait for the '\n'.

Your understanding of Serial.read() is backwards. Open up a few of the examples that came with your Arduino and see how they work. Also use the online reference.

can someone give an example of this please.

Or is it a comma ',', you know just a 44.

jgreene33:
can someone give an example of this please.

Open the IDE and go to the examples. You already have plenty of them. Or click "RESOURCES" at the top of this page. You don't need this spoon fed to you. You can do it. It's only going to get tougher from here cupcake.

jgreene33:
can someone give an example of this please.

I have trouble believing you received my reply, read the reference page I linked to, tested the example code there, and tried to apply that to your code in 3 minutes.

Once you get done with that spend some time with this page:
https://www.arduino.cc/reference/en/language/structure/control-structure/if/

Pert yes good link but im still doin something wrong

int led =13;
int datain = 0;
 
 

void setup() 
{
 Serial.begin(9600);
}

void loop() 
{  
   if (Serial.available() > 0)             
   datain = Serial.read();
   if (datain) = 44;
 digitalwrite(led, HIGH);
  if(datain) = 33;
 digitalwrite(led, HIGH);  
}
   if (datain) = 44;

We're not going to do your homework for you. This is wrong. You have the brackets in the wrong place. You're also using the assignment operator (=) where you probably should be using the equality test (==).

Also, if() statements don't end with a semicolon. That terminates the statement there. Use the braces {} to make the meaning more obvious, even if there's only one line in the {} block.

pert:
Once you get done with that spend some time with this page:
https://www.arduino.cc/reference/en/language/structure/control-structure/if/

After that:
https://www.arduino.cc/reference/en/language/structure/arithmetic-operators/assignment/
and
https://www.arduino.cc/reference/en/language/structure/comparison-operators/equalto/

Are you seeing a pattern here? All the information you could hope for is right here. You just need to use it:
http://www.arduino.cc/reference/en

i need an example please.

int datain = 0;   

void setup() {
        Serial.begin(9600);    
}

void loop() {

        
        if (Serial.available() > 0) 
        {               
                datain = Serial.read();               
                Serial.print("I received: ");
                Serial.println(datain, DEC);
                if(datain) == 44
                digitalWrite(led, HIGH);
                delay(1000);
        }
}

closer???

Remove the delay(1000). Otherwise, it is looking better.

Also, try the CTRL-T autoformat on the IDE. It will show you how to lay out your code better.

thank you! i keep erroring on this line though:

if (datain) <= 44 {

expected primary-expression before ‘<=’ token

The conditional expression should be inside the brackets ()

jgreene33:
i need an example please.

4.5 minutes is nowhere near enough time to have spent with those pages I linked to. You've been at this for almost a year now. It's time for you to start making more of an effort. Us spoonfeeding you answers here on the forum is only holding you back. You should have progressed far beyond this by now. Put in some hours. No, put in some days. Then if you're still stuck on specific questions that you can't find an answer to after exhaustive research come back here.

like pulling teeth every time but I got it! Thanks…

int datain = 0;
int led = 2;

void setup() {
  Serial.begin(9600);
}

void loop() {


  if (Serial.available() > 0)
  {
    datain = Serial.read();
    Serial.print("I received: ");
    Serial.println(datain, DEC);
  }
  if (datain <= 44) {
    digitalWrite(led, HIGH);
  }
}

This link may help - Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R