/* ---------- analog_Sensor sends data to Serial ------------- Hardware Setup- a voltage divider connected to analog 5 : 1) -Wire a photoresister between +5vdc and an empty row on the breadboard 2) -Wire a 10k resistor between that same row on the breadboard to ground. 3) -Jumper wire from that same row to the last pin on the chip (analog 5) or 1) -Wire the outer pins of a pot to +5v and Gnd 2) -Wire the middle pin (wiper) to analog pin A5 -------------------------------------------------------------------------*/ int sensorPin = A5; // variable for analog pin as A5 int a_in; // create variable for storing analog readings int highValue = 255; // variables for hi and low output ranges int lowValue = 0; void setup() { Serial.begin(9600); } void loop() { // read sensor, store in variable, print a_in = analogRead(sensorPin); // get 10 bit analog value // Uncomment this to see the raw data - work with your sensor to determine the range // that's useful: dark/light, straight bent, hot/cold, etc. //Serial.println(a_in); // Now, map the useful input range to the desired output range // 580 - 900 is the range for my sensor, yours will be different a_in = map(a_in, 580, 900, lowValue, highValue); // scale it to 8 bits // Next, CONSTRAIN the output values so they do not exceed your output range; // this can happen if the input range exceeds what you set above - maybe it got a bit darker // or you bent the bend sensor a bit farther than normal... a_in = constrain(a_in, lowValue, highValue); // note, CONSTRAIN is the same a doing this: // if (a_in < lowValue) { // a_in = lowValue; // } // // if (a_in > highValue) { // a_in = highValue; // } // This is our scaled value to be sent as ASCII to Procesing, Max, PureData, etc. // Remember, ASCII means we are sending characters, so 200 means we send // 2, 0, 0, carriage return, line feed or the series: 50 48 48 13 10 // see: http://www.asciitable.com Serial.println(a_in); // Sometimes it's easier to just send the data itself, as a single number // especially for Max and PureData. The number can only be a single BYTE // meaning it cannot be less than 0 or exceed 255. If you use this, be // sure to comment out the Serial.println() function above. //Serial.write(a_in); delay(100); // easier to read screen }