hi need servo tune help

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);
}

map(cm, 0.1,oops

???? what

int angle = map(cm, 0.1, 5, 10,  180);

The map function works with integers only. 0.1 will be treated as 0.

You have not told us what rangefinder that you are using. Mind that the minimum range of an HC SR04 rangefinder (and its relatives) is 2 cm.

thats is not problem and just that rangef i use , try my laser auto height tuning at the burning point be always focused even dont have flat surface :frowning:

No, sorry.
Can you explain your problem please?
How does the burning problem relate to the 100mm travel problem?

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 :slight_smile: 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;
        }
    }
}

No.
Arduinos don't understand "nicely".

:smiley: yes i start feel so do

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

I really have no idea what you're trying to do, or how.

need make laser engraver mount what keep the burning point same for moving up and down following shape of surface ... simple if i was better coder :frowning:

Industry Plasma Cutting Machine with HYD Auto Height Control - YouTube like this machine

keep the burning point same for moving up and down following shape of surface ... simple if i was better coder

How do you measure the distance?

How do you control the height?

Why do you think any of this should be "simple"? I don't.

jremington:
How do you measure the distance?

With an ultrasound ranger.

How do you control the height?

With a servo.
Sheesh. Haven't you been following this?

Sorry, will pay closer attention next time. But now that I have, sonar won't work for this project (as already noted).