Photo resistors reversing values on Arduino
Hello I am using 6 photo resistors/LDR's with an Arduino Mega 2560, the LDR is connected to +5V then the other leg of the LDR goes to the control cable in the Arduino (A0-A5) then finally a 10K resistor to the Arduino's ground. The aim is to make a laser harp, with the photo resistors producing a high resistance when light is upon them and low when the beam has been broken (or the opposite way around), however I have an intermittent problem were random LDR's invert the value making the LDR's perform in the opposite manner whilst the other's function as intended. Has anyone experienced this before or have suggestions?
The code on the arduino is:
int sensVar;
void setup () {
Serial.begin(9600);
}
void loop () {
for(int x=0; x
sensVar=analogRead (x);
Serial.write(x);
Serial.write(sensVar);
}
}
This is fed into a max patch
Hi
the problem is one I encountered and had solved recently
https://cycling74.com/forums/unravelling-16-10-bit-sensor-stream/
The pin idents and sensor value-pairs (0 96; 1 12; 2 13; 3 54 . . . ) are being sent continuously by the Arduino sketch. You need some way to guarantee that each pair arrives, in order and when requested.
If your circuit is solid, Steven Miller's solution in the thread I cite above is where your happiness lies!
Essentially what it does is tell the Arduino to wait until it gets a specific character from Max, before sending a complete bundle of ident-value pairs for each sensor; the package is terminated with a CR/LF (ASCII 13 10); this tells Max that the package is complete, and the process begins again. You can ignore all the 10-bit stuff in that thread, unless you want to try it.
HTH
Brendan
Glad to see that’s still handy. :)
Hey guys thank you so much for your help :)