Hello, when I open the serial monitor anything appear. I have tried to put a serialprint before the while and It apeared but only once. Why my data DONT apear if I put It after the while command.

const int sensor1 = 12; const int sensor2 = 11; const int sensor3 = 13; const int sensor4 = 14; const int driver1 = 10; const int driver2 = 9; const int startbutton = 8; int pollagorda ; long timer; int condition; int direcionr; int direcioncr;

void setup() {

Serial.begin (9600); pinMode(sensor1, INPUT); pinMode(sensor2, INPUT); pinMode(sensor3, INPUT); pinMode(sensor4, INPUT); pinMode(driver1, OUTPUT); pinMode(driver2, OUTPUT); pinMode(startbutton, INPUT); timer = 0; condition = 0; direcionr = 0; direcioncr = 0; pollagorda = 0;


void loop() {

while (pollagorda == 0) { if(digitalRead(sensor1) == HIGH || digitalRead(sensor3) == HIGH){ direcioncr + 1; pollagorda + 1; } if(digitalRead(sensor2) == HIGH || digitalRead(sensor4) == HIGH){ direcionr + 1; pollagorda + 1; } } if (condition == 0 && digitalRead(startbutton) == HIGH) { digitalWrite(driver1, HIGH); digitalWrite(driver2, HIGH); condition = 1;


Serial.print ("direcionr"); Serial.println(direcionr);

Serial.print ("direcioncr"); Serial.println(direcioncr);


  1. Which Arduino are you using?
  2. Can you please edit your post to wrap [code][/code] tags around your code?
  3. What do you expect this line to do?

pollagorda + 1;

If you were expecting it to add one to pollagorda and save the result in pollagorda, then you should have used the += operator instead of +

Why my data DONT apear if I put It after the while command.

Clearly because your while statement never ends.

How is the switch wired? You are not using the internal pullup resistor, so you need an external resistor. You do have one, right?

I am almost certain that you do not have things that came in a box labeled SENSOR. So, naming pins sensor1, sensor2, etc. is useless for conveying information about what kind of sensor is attached. You also need pullup or pulldown resistors with your generic sensors, unless they are included in the sensor.