using a flex sensor

Hello,

I'm trying to get readings on the Arduino serial print from my flex sensor. This is the code I have.

#define flexPin 1
int flexVal;

void setup() {
  Serial.begin(9600);
}

void loop() {
  flexVal = analogRead(flexPin);
  Serial.println(flexVal);
}

The numbers I'm getting from this aren't very good though. I don't know. They seem to be a bit arbitrary. I followed the schematic for using a photocell variable resistor according to the Arduino Spooky Projects Class 2 pdf file.

I'm a real noob to circuits and the arduino. Would anyone be kind enough to let me know what I'm doing wrong?

It seems I am having the same problem but with a photo resistor. I get values around 1023 with it connected and values around 300 - 500 without anything connected. What's up?

hi

@Drewu, my guess is that you need a resistor for your circuit. Google "voltage divider" and add make a voltage divider using a 10K resistor.

@gasoy, can you measure the value on the analog input with a voltmeter? Check to see if there is a range of voltage in response to light changes. One other possibility is that 9600 baud updates slowly, and thus you will miss values while the serial is transmitting. ... try 115200.

D

I tried it and it kida works. But first let me know it I have this strait. I connect a resistor (I tried many with about the same result) to the 5V onboard power and ground. I then connect the photoresistor to my analog pin and the ground pin on the resistor. It seem this inverts my output. It now hovers around 0 and goes up if I cover it. It is still not usably sensitive though. Have I got it right?

I am also wondering why does the pin idle at 400ish?

BTW, Sorry for dragging you back through electronics 101. Oh and thanks for all the help. It helps.

Woot! Got it to work! Found the nice tutorial here: http://todbot.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class2.pdf It turns out I totaly misunderstood the voltage divider page that I looked up on google and that was my mistake. Thanks a bunch!