SHARE
TWEET

Arduino ESC control with servo library

FatherOfElectronics Jul 18th, 2019 (edited) 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ESC control using servo library
  2. //
  3. // ESC connector black wire -> Arduino GND
  4. // ESC connector red wire -> Arduino 5V
  5. // ESC connector white/yellow wire -> Arduino pin defined below
  6.  
  7. // Include servo library
  8. #include <Servo.h>
  9.  
  10. // Define new instance of servo library
  11. Servo ESC;
  12.  
  13. // Define pinout
  14. const int ESC_PIN = 2;
  15.  
  16. // Define min. & max. HIGH-time (usually 1000us and
  17. // 2000us, but some ESCs might work over a greater
  18. // range so change as needed)
  19. const int minOnTime = 1000;
  20. const int maxOnTime = 2000;
  21.  
  22. // Create variable for rpm set point in % (may be
  23. // changed at any time in your program to match your
  24. // desired rpm)
  25. float rpmPercentage = 100;
  26.  
  27. void setup()
  28. {
  29.   // Set ESC output pin
  30.   ESC.attach(ESC_PIN);
  31. }
  32.  
  33. void loop()
  34. {
  35.   // Calculate HIGH-time for given rpm
  36.   int onTime = map(rpm, 0, 100, minOnTime, maxOnTime);
  37.  
  38.   // Set ESC signal
  39.   ESC.writeMicroseconds(onTime);
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top