Variable storing on Arduino uno

Hello,

I basically want the EchoSendRecieveNorth/East/West to read the time it takes till it gets back, convert that to centimeters and store that to Ncm/Ecm/Wcm. I then want to read these values and to make a decision based on these values. Then after that decision has been made I want then to execute the things, and rescan the area. How do I store these value’s? Here is my code:

#include <Servo.h> 

int SnorRechts = 6;
int SnorLinks = 5;
int SnorRechtsStaat = LOW;
int SnorLinksStaat = LOW;
int Ontvanger = 7;
int Echo = 8;
long Eduration, Ecm;
long Nduration, Ncm;
long Wduration, Wcm;
int LED = 13;

Servo Left;
Servo Right;
Servo Top;
void setup() {
  Serial.begin(9600);
  Top.attach(9);
  Left.attach(11);
  Right.attach(12);
  pinMode(SnorRechts, INPUT);
  pinMode(SnorLinks, INPUT);
  pinMode(Echo, OUTPUT);
  pinMode(Ontvanger, INPUT);
  pinMode(LED, OUTPUT);
  Top.write(12);
      }

void loop() {
  
  Eduration = pulseIn(Ontvanger, HIGH);
  Nduration = pulseIn(Ontvanger, HIGH);
  Wduration = pulseIn(Ontvanger, HIGH);
  
  Ecm = Eduration/58.4; 
  Ncm = Nduration/58.4;
  Wcm = Wduration/58.4;
  
  SnorRechtsStaat = digitalRead(SnorRechts);
  SnorLinksStaat = digitalRead(SnorLinks);

  Right.write(202);
  Left.write(18); 
 
   
 /* if (cm <= 20){
   Left.write(198);
   Right.write(22);
   delay(1800);
   Serial.println(cm);
   delay(100);
        }
  if (cm >= 20){

  Right.write(202);
  Left.write(18); 
  delay(50);
  Serial.println(cm);
  delay(100);
  //digitalWrite(LED, LOW); */
  Top.write(12);
  delay(1000);
  EchoSendRecieveEast();
  delay(100);
  
  Top.write(102);
  delay(500);
  EchoSendRecieveNorth();
  delay(100);
  
  Top.write(192);
  delay(500);
  EchoSendRecieveWest();
  delay(100);

  if (Wcm <= 20 && Ncm <= 20){
    delay(50);
    Left.write(18);
    Right.write(102);
    delay(890);
    Right.write(202);
  }
  
  if (Ecm <= 20 && Ncm <= 20){
    delay(50);
    Left.write(118);
    Right.write(202);
    delay(970);
    Left.write(18);
    
  }
  
 
  if(SnorRechtsStaat == HIGH) {
    delay(100);
    Left.write(198);
    Right.write(22);
    delay(2750);
    Rechtsturn(); 
    Linksturn();
  
  
}
 if(SnorLinksStaat == HIGH){
   delay(100);
   Left.write(198);
   Right.write(22);
   delay(2750);
   Linksturn();
   Rechtsturn();
  
 }
}
 

  void Rechtsturn(){
  Left.write(18);
  Right.write(202);
  delay(750);
  Right.write(102);
  //delay(3650);
  //delay(6850);
  delay(890.0);
  //Left.write(108);
  //Right.write(112);
  }
  void Linksturn(){
  Left.write(18);
  Right.write(202);
  delay(750);
  Left.write(118);
  delay(970);
  }
  void achtje(){
  Right.write(202);
  Left.write(103);
  delay(7200);
  Left.write(18);
  delay(3000);
  Right.write(117);
  delay(10000);
  Right.write(202);
  delay(3000); }

  void EchoSendRecieveWest(){
  digitalWrite(Echo, LOW);
  delayMicroseconds(2);
  
  digitalWrite(Echo, HIGH);
  delayMicroseconds(11);
  
  digitalWrite(Echo, LOW); 
[s]  Serial.println(Wcm);[/s]
  delay(15);
    }
    void EchoSendRecieveNorth(){
  digitalWrite(Echo, LOW);
  delayMicroseconds(2);
  
  digitalWrite(Echo, HIGH);
  delayMicroseconds(11);
  
  digitalWrite(Echo, LOW); 
[s]  Serial.println(Ncm);[/s]
  delay(15);
    }
    void EchoSendRecieveEast(){
  digitalWrite(Echo, LOW);
  delayMicroseconds(2);
  
  digitalWrite(Echo, HIGH);
  delayMicroseconds(11);
  
  digitalWrite(Echo, LOW); 
[s]  Serial.println(Ecm);[/s]
  delay(15);
    }

Thanks for help

You've got an awful lot of code there for someone who doesn't know how to assign a simple variable.

What I'm trying to say is that if this is really where you're stuck, then it would do you a lot of good to look at a few basic C++ tutorials and maybe a few of the example sketches that come with the IDE.

What you're asking right now is analogous to... "I am gonna drive this truck, now what is a steering wheel?"

If you want to copy and paste your way through writing code that's fine, just don't expect to be able to modify any of it in any meaningful way.

How do I store these value's?

In variables by using the equals sign =

OK what am I missing here, what are you really asking?

Delta_G: You've got an awful lot of code there for someone who doesn't know how to assign a simple variable.

What I'm trying to say is that if this is really where you're stuck, then it would do you a lot of good to look at a few basic C++ tutorials and maybe a few of the example sketches that come with the IDE.

What you're asking right now is analogous to... "I am gonna drive this truck, now what is a steering wheel?"

If you want to copy and paste your way through writing code that's fine, just don't expect to be able to modify any of it in any meaningful way.

This is a school project, I need to make a car that can drive through a maze. The code your seeing is not complicated, it is just much. I don't want to copy paste code, I only have written this code because I understand it. I cannot find an example sketch that I am looking for, so I see what I have to do, but I do not get what the code means so I am not going to implement it unless I can see what it means.

Grumpy_Mike: In variables by using the equals sign =

OK what am I missing here, what are you really asking?

I want to store the values that it reads (the Pulseln(ontvanger, HIGH);) and then read it a second later to make a decision.

int firstTime = Pulseln(ontvanger, HIGH);
// do stuff
int secondTimeTime = Pulseln(ontvanger, HIGH);

if( firstTime != secondTime) {
 // do stuff
}

Lets just explain the whole thing

I have a servo car that I want to do the following
(also has a servo with hc sr04 on top)

start at 12* Measure distance to east (right of the car) store to: Ecm
Turn 90* so its at 102 degrees and then measure the distance to north (in front of the car) and store to: Ncm
Turn 90* so its at 192 degrees and then measure the distance to west (left of the car) and store to: Wcm

If there is an object within xx cm then I want it to take an action
If Ecm is smaller then 30(cm) and if Ncm is smaller then 30(cm) then I want it to turn right after 0.5 seconds for example.

The problem is the storing to, I tried modifying it a bit:

#include <Servo.h> 
#include <EEPROM.h>

int SnorRechts = 6;
int SnorLinks = 5;
int SnorRechtsStaat = LOW;
int SnorLinksStaat = LOW;
int Ontvanger = 7;
int Echo = 8;
long duration, cm;
int LED = 13;
int Eastcm ;
int Northcm ;
int Westcm ;
int Ecm ;
int Ncm ;
int Wcm ;

Servo Left;
Servo Right;
Servo Top;
void setup() {
 Serial.begin(9600);
 Top.attach(9);
 Left.attach(11);
 Right.attach(12);
 pinMode(SnorRechts, INPUT);
 pinMode(SnorLinks, INPUT);
 pinMode(Echo, OUTPUT);
 pinMode(Ontvanger, INPUT);
 pinMode(LED, OUTPUT);
 Top.write(12);
     }

void loop() {
 
 duration = pulseIn(Ontvanger, HIGH);
 cm = duration/58.4; 
   
SnorRechtsStaat = digitalRead(SnorRechts);
 SnorLinksStaat = digitalRead(SnorLinks);

 Right.write(202);
 Left.write(18); 

 Wcm = Serial.println(EEPROM.read(Westcm));
 Ncm = Serial.println(EEPROM.read(Northcm));
 Ecm = Serial.println(EEPROM.read(Eastcm));
/* if (cm <= 20){
  Left.write(198);
  Right.write(22);
  delay(1800);
  Serial.println(cm);
  delay(100);
       }
 if (cm >= 20){

 Right.write(202);
 Left.write(18); 
 delay(50);
 Serial.println(cm);
 delay(100);
 //digitalWrite(LED, LOW); */
 Top.write(12);
 delay(1000);
 EchoSendRecieve();
 delay(50);
 EEPROM.write(Eastcm,cm);
 delay(100);
 
 Top.write(102);
 delay(500);
 EchoSendRecieve();
 delay(50);
 EEPROM.write(Northcm, cm);
 delay(100);
 
 Top.write(192);
 delay(500);
 EchoSendRecieve();
 delay(50);
 EEPROM.write(Westcm, cm);
 delay(100);

 if (Wcm <= 20 && Ncm <= 20){
   delay(50);
   Left.write(18);
   Right.write(102);
   delay(890);
   Right.write(202);
 }
 
 if (Ecm <= 20 && Ncm <= 20){
   delay(50);
   Left.write(118);
   Right.write(202);
   delay(970);
   Left.write(18);
   
 }
 

 if(SnorRechtsStaat == HIGH) {
   delay(100);
   Left.write(198);
   Right.write(22);
   delay(2750);
   Rechtsturn(); 
   Linksturn();
 
 
}
if(SnorLinksStaat == HIGH){
  delay(100);
  Left.write(198);
  Right.write(22);
  delay(2750);
  Linksturn();
  Rechtsturn();
 
}
}


 void Rechtsturn(){
 Left.write(18);
 Right.write(202);
 delay(750);
 Right.write(102);
 //delay(3650);
 //delay(6850);
 delay(890.0);
 //Left.write(108);
 //Right.write(112);
 }
 void Linksturn(){
 Left.write(18);
 Right.write(202);
 delay(750);
 Left.write(118);
 delay(970);
 }
 void achtje(){
 Right.write(202);
 Left.write(103);
 delay(7200);
 Left.write(18);
 delay(3000);
 Right.write(117);
 delay(10000);
 Right.write(202);
 delay(3000); }

 void EchoSendRecieve(){
 digitalWrite(Echo, LOW);
 delayMicroseconds(2);
 
 digitalWrite(Echo, HIGH);
 delayMicroseconds(11);
 
 digitalWrite(Echo, LOW); 
 Serial.println(cm);
 delay(15);
   }
Wcm = Serial.println(EEPROM.read(Westcm));
 Ncm = Serial.println(EEPROM.read(Northcm));
 Ecm = Serial.println(EEPROM.read(Eastcm));

That is not going to do anything useful because Serial.println does not return the value it just printed.

EEPROM.write(Eastcm,cm);

Only use the EEPROM if you want to maintain the values when you power the board down. As you have it you will soon burn the EEPROM out, it is limited to 100,000 writes.
I still don’t understand why the concept of storing your values in a variable is giving you problems.