Loading...
  Show Posts
Pages: 1 2 [3]
31  Using Arduino / Sensors / Re: sharp ir switch on: October 18, 2012, 12:46:12 am
work like charm,no debounce and very stable,thank you so much johnwasser,i realy apreciate your help smiley-grin
32  Using Arduino / Sensors / sharp ir switch on: October 17, 2012, 10:52:36 am
hi everyone,after reading allmost all post around here and google,hope 2 get my answers here.I found hundred of examples of Ir conected to Atmegas that light up a Led when get close to object,but not even one example on how to make a toogle switch.Im not the only one looking for codes like this,truth is this subject is avoided,anyway..I wanna do a simple toogle switch,with the arduino Duemilanove and the Sharp 2Y0A21 ir sensor,that can light a Led.So far i can only make it like momentary switch:
+LED on pin 13
+DATA from ir on pin analog 0
----------------------------------
int led1 = 13;
int sensor = A0;
 
void setup() {
  Serial.begin(9600);
  pinMode(led1, OUTPUT);     
}
 
void loop() {
// we read the sensor Value
  int Value = analogRead(A0);
// we maps the value
  int sensorValue = map(Value, 0, 1024, 0 , 200);
// turn on the led1 when the value is beetween 50 and 100
  if ( sensorValue > 50 && sensorValue <300){
    digitalWrite(13, HIGH);
 
  }

  else {
// turn off the two leds
    digitalWrite(13, LOW);
   
  }
  Serial.println(sensorValue);
  delay(100);
}
Pages: 1 2 [3]