Go Down

Topic: Flew sensor and a LED (Read 375 times) previous topic - next topic

ColeH

Hello,
    I am new to arduino and coding and i have a question regarding flex sensors.  I am trying to make it so that when a flex sensor has a value between 10 and 0, around the straight position,  then turn on a LED. And when it is bent, the LED is turned off.  I have looked around online and can not figure out how to do this.  Can anybody help?
Thanks

lloyddean

#1
Jan 30, 2013, 02:27 am Last Edit: Jan 30, 2013, 08:01 am by lloyddean Reason: 1
Code: [Select]

if ( analogRead(pinANALOG_FLEX_SENSOR) <= 10 )
{
   digitalWrite(pinLED, LED_ON);
}
else
{
   digitalWrite(pinLED, LED_OFF);
}


Quick5pnt0

^That would be "analogRead"

Code: [Select]
if ( analogRead(pinANALOG_FLEX_SENSOR) <= 10 )
{
    digitalWrite(pinLED, HIGH);
}
else
{
    digitalWrite(pinLED, LOW);
}

ColeH

Thank you for wha you have shown me, but how would I set everything up so that the console knows what I mean by analogread and what not.
I am sorry, I am new.

Quick5pnt0

#4
Jan 30, 2013, 07:30 am Last Edit: Jan 30, 2013, 07:33 am by Quick5pnt0 Reason: 1
This is untested code. Your flex sensor should be connected to analog pin 0 and the LED to pin 12.

Code: [Select]
byte pinLED = 12;
byte pinFlex = A0;

void setup()
{                
   pinMode(pinLED, OUTPUT);    
}

void loop()
{
   if ( analogRead(pinFlex) <= 10 )
   {
       digitalWrite(pinLED, HIGH);
   }
   else
   {
       digitalWrite(pinLED, LOW);
   }
}

ColeH

Thank you very much for your help.

lloyddean


^That would be "analogRead"


Yes, well, I was being rushed out the door ...

Go Up