I don't start serial.begin

Hello there. I have installed the following code arduino but serial.begin i could not start. I would appreciate if you help. sorry for bad english.

Park_sensor.pde (2.02 KB)

Code posted properly. Please read and follow the directions in the “How to use this forum” post.

#include "NewPing.h"
/*#include "SPI.h"      
#include "SD.h"     
#include "TMRpcm.h"*/


#define SONAR_NUM 3     
#define MAX_DISTANCE 300 

NewPing sonar[SONAR_NUM] = {   
  NewPing(4, 5, MAX_DISTANCE), 
  NewPing(6, 7, MAX_DISTANCE),
  NewPing (8, 9, MAX_DISTANCE),
};

/*#define SD_ChipSelectPin 53
TMRpcm audio;*/

int led1=26;
int led2=27;
int led3=28;
int led4=29;
int mesafe=sonar[1].ping_cm();

int led5=43;
int led6=42;
int led7=41;
int led8=40;
int mesafe2=sonar[2].ping_cm();


void setup() {
 /*   audio.speakerPin= 46; 
    audio.volume(4);
    if (!SD.begin(SD_ChipSelectPin)) {
    Serial.println("SD BASARISIZ");
    return;
}*/
  Serial.begin(115200); 
}

void loop() { 
Serial.print("mesafe;"); Serial.println(mesafe);
Serial.print("mesafe2;"); Serial.println(mesafe2);

if(mesafe<5){
digitalWrite(led1,1);
digitalWrite(led2,1);
digitalWrite(led3,1);
digitalWrite(led4,1);
//audio.play("");
}
if(mesafe2<5){
digitalWrite(led5,1);
digitalWrite(led6,1);
digitalWrite(led7,1);
digitalWrite(led8,1);
//audio.play("");
}
else if(5<=mesafe<10){
digitalWrite(led1,1);
digitalWrite(led2,1);
digitalWrite(led3,1);
digitalWrite(led4,0);
//audio.play("");
}
else if(5<=mesafe2<10){
digitalWrite(led5,1);
digitalWrite(led6,1);
digitalWrite(led7,1);
digitalWrite(led8,0);
//audio.play("");
}
else if(10<=mesafe<15){
digitalWrite(led1,1);
digitalWrite(led2,1);
digitalWrite(led3,0);
digitalWrite(led4,0);
//audio.play("");
}
else if(10<=mesafe2<15){
digitalWrite(led5,1);
digitalWrite(led6,1);
digitalWrite(led7,0);
digitalWrite(led8,0);
//audio.play("");
}
else if(15<=mesafe<20){
digitalWrite(led1,1);
digitalWrite(led2,0);
digitalWrite(led3,0);
digitalWrite(led4,0);
//audio.play("");
}
else if(15<=mesafe2<20){
digitalWrite(led5,1);
digitalWrite(led6,0);
digitalWrite(led7,0);
digitalWrite(led8,0);
//audio.play("");
}
else if(mesafe>=20){
digitalWrite(led1,0);
digitalWrite(led2,0);
digitalWrite(led3,0);
digitalWrite(led4,0);
}
else if(mesafe2>=20){
digitalWrite(led5,0);
digitalWrite(led6,0);
digitalWrite(led7,0);
digitalWrite(led8,0);
}
delay(50);
}

if(10<=mesafe2<15)Oops.

You need to call ping_cm for each sensor every time through loop()

but serial.begin i could not start.

How do you know that there was a problem ?

UKHeliBob:
How do you know that there was a problem ?

Because monitor does not write anything

AWOL:

if(10<=mesafe2<15)

Oops.

You need to call ping_cm for each sensor every time through loop()

And the condition in the if statement cannot be written like you’re in maths class, you need something like

if ((10 <= mesafe2) && (mesafe2 < 15)) …

a7

This is sample code(in library)

NewPing3Sensors.pde (1.04 KB)

Please post your code, don't attach it.

Remember to use code tags.

Why a .pde? What is the version of the IDE?

Fatiko5234:
This is sample code(in library)

But there are no if clauses in that code …

What if you run the code you attached ? Do you get any output on the Serial monitor ?

UKHeliBob:
But there are no if clauses in that code …

What if you run the code you attached ? Do you get any output on the Serial monitor ?

serial monitor works in this code but does not work in pak_sensor.pde

AWOL:
Please post your code, don’t attach it.

Remember to use code tags.

Why a .pde? What is the version of the IDE?

Code:(in library)
// ---------------------------------------------------------------------------
// Example NewPing library sketch that pings 3 sensors 20 times a second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define SONAR_NUM 3 // Number of sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.

NewPing sonar[SONAR_NUM] = { // Sensor object array.
NewPing(4, 5, MAX_DISTANCE), // Each sensor’s trigger pin, echo pin, and max distance to ping.
NewPing(6, 7, MAX_DISTANCE),
NewPing(8, 9, MAX_DISTANCE)
};

void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through each sensor and display results.
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print(i);
Serial.print("=");
Serial.print(sonar*.ping_cm());*

  • Serial.print("cm ");*
  • }*
  • Serial.println();*
    }

This is not getting any easier. Your code has been mangled by the forum software interpreting [­i] in your code as an HTML italics command.

Please read this before posting a programming question and use code tags when posting code.

Thanks for helps

void setup() {
 /*   audio.speakerPin= 46; <<———
    audio.volume(4);
    if (!SD.begin(SD_ChipSelectPin)) {
    Serial.println("SD BASARISIZ");  <<———
    return;  <<———
    }*/
  Serial.begin(115200); <<———
}

While on your original code - this is not an encouraging start…
Think through what you write.
If you can’t understand it, the processor certainly can’t.
Probably also good to ask, what the serial monitor speed is set to,