Forums > MaxMSP

Photo resistors reversing values on Arduino

April 23, 2014 | 3:00 am

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<6; x++) {
sensVar=analogRead (x);
Serial.write(x);

Serial.write(sensVar);

}

}

This is fed into a max patch

  • This topic was modified 4 months by  stevepk123.
Attachments:
  1. Screen-shot-2014-04-14-at-19.59.51
  2. Screen-shot-2014-04-23-at-11.00.311
  3. Screen-shot-2014-04-23-at-11.00.31

April 23, 2014 | 5:10 am

Hi
the problem is one I encountered and had solved recently

http://cycling74.com/forums/topic/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


April 23, 2014 | 7:02 am

Glad to see that’s still handy. :)


April 24, 2014 | 1:46 am

Hey guys thank you so much for your help :)


April 24, 2014 | 6:32 am

:)


Viewing 5 posts - 1 through 5 (of 5 total)