*URGENT* proximity sensor code not working

Hi,
I need urgent help with this code.

I am connecting a proximity sensor that plays sound when activated for one minute. I keep getting an error but am unsure why.

Is anyone able to assist? I have attached my code bellow.

Thank you!

#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>

#include <Event.h>
#include <Timer.h>

#include <Event.h>
#include <Timer.h>
#include "TMRpcm.h"


#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;


 
#define ds_pin A0 // Pin to which the distance sensor is connected
#define ds_pin_1 A1 // Pin to which the distance sensor is connected
#define ds_pin_2 A2 // Pin to which the distance sensor is connected
#define ds_pin_3 A3 // Pin to which the distance sensor is connected

Timer t;
int red_pin = 6;
int green_pin = 7;
int ds_value=0; // Integer to hold the sensor’s reading
int ds_value_1=0; // Integer to hold the sensor’s reading
int ds_value_2=0; // Integer to hold the sensor’s reading
int ds_value_3=0; // Integer to hold the sensor’s reading
int status_red;


  
void setup()
{
  tmrpcm.speakerPin = 9;
  if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
 tmrpcm.setVolume(10);
tmrpcm.play("rain.wav");
  pinMode(red_pin, OUTPUT);
  pinMode(green_pin, OUTPUT);
  t.oscillate(red_pin, 1 * 1000, HIGH); // 10 minutes  
  t.oscillate(green_pin, 1 * 1000, LOW);// 10 minutes  

}
 
 
void loop()
{
  t.update();

  ds_value = analogRead (ds_pin);  // Reads the distance sensor
  ds_value_1 = analogRead (ds_pin_1);  // Reads the distance sensor
  ds_value_2 = analogRead (ds_pin_2);  // Reads the distance sensor
  ds_value_3 = analogRead (ds_pin_3);  // Reads the distance sensor

  status_red=digitalRead(red_pin);if(ds_value<3000 && ds_value_1<300 status_red==0)
  {
    //play light music  
   tmrpcm.play("music.wav");
 
  }
  else if(ds_value_2<300 && ds_value_3<300 status_red==1)
  
  {
    //play thunder
    tmrpcm.play("thunder.wav");
  
  }
  else
  {
  tmrpcm.stopPlayback()
  
  }
  delay (200);                  // Delay of 200ms

}

at the }
else if(ds_value_2<300 && ds_value_3<300 status_red==1) part it states expected ‘)’ before ‘status_red’

Arduino_task2.ino (1.71 KB)

ds_value_3<300 status_red==1

?

When I do that, another error comes up.

at

status_red=digitalRead(red_pin);if(ds_value<3000 && ds_value_1<300 status_red==0)

its the same error that pops up, do I need to get rid of the () as well??

Thank you

You need to fill the space. Try &&

When I do that, another error comes up.

We have NO idea what "that" is you did.

You KNOW how to use && in an if statement. Why do you not use && between ALL the clauses?

That worked, now there’s another error

}
else if ds_value_2<300 && ds_value_3<300 status_red==1

now this one has the same error, and i tried the && that also didn’t work

Sorry, I got the code from a friend because I don’t know how to code

thank you

and PaulS… I DONT KNOW HOW TO CODE THAT’S WHY I AM ASKING…

And now you're missing both ( and ), and &&

I added the () but it comes up as expected ) before status red

Thank you for helping AWOL

If you changed your code, you need to post it again. Are you still missing the && between the last two clauses?

stevenskintzis:
Sorry, I got the code from a friend because I don’t know how to code

I DONT KNOW HOW TO CODE THAT’S WHY I AM ASKING…

And if you’d said that earlier instead of saying " I have attached my code" you might have got some different answers.

If you can post the complete latest version and then say exactly what problems you have with THAT version it will be a lot easier to help.

Steve

Do you believe that writing “URGENT” somehow motivates others to want to help you more? It has the opposite effect on me.

I'm sensing "late assignment"

I think I have got the code working now. Thank you everyone.