system
July 20, 2014, 7:28pm
1
How to activate a sensor with serial monitor ? i have try and i can't make this i will show you the code . Please HELP . 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);
}
}
}
}
system
July 20, 2014, 7:40pm
2
And the serial monitor shows . . . what?
system
July 20, 2014, 7:43pm
3
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);
}
system
July 20, 2014, 7:47pm
4
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.
system
July 20, 2014, 7:52pm
6
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 ...
system
July 20, 2014, 7:53pm
7
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 . 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?
system
July 20, 2014, 8:06pm
9
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.
system
July 20, 2014, 8:12pm
10
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 .
system
July 20, 2014, 8:19pm
11
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
system
July 20, 2014, 8:22pm
12
Post code.
Post schematic.
Post links to sensor.
Start helping us to help you.
system
July 20, 2014, 8:34pm
13
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 !!! ");
}
}
}
system
July 20, 2014, 8:43pm
16
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
system
July 20, 2014, 8:49pm
17
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
system
July 20, 2014, 8:55pm
18
OK, thanks for letting us know.
system
July 20, 2014, 8:59pm
19
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 !!! ");
}
}
}
}