How do I insert INT on Arduino SoftwareSerial?

So, I tried to make some projects for school. I sure for you guys seem pretty easy as well. So here goes the code:

#include <SoftwareSerial.h>

int PulseSensorPurplePin = A0;
int Signal;
int Threshold = 550;
int S;
const int PIN_SPEAKER = 2; // speaker on pin2 makes a beep with heartbeat

SoftwareSerial mySerial(10, 11); // RX, TX

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

void loop()
{
Signal = analogRead(PulseSensorPurplePin);
S=(Signal/8);
Serial.print("Your heart Beat is : ");
Serial.println(S);

if ( mySerial.read(101)) = S;
{
tone(PIN_SPEAKER,1047);
}
if ( mySerial.read(35)) = S;
{
tone(PIN_SPEAKER,1047);
}
if ( mySerial.read(0))= S;
{
noTone(PIN_SPEAKER);
}

}

Serial.begin(9600);
mySerial.println(S);

delay(1000);
}

testing2.ino (788 Bytes)

You'll have much more success with Arduino if you take the time to understand the code instead of just making it up as you go along. It might seem like it takes longer at first, but in the end it will save you a huge amount of time and frustration.

Please spend some time studying these reference pages:

You should start by writing simple programs to test out every part of your final project individually:

  • Reading from an analog pin.
  • Printing to Serial.
  • Reading from a software serial port.
  • Playing a tone on a speaker.

Once you have verified you fully understand the code to do each of those things individually and that they are working as expected, it will be very easy to assemble the parts into your final project.

if ( mySerial.read(35)) = S;

Oops at least twice.

The semicolon at the end is a premature end of the if statement.

= is for assignment.
== is for comparisons.
There are exceptions but this is not one of them.

I don't think that Serial.read() should include a number inside the parentheses.

The line should be more like

if ( mySerial.read()) = S;

These errors occur multiple times and are not the only errors in this short program.
I should also mention that code tags are sadly missing.

vaj4088:
The line should be more like

if ( mySerial.read()) = S;

Pot and Kettle :slight_smile: :slight_smile:

It should be

if ( mySerial.read()) == S {

…R

Robin2:
Pot and Kettle :slight_smile: :slight_smile:

It should be

if ( mySerial.read()) == S {

...R

Wouldn't that be

if ( mySerial.read() == S ) {

Robin2:
Pot and Kettle :slight_smile: :slight_smile:

It should be

if ( mySerial.read()) == S {

...R

Whoopsie,

It should be

if (mySerial.read() == 'S') {

arduino_new:
Whoopsie,

It should be

if (mySerial.read() == 'S') {

But it is not the character 'S', it is the variable S

Isn't it wonderful how there are so many ways to get such a simple thing wrong :slight_smile: :slight_smile:

...R