0

Is there a way to implement an Infrared sensor as input in an Arduino code ? I want the sensor to send data to the Arduino in values (changes of the IR position) and then use that value as an input in the software.

Code is an example of a light resistive sensor that turns on the LED every time it's dark, and turns it off when the light sensor detects its bright.

int sensor1Value = 0;
void setup()
{
  // declare the ledPins as an OUTPUT:
  pinMode(13, OUTPUT);
  
}

void loop() {
  // read the value from the sensor:
  sensor1Value = analogRead(A0);
{
  if(sensor1Value <200)     // check the value of sensor 
 {                          //if the value is less than 200 then turn the leds on
 digitalWrite(13, HIGH);
  delay(500);
 }
 else                      // if the value is greater than or equal to 200 then turn leds off
 {
  digitalWrite(13, LOW);
  delay(500);
}
}

1 Answer 1

0

The simpliest way is to use IR phototransistor

There is no need for a delay after each digitalWrite(), just add it at the end of the loop() function.

void loop() {
  // read the value from the sensor:
 sensor1Value = analogRead(A0);
 if(sensor1Value <200)     // check the value of sensor 
 {                          //if the value is less than 200 then turn the leds on
 digitalWrite(13, HIGH);
  
 }
 else                      // if the value is greater than or equal to 200 then turn leds off
 {
  digitalWrite(13, LOW);
 
 }
 delay(500);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.