Go Down

Topic: VL53L0X to control Servo (Read 829 times) previous topic - next topic

anases

can someone please help me write the code to make the servo move when the VL53L0X sensor reach cretin range,,

ive wrote the basic code as below :

#include <Wire.h>
#include <VL53L0X.h>


VL53L0X sensor;

void setup()
{
  pinMode(12,INPUT_PULLUP);
  digitalWrite(12,HIGH);
  Serial.begin(9600);
  Wire.begin();

  sensor.init();
  sensor.setTimeout(500);

  // Start continuous back-to-back mode (take readings as
  // fast as possible).  To use continuous timed mode
  // instead, provide a desired inter-measurement period in
  // ms (e.g. sensor.startContinuous(100)).
  sensor.startContinuous();
}

void loop()
{
  int distance =sensor.readRangeContinuousMillimeters();
  //int distance =sensor.startContinuous(100);
 
 //distance = distance;
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.print("mm");
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
  delay(100);
}


what should i do next ?

slipstick

Have a look at the Knob example in the IDE. That moves a servo in response to a potentiometer. There's not much difference between values read from a sensor and values read from a potentiometer so that should give you most of what you need.

Steeve


anases

thanks for the reply,

i saw that, but sorry i am not that good writing  in the IDE.

i need someone to help me writing the code.


slipstick

"Help" means you make some attempt at writing it, post your attempt here and then we tell you how to get it working.

If you don't want to put any effort in yourself and just want someone to write a program for you try asking in the Gigs and Collaborations forum and be prepared to pay for it.

Steve

anases

thanks again, i will try to do my best

TomGeorge

#5
Aug 25, 2019, 03:29 pm Last Edit: Aug 25, 2019, 03:30 pm by TomGeorge
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up