Skip to content

Instantly share code, notes, and snippets.

@IdrisCytron
Created July 25, 2017 03:44
Show Gist options
  • Save IdrisCytron/4bac83fa84ce9abec3c6b5a1f6700c4b to your computer and use it in GitHub Desktop.
Save IdrisCytron/4bac83fa84ce9abec3c6b5a1f6700c4b to your computer and use it in GitHub Desktop.
IR Distance Click Arduino examples code
void setup()
{
// IR Distance Click OUT pin is connected to pin A0
// Set A0 as input
pinMode(A0, INPUT);
// Initialize Serial for debug purpose
Serial.begin(9600);
delay(1000); // Put some delay
}
void loop()
{
int adc = analogRead(A0); // Read analog input from pin A0
float voltage = adc * 0.00488; // Change ADC to voltage
// Print distance information to serial
Serial.print("ADC: ");
Serial.print(adc);
if (adc < 99) Serial.print('\t');
Serial.print("\tVoltage: ");
Serial.println(voltage);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment