Activ sensor ! Or not !

How to activate a sensor with serial monitor ? i have try and i can't make this :frowning: i will show you the code . Please HELP :frowning: . Thank you !

byte senzor = 7;
int senzor_activ;

void setup(){ 


  pinMode( senzor, OUTPUT );
  Serial.begin(9600);
  
  
  senzor_activ =1;
  Serial.println("Senzor Activ/inactiv - a/d ");
}

void loop()
{
if( Serial.available() ){

    switch(Serial.read()) {
      case 'q': 
      Serial.println("Senzor Activ/inactiv - a/d ");
      
senzor_activ = 1;
 

    
    case 'a' : 
      senzor_activ = 1;
      Serial.println("The sensor is ON"); 
      break;
    
    case 'd' : 
      senzor_activ = 0;
      Serial.println("The sensor is OFF"); 
      break;

    }


{
  if ( analogRead( A2 ) <  700)
{
  digitalWrite( senzor, HIGH );
Serial.print("THE SENSOR IS ACTIV !!! ");
Serial.println();
}
else
  {
    digitalWrite( senzor,LOW);
  }
}

}
}

And the serial monitor shows . . . what?

Show if activ or inactiv and i want to activ the sensor is i press "a " and i turn off if i press " d "

Because i have and this

if ( analogRead( A2 ) <  700)
{
  digitalWrite( senzor, HIGH );
Serial.print("THE SENSOR IS ACTIV !!! ");
Serial.println();
}
else
  {
    digitalWrite( senzor,LOW);
  }

No, I'm asking what you observe when you run your sketch and how that differs from what you expect.

Haven't we been here before?
You can not activate sensors, you can only read them or not read them.

AWOL:
No, I'm asking what you observe when you run your sketch and how that differs from what you expect.

yes , is show in the serial monitor , but i want to activ , and inactiv sensor when I give the command "a" or "d" . Like if i have a robot and i pres " w " to move forward . But i want to activ and dezactiv a sensor . I know is possible but i can't do :frowning: ...

Grumpy_Mike:
Haven't we been here before?
You can not activate sensors, you can only read them or not read them.

Is possible to activ and dezactiv a sensor :slight_smile: . And no ... we haven't was here before for this problem

Is possible to activ and dezactiv a sensor

So what is the sensor then, or do we have to guess that?

yes , is show in the serial monitor

That isn't any kind of answer to the question I asked.

Cut the curt, cryptic responses if you want help.

Grumpy_Mike:

Is possible to activ and dezactiv a sensor

So what is the sensor then, or do we have to guess that?

is a analogic sensor ; a distance sensor , and normaly if is activ he turn ON a LED . If is not activ led Is OFF .
I have this code

 if ( analogRead( A2 ) <  700)
{
  digitalWrite( LED, HIGH );
Serial.print("THE SENSOR IS ACTIV !!! ");
Serial.println();
}
else
  {
    digitalWrite( LED,LOW);
  }

And i want to deaztivate the sensor " A2 " . Like is not there . If i case " a" is active and wait somebody to close them , to start the LED . And if i case " d " i want to not react sensor is close somebody .

AWOL:
No, I'm asking what you observe when you run your sketch and how that differs from what you expect.

appears exactly what I expect, he just do not activates and deactivates the sensor , when i case " a " and " d " only appears on the monitor

Post code.
Post schematic.
Post links to sensor.

Start helping us to help you.

AWOL:
Post code.
Post schematic.
Post links to sensor.

Start helping us to help you.

My code is :

byte LED = 7;

int senzor_activ;

void setup(){

pinMode( LED, OUTPUT );
  Serial.begin(9600);
 
 
  senzor_activ =1;
  Serial.println("Senzor Activ/inactiv - a/d ");
}

void loop()
{
if( Serial.available() ){

switch(Serial.read()) {
      case 'q':
      Serial.println("Senzor Activ/inactiv - a/d ");
     
senzor_activ = 1;

case 'a' :
      senzor_activ = 1;
      Serial.println("The sensor is ON");
      break;
   
    case 'd' :
      senzor_activ = 0;
      Serial.println("The sensor is OFF");
      break;

}

{
  if ( analogRead( A2 ) <  700)
{
  digitalWrite( LED, HIGH );
Serial.print("THE SENSOR IS ACTIV !!! ");
Serial.println();
}
else
  {
    digitalWrite( LED,LOW);
  }
}

}
}




Link sensor : http://www.pololu.com/product/1132 

And i don't know what scheme to do .... block diagram?

Your code will only ever activate the sensor if what is read on A2 is less than 700.
How are you going to get a reading from the sensor to give you that reading if it is never active?

byte senzor = 7;
int senzor_activ;

void setup(){ 


  pinMode( senzor, OUTPUT );
  Serial.begin(9600); 
  senzor_activ =1;
  digitalWrite( senzor, senzor_activ );
  Serial.println("Senzor Activ/inactiv - a/d ");
}

void loop()
{
if( Serial.available() ){

    switch(Serial.read()) {
      case 'q': 
      Serial.println("Senzor Activ/inactiv - a/d ");
      senzor_activ = 1;
      break;
   
    case 'a' : 
      senzor_activ = 1;
      Serial.println("The sensor is ON"); 
      break;
    
    case 'd' : 
      senzor_activ = 0;
      Serial.println("The sensor is OFF"); 
      break;
    }
    digitalWrite( senzor, senzor_activ );
}

{
  if ( analogRead( A2 ) <  700)
  {
   Serial.println("THE SENSOR IS ACTIV !!! ");
   }
  }
}

Grumpy_Mike:
Your code will only ever activate the sensor if what is read on A2 is less than 700.
How are you going to get a reading from the sensor to give you that reading if it is never active?

Yes sensor will can get activ is is less 700 , but i want to " out of the circuit " if i case 'd ' and if i case 'a ' to " enter in circuit "

If is never active , then there will not read anything . But if i case 'a ' will start reading

Grumpy_Mike:

byte senzor = 7;

int senzor_activ;

void setup(){

pinMode( senzor, OUTPUT );
  Serial.begin(9600);
  senzor_activ =1;
  digitalWrite( senzor, senzor_activ );
  Serial.println("Senzor Activ/inactiv - a/d ");
}

void loop()
{
if( Serial.available() ){

switch(Serial.read()) {
      case 'q':
      Serial.println("Senzor Activ/inactiv - a/d ");
      senzor_activ = 1;
      break;
   
    case 'a' :
      senzor_activ = 1;
      Serial.println("The sensor is ON");
      break;
   
    case 'd' :
      senzor_activ = 0;
      Serial.println("The sensor is OFF");
      break;
    }
    digitalWrite( senzor, senzor_activ );
}

{
  if ( analogRead( A2 ) <  700)
  {
   Serial.println("THE SENSOR IS ACTIV !!! ");
   }
  }
}

The program is not stop the sensor . He is continue running :frowning:

OK, thanks for letting us know.

AWOL:
OK, thanks for letting us know.

Sorry I do not know to speak very good English and more I'm missing some things: (

You are missing the fact that you never explain what you want to do. Nether in this thread or the other one you had.

He is continue running

So what do you want it to do?
If you only want to to read the sensor when you activate the LED, then:-

byte senzor = 7;
int senzor_activ;

void setup(){ 


  pinMode( senzor, OUTPUT );
  Serial.begin(9600); 
  senzor_activ =1;
  digitalWrite( senzor, senzor_activ );
  Serial.println("Senzor Activ/inactiv - a/d ");
}

void loop()
{
if( Serial.available() ){

    switch(Serial.read()) {
      case 'q': 
      Serial.println("Senzor Activ/inactiv - a/d ");
      senzor_activ = 1;
      break;
   
    case 'a' : 
      senzor_activ = 1;
      Serial.println("The sensor is ON"); 
      break;
    
    case 'd' : 
      senzor_activ = 0;
      Serial.println("The sensor is OFF"); 
      break;
    }
    digitalWrite( senzor, senzor_activ );

{
  if ( analogRead( A2 ) <  700)
  {
   Serial.println("THE SENSOR IS ACTIV !!! ");
   }
  }
 }
}