0% found this document useful (0 votes)
15 views

IR Sensor Arduino Code

The document describes code for reading IR sensor values from an Arduino using both analog and digital pins. It initializes the analog and digital pins for the IR sensor, reads the sensor values in a loop, and prints the analog and digital values to the serial monitor.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

IR Sensor Arduino Code

The document describes code for reading IR sensor values from an Arduino using both analog and digital pins. It initializes the analog and digital pins for the IR sensor, reads the sensor values in a loop, and prints the analog and digital values to the serial monitor.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

IR Sensor Arduino Code

int ir_analog = A0;


int ir_analog_val;
int ir_digital_val;
int ir_digital=D13;

void setup()
{
pinMode(ir_analog, INPUT);
pinMode(ir_digital, INPUT);
}
void loop()
{
ir_analog_val= analogRead(ir_analog);
ir_digital_val = digitalRead(ir_digital);

Serial.print("Analog Value - ");


Serial.println(ir_analog_val);
Serial.print("Digital Value - ");
Serial.println(ir_digital_val);
}
int sensorpin = 0; // analog pin used to connect the sharp sensorint val = 0;
// variable to store the values from sensor(initially zero)void setup(){ Serial.begin(9600);
// starts the serial monitor} void loop(){ val = analogRead(sensorpin); // reads the value
of the sharp sensor Serial.println(val); // prints the value of the sensor to the serial
monitor delay(100); // wait for this much time before printing next value}

You might also like