Hello, I\'m working on a school project using arduino. I\'m using a potentiomete
ID: 3740287 • Letter: H
Question
Hello, I'm working on a school project using arduino. I'm using a potentiometer to control a brushless motor and so far it works. I was just wondering how to create a dead zone so that the motor doesn't starting spinning the moment I press on the throttle.
My teacher gave me a hint:
if (voltage=>1.5) {
send out signal;
}
else {
send out zero;
}
This is the arduino code that I have and it works:
#include <Servo.h> //accesses the Arduino Servo Library
Servo myservo; // creates servo object to control a servo
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(9); // ensures output to servo on pin 9
}
void loop()
{
val = analogRead(1); // reads the value of the potentiometer from A1 (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // converts reading from potentiometer to an output value in degrees of rotation that the servo can understand
myservo.write(val); // sets the servo position according to the input from the potentiometer
delay(15); // waits 15ms for the servo to get to set position
}
Thank you in advanced
Explanation / Answer
here is your modified code :---------------->>>>>>>>>>
void loop()
{
val = analogRead(1); // reads the value of the potentiometer from A1 (value between 0 and 1023)
//use this code for setting deadZone
float volt = val*(5.0/1023.0);
if(volt < 1.5){
val = 0;
}
val = map(val, 0, 1023, 0, 180); // converts reading from potentiometer to an output value in degrees of rotation that the servo can understand
myservo.write(val); // sets the servo position according to the input from the potentiometer
delay(15); // waits 15ms for the servo to get to set position
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.