Light sensor module

I can’t seem to find a tutorial based on a light sensor I’ve purchased (and received) that doesn’t include a sensor shield…
As I’m new to Arduino, I have yet again no idea what to do with this. It only has 3 inputs, but I am afraid of blowing it.

The back of the sensor is labelled -, + and S. Here is a labelled picture of the sensor:

nate890: I can't seem to find a tutorial based on a light sensor I've purchased (and received) that doesn't include a sensor shield... As I'm new to Arduino, I have yet again no idea what to do with this. It only has 3 inputs, but I am afraid of blowing it.

The back of the sensor is labelled -, + and S. Here is a labelled picture of the sensor:

You would plug the - wire into ground, the + wire into 5 volts, and the S wire into the Arduino analog input pin (A0..A5). The sensor shields have the 3 pins grouped together, so that you can use a 3 element wire to connect them with one cable. The shields make it simple to plug in multiple sensors since they provide a ground and power pin for each digital and analog pin.

If you have more than one sensor, you likely need a breadboard if you don't get a sensor shield in order to plug each sensor into both the ground and power pins. On most breadboards, there are two columns on either side, a red column, and a black column. You plug the 5 volt pin into the red column, and the ground pin into the black column. Then for each sensor you would plug the - into the black column, the + into the red column, and the S wire into the pin.

Maybe I blew it… Doesn’t seem to work with this code

int ledPin = 13; // choose pin for the LED
int inputPin = 1; // choose input pin (for Push Button)
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare magnetic switch as input
}
void loop(){
val = analogRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
delay(500);
}

Hey 57 posts and you are still not using the # icon to post code.

int inputPin = 1;               // choose input pin (for Push Button)

Do not use pins 0 & 1 as they are used for serial communications.

val = analogRead(inputPin);  // read input value

Now what is it? A push button or an analogue input. Where is it wired up?

Ahh, worked with other code. It’s hooked up to A1

It's hooked up to A1

So you can't use:-

val = analogRead(inputPin);  // read input value
  if (val == HIGH) {

Because val will always be HIGH and never LOW. HIGH and low are Boolean values, analogRead returns a number from 0 to 1023. Unless it returns 0 it will always be high. Print out the values of val and see how this changes.

nate890: Ahh, worked with other code. It's hooked up to A1

Then you should use:

int inputPin = A1;               // choose input pin (for Push Button)

thanks all