Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[questions] if the distance is less than 5 cm, switch off the LED on pin 5 #3

Open
vongomben opened this issue Jul 21, 2020 · 0 comments

Comments

@vongomben
Copy link
Owner

vongomben commented Jul 21, 2020

How do we do that?

this is the referral code

/*

  Example taken from Seeestudio Wiki
  for the Grove Ultrasonic Ranger
  https://wiki.seeedstudio.com/Grove-Ultrasonic_Ranger/
  adapted to work with Arduino Grove Carrier (on MKR1010)

  https://www.arduino.cc/en/Guide/MKRConnectorCarrier
  by Davide Gomba

  Library here
  https://github.com/Seeed-Studio/Seeed_Arduino_UltrasonicRanger/archive/master.zip

  Install Library Sketch>include Library> Add Zip Library
*/




#include "Ultrasonic.h"

int led = 5;

Ultrasonic ultrasonic(0);

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}
void loop()
{
  long RangeInInches;
  long RangeInCentimeters;

  /* Serial.println("The distance to obstacles in front is: ");
    RangeInInches = ultrasonic.MeasureInInches();
    Serial.print(RangeInInches);//0~157 inches
    Serial.println(" inch");
    delay(250);
  */
  RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
  Serial.print(RangeInCentimeters);//0~400cm
  Serial.print(" cm");
  int value = map(RangeInCentimeters, 0, 30, 0, 255);
  Serial.print(" - ");
  Serial.println(value);
  analogWrite(led, value);

  delay(25);
}
@vongomben vongomben changed the title [questions] if the distance is less than 5 cm, swutch off the LED on pin 5 [questions] if the distance is less than 5 cm, switch off the LED on pin 5 Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant