hey the engine should be servo move from the left end to the other extreme position and the action height would be max 100mm for sensor
#include <NewPing.h>
#include <Servo.h>
#include <NewPing.h>
const int Servopin = 11;
const int Triggerpin = 10;
const int Echopin = 9;
// 10 = maxDistance
NewPing sonar(Triggerpin, Echopin, 10);
Servo servo;
void setup() {
Serial.begin (9600) ;
servo.attach(Servopin);
}
void loop() {
int cm = sonar.ping_cm();
Serial.println(cm);
int angle = map(cm, 0.1, 5, 10, 180); <<< here is the what i need figure out i think
servo.write(angle);
delay(40);
}
just need make servo work nicely full rotation range.... ok no servo no ultrasonic sensor but laser sensor and stepper motor with lead screw will work here some stuff
// Include Libraries
#include "Arduino.h"
#include "StepperMotor.h"
// Pin Definitions
#define STEPPERGEARED_PIN_STEP 3
#define STEPPERGEARED_PIN_DIR 2
// Global variables and defines
#define stepperGearedDelayTime 1000
// object initialization
StepperMotor stepperGeared(STEPPERGEARED_PIN_STEP,STEPPERGEARED_PIN_DIR);
// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println("start");
// enable the stepper motor, use .disable() to disable the motor
stepperGeared.enable();
// set stepper motor speed by changing the delay value, the higher the delay the slower the motor will turn
stepperGeared.setStepDelay(stepperGearedDelayTime);
menuOption = menu();
}
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{
if(menuOption == '1') {}
// Disclaimer: The Adafruit VL53L0X Time of Flight Distance Sensor is in testing and/or doesn't have code, therefore it may be buggy. Please be kind and report any bugs you may find.
else if(menuOption == '2') {
// Small Reduction Stepper Motor - 5VDC 32-Step 1/16 Gearing - Test Code
// the higher the time value the slower the motor will run
stepperGeared.step(1, 1000); // move motor 1000 steps in one direction
delay(1000); // short stop
stepperGeared.step(0, 1000); // move motor 1000 steps in the other dirction
delay(1000); //short stop
}
if (millis() - time0 > timeout)
{
menuOption = menu();
}
}
// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{
Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) Adafruit VL53L0X Time of Flight Distance Sensor"));
Serial.println(F("(2) Small Reduction Stepper Motor - 5VDC 32-Step 1/16 Gearing"));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());
// Read data from serial monitor if received
while (Serial.available())
{
char c = Serial.read();
if (isAlphaNumeric(c))
{
if(c == '1')
Serial.println(F("Now Testing Adafruit VL53L0X Time of Flight Distance Sensor - note that this component doesn't have a test code"));
else if(c == '2')
Serial.println(F("Now Testing Small Reduction Stepper Motor - 5VDC 32-Step 1/16 Gearing"));
else
{
Serial.println(F("illegal input!"));
return 0;
}
time0 = millis();
return c;
}
}
}
int angle = map(cm, 0.1,is this start postion 5 this end position, 10what this, 180 and this)
can is use mm instead cm´s is ultrasonic sensor accary real for 1cm need like 1mm maybe laser sensor better