const int variable value changes?!

Hi! First of all, thanks for any help you can provide me. I’m baffled.

The variable ldrpause is set to 60000. But the Serial.print prints out -5326 (shoot, now I can’t remember the exact value, but it was something like that).

WHY?!?! It works correctly for the other variables like doorheight.

int dirpin = 2;                   		// motor direction pin
int steppin = 3;                  		// motor control pin
const int doorheight = 27000;     		// corresponds to how high the door raises
int SLEEP = 7;                    		// PIN 7 is connected to SLP on the motor controller

const int numReadings = 3;        		// number of light sensor readings
const int ldrpause = 60000;                     // time in milliseconds between light sensor readings
int readings[numReadings];        		// the readings from the light sensor
int index = 0;                    		// the current reading
int total = 0;                    		// the running total
int averageLight = 0;                 		// the averageLight

const int lightthreshold = 11;    		// value to trigger opening the door
const int darkthreshold = 10;     		// value to trigger closing the door
int doorstate = 1;                		// 0 means open, 1 means closed

int motionvalue = 0;              		// the value read by the motion sensor

int LDRinputPin = A0;             		// read light sensor value from this pin
const int ledPin = 13 ;
const int motionPin = 12;

void setup()
{
  Serial.begin(9600);             		// initialize serial communication with computer   
  for (int thisReading = 0; thisReading < numReadings; thisReading++)     
    readings[thisReading] = 0;    		// initialize all the readings to 0 
  pinMode(motionPin, INPUT);      		// declare motion sensor as input
  pinMode(ledPin, OUTPUT);        		// set pinMode to output to turn on the LED lights
  pinMode(dirpin, OUTPUT);        
  pinMode(steppin, OUTPUT);       
  pinMode(SLEEP, OUTPUT);         		// set the SLEEP pin to output

delay(10000);                     		//to get the serial monitor open
Serial.println(ldrpause);
}

I’m using a Uno and Win7. I’m trying to make an automated chicken coop door, in case you were wondering.

Because it’s type int, which has a value range of -32768 to 32767. Basically once the value goes past 32767, it rolls over into the negatives so 60000 - 65535(double the range) is the value you are seeing. If you make it unsigned long in which case the value range is now 0 to 65535, it won’t change. Take a look at the arduino refference page to see all the types.

I'm trying to make an automated chicken coop door

Oh no, not another one 8)

HazardsMind: Because it's type int, which has a value range of -32768 to 32767. Basically once the value goes past 32767, it rolls over into the negatives so 60000 - 65535(double the range) is the value you are seeing. If you make it unsigned long in which case the value range is now 0 to 65535, it won't change. Take a look at the arduino refference page to see all the types.

Awesome, thanks.

JimboZA:

I'm trying to make an automated chicken coop door

Yes but MINE is the BEST. Except that it doesn't work. Oh no, not another one 8)