digitalRead returning pin number instead of a value

I've stared at this simple few lines of code for hours but I can't see what's wrong.
It's got to be syntax right?

I simply want to check a pin and then assign it's value to another variable name.
Checking the program with serialPrint though and all it gives me is the pin number.
I'm expecting a 1 or 0
Help please.
If you are wondering about the variables defined here that aren't used in this simple program. They are part of a much longer program, as will this bit of program when I get it working.

// defines how long events will occur
    const long fanHigh = 30000; //how long to run fan high speed
// defines variables
    const int fanPin = 5; //which pin is controling fan
         long seqTimer = 0; //time between fan blasts
    const int slow;
    const int fast;
          int fanSpeed;
     long int fastDurr;
    unsigned long seqStart = 0;    //the time when the whole sequence began
    unsigned long fan_HighTime = 0;//the time when fan was switched to High
    unsigned long fastStart = 0;   //time that fan was switched to high
             long timeNow = 0;

//these are the defines for the sensor
    const int detectPin = 6;//Pin connected to TTL
    const int detect = 10;  //Pin connected to LED & 
    int senState = HIGH;    // senser initial state
    int motion = 0;         // variable High or LOW

void setup() {
    pinMode(fanPin,OUTPUT);// initialize digital pin 5 as an output for fan control.
    int fanSpeed = 0;      // starts fan at low speed
    long int fastDurr = (timeNow - fastStart);

    pinMode(detectPin, INPUT); // Sets the detect pin (6) as an Input

    pinMode(detect, OUTPUT);  //led indicator light

    digitalWrite(detect,LOW); //start with red LED off


void loop() {
                Serial.println(" fan speed");

    timeNow = millis(); //remember current time

    digitalRead(detectPin);  //read pin 6
        Serial.println(" detectPin");
        Serial.println(" ");
    fanSpeed = detectPin;   //assign pin 6 value to "fanSpeed" variable

        Serial.println(" fan speed");
        Serial.println(" ");




     Serial.print( digitalRead(detectPin) );


     Serial.print( digitalRead(detectPin) );

Yep, that did the trick.
Thank you!

We need to review the digitaRead() function to understand why your these codes:


did not work;

but, the following code @Blackfin worked:

Serial.print( digitalRead(detectPin) );

1. The following is the description of the digitalRead() function, which has been taken from the Arduino Reference Manual.


pin: the Arduino pin number you want to read


The instruction says that it will read 1-bit data from a digital pin (here the name is pin; in your case it is detectPin) and will store it in an 1-bit location as HIGH or LOW (the Return value). Therefore, the user has to declare an 1-bit location (like: bool n;) to catch/hold the return value.

So, the syntax of digitalRead() instruction would be:

bool n = digitalRead(detectPin);

And the codes to display the pin-value would be:

bool n = digitalRead(detectPin);
Serial.print(n);                   //Serial Monitor shows: 1 or 0 depending on Button position

Or in nested form due to @Blackfin: (this is not a trick but a standard practice)

Serial.print(digitalRead(detectPin));  //n is replaced by digitalRead(detectPin);