Can anyone help me with this? I don't know much about hardware. But i am trying to read 2 photocells with a arduino uno. They have the potentiometer and return 1 or 0. When i have 1 connected all works fine, but when i connect the second, both pins return 1 when activated. I am using digitalRead and have tried setting pinmode to both input and input_pullup. Is there something i am doing wrong, or can't you read multiple digital input pins?
Hi.... You need to:
a) post your code (using the # button to make it easily read) and
b) post a circuit diagram.
Then you'll probably get some helpful response.... 8)
Here is more information...
This is the sensor i am using
http://www.robotshop.com/electronic-brick-light-sensor.html
void setup()
{
Serial.begin(9600);
pinMode(3, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
}
void loop() {
sensorValue = digitalRead(3);
Serial.print("DR3-");
Serial.println(sensorValue);
sensorValue = digitalRead(7);
Serial.print("DR7-");
Serial.println(sensorValue);
}
Maybe i should ask this... should i be able to read to digital inputs? Say input pins 3 and 7 are used. Can i use digitalread(3) and digitalread(7) in the sketch and expect to see 2 different results? I seem to get the same results on both reads. If pin 3 is a 1 pin 7 automatically is 1 also. I can't seem to read them separately.
I thought i can read each digital input separately on the uno. Or do i have a bad board or something...or is it just me:(
Thanks
Yes, you can read 2 pins and get different results. How do you have the photo sensors and potentiometers connected to the Arduino?
I have the + off the sensor to the 5v and the - off the sensor to the gnd next to it. The S off the sensor is going to the 4 pin and 7 pin. These are connected to a breadboard.
So 5v goes into breadboard. GND goes into breadboard. Then the + and - from sensors connect into breadboard. Then the S wire goes directly into the pins(4 and 7).
Would i need any resistors on this?
You code uses pins 3 and 7, and one of your posts mentions those pins.
But your last post says 4 and 7.... twice.
Edit.... I see from the pic and datasheet (more of a *non-*datasheet) that you need to set the brick to Analog or Digital... have you got the switches set correctly?
I have been trying different pins that is why the confusion. I do have the switch set to digital.
When i just do one read it works fine. When I attach the second and use the 2 digitalreads is when i get 2 positives. For either one. If i cover sensor 4 it shows 2 ones. (1 for pin 4 and 1 for pin 7) If i cover sensor 7 it will also show 2 ones. Its like they are attached somehow.
Hmmmm.... maybe post a pic of the setup?
Attached is the image...
test.bmp (2.1 MB)
That looks ok to me- now post a photo of your actual setup.....
Edit.... have you hooked them up one at a time, so that you know both bricks actually work?
Yes i tested both and both work...i will work on posting the picture.