Created
July 29, 2020 14:39
-
-
Save myarduinosale/88e18d5b2fdfa749efc613b072d1e115 to your computer and use it in GitHub Desktop.
M0135_Arduino_V2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SharpIR.h> | |
int led = 2; | |
//int buzzer = 3; | |
#define IR A0 | |
#define model 430 | |
/* | |
2 to 15 cm GP2Y0A51SK0F use 1080 | |
4 to 30 cm GP2Y0A41SK0F / GP2Y0AF30 series use 430 | |
10 to 80 cm GP2Y0A21YK0F use 1080 | |
10 to 150 cm GP2Y0A60SZLF use 10150 | |
20 to 150 cm GP2Y0A02YK0F use 20150 | |
100 to 550 cm GP2Y0A710K0F use 100500 | |
*/ | |
SharpIR SharpIR(IR, model); | |
void setup() { | |
pinMode(led, OUTPUT); | |
//pinMode(buzzer, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
unsigned long startTime = millis(); | |
int dis = SharpIR.distance(); | |
//dis = dis - 2; | |
Serial.print("distance: "); | |
Serial.println(dis); | |
if (dis > 10) { | |
digitalWrite(led, LOW); | |
//digitalWrite(buzzer, HIGH); | |
} | |
if (dis < 10) { | |
digitalWrite(led, HIGH); | |
//digitalWrite(buzzer, LOW); | |
} | |
delay (500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment