Skip to content

Instantly share code, notes, and snippets.

@penpencool
Last active May 20, 2018 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penpencool/043423103db9342f4a994d483c8a1eae to your computer and use it in GitHub Desktop.
Save penpencool/043423103db9342f4a994d483c8a1eae to your computer and use it in GitHub Desktop.
/*
Example By ArduinoAll
VCC -> 5V
GND -> GND
Vo -> A0
*/
int IRpin = A0; // ต่อเซนเซอร์กับขา A0
void setup() {
Serial.begin(9600);
}
void loop() {
float volts = analogRead(IRpin) * 0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 65 * pow(volts, -1.10);
Serial.println(distance);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment