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.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% 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.
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}