Pages: [1]   Go Down
Author Topic: Flew sensor and a LED  (Read 321 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if ( analogRead(pinANALOG_FLEX_SENSOR) <= 10 )
{
    digitalWrite(pinLED, LED_ON);
}
else
{
    digitalWrite(pinLED, LED_OFF);
}
« Last Edit: January 30, 2013, 02:01:31 am by lloyddean » Logged

NE PA
Offline Offline
Full Member
***
Karma: 5
Posts: 156
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

^That would be "analogRead"

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


Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

NE PA
Offline Offline
Full Member
***
Karma: 5
Posts: 156
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is untested code. Your flex sensor should be connected to analog pin 0 and the LED to pin 12.

Code:
byte pinLED = 12;
byte pinFlex = A0;

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

void loop()
{
    if ( analogRead(pinFlex) <= 10 )
    {
        digitalWrite(pinLED, HIGH);
    }
    else
    {
        digitalWrite(pinLED, LOW);
    }
}
« Last Edit: January 30, 2013, 01:33:21 am by Quick5pnt0 » Logged


Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much for your help.
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

^That would be "analogRead"

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

Pages: [1]   Go Up
Jump to: