How to check if my 5x CNY-70, one button sensors are working

So I have a boe bot with 5 CNY-70 sensors, my code if the following:

#include <Servo.h> // Include servo library

Servo servoLeft; // Declare left and right servos
Servo servoRight;
int button=2;
int led=11;
int value=0;
int d3=3;
int d4=4;
int d5=5;
int d6=6;
int d7=7;

void setup() // Built-in initialization block
{
Serial.begin(9600);
pinMode(button, INPUT_PULLUP);
pinMode(led, OUTPUT);
pinMode(d7, INPUT); // Set right whisker pin to input
pinMode(d6, INPUT);
pinMode(d5, INPUT); // Set right whisker pin to input
pinMode(d4, INPUT);
pinMode(d3, INPUT);

delay(1000); // Delay to finish tone

servoLeft.attach(12); // Attach left signal to P12
servoRight.attach(13); // Attach right signal to P13

//forward(2000); // Go forward for 2 seconds
//turnLeft(1500); // Turn left for 0.6 seconds
//turnRight(600); // Turn right for 0.6 seconds
//forward(2000); // go backward for 2 seconds

disableServos(); // Stay still indefinitely
}

void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
int sensor1 = digitalRead(d7); //Leftmost
int sensor2 = digitalRead(d6);
int sensor3 = digitalRead(d5); //middle
int sensor4 = digitalRead(d4);
int sensor5 = digitalRead(d3); //Rightmost

Serial.println(sensor5);
Serial.println(value);
Serial.println(sensor4);
Serial.println(value);
Serial.println(sensor3);
Serial.println(value);
Serial.println(sensor2);
Serial.println(value);
Serial.println(sensor1);
Serial.println(value);

int buttonState = digitalRead(button);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(led, HIGH);
} else {
// turn LED off:
digitalWrite(led, LOW);
}
delay(100);
}

void forward(int time) // forward function
{
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise
delay(time); // Maneuver for time ms
}

void turnLeft(int time) // Left turn function
{
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise
delay(time); // Maneuver for time ms
}

void turnRight(int time) // Right turn function
{
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(time); // Maneuver for time ms
}

void backward(int time) // backward function
{
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(time); // Maneuver for time ms
}

void disableServos() // Halt servo signals
{
servoLeft.detach(); // Stop sending servo signals
servoRight.detach();
}

It works fine for the movement part but led does not turns on even if i pres the button… I get no error while compiling… Is there any way I can check if my sensors are working ? or am I doing something wrong in the code? Also how can i see the values of the sensors on my screen?

p.s.- Any help is appreciated

Please post a wiring diagram. (not a Fritzing)

thanks for the reply although i figured out what was wrong, apparently my led was bad but my sensors were working fine when i checked on serial monitor.(pretty silly mistake) .

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.