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
if ( analogRead(pinANALOG_FLEX_SENSOR) <= 10 )
{
digitalWrite(pinLED, LED_ON);
}
else
{
digitalWrite(pinLED, LED_OFF);
}
^That would be "analogRead"
if ( analogRead(pinANALOG_FLEX_SENSOR) <= 10 )
{
digitalWrite(pinLED, HIGH);
}
else
{
digitalWrite(pinLED, LOW);
}
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.
This is untested code. Your flex sensor should be connected to analog pin 0 and the LED to pin 12.
byte pinLED = 12;
byte pinFlex = A0;
void setup()
{
pinMode(pinLED, OUTPUT);
}
void loop()
{
if ( analogRead(pinFlex) <= 10 )
{
digitalWrite(pinLED, HIGH);
}
else
{
digitalWrite(pinLED, LOW);
}
}
Thank you very much for your help.
Quick5pnt0:
^That would be "analogRead"
Yes, well, I was being rushed out the door ...