logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Arduino

Arduino-Based DIY Electric Skateboard

Rahul Iyer
Published by Rahul Iyer at September 23, 2016
Categories
  • Arduino
Tags
  • Arduino
  • diy
  • electric skateboard
  • electric vehicle
  • skateboard
  • vehicle
DIY electric skateboard
  • Intro & Step 1 – Layout
  • Step 2 – Fabricate Parts
  • Step 3 – Connecting the Electrical Systems
  • Step 4 – Writing and Uploading the Code to the Arduino
  • Conclusion

Step 4 – Writing and Uploading the Code to the Arduino

The final step before the skateboard can be assembled and tested is writing and uploading the control software to the Arduino.  Before you connect your Arduino to your laptop, make sure that it is not powered by the skateboard’s batteries via the BEC.  Connecting the Arduino to your computer’s USB port while it is powered by the BEC can damage either your computer’s USB port, the Arduino, or both!

You can find the Arduino control software that I wrote in the github repository here!  Right now, it is a pretty simple sketch that translates the nunchuck input into a motor speed that is communicated to the ESC.  In the near future, I hope to write better, more advanced versions of this control software to improve the skateboard’s performance.  Tweak and improve the code to your liking and share your improvements with me!

Skateboard Control Arduino Sketch:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*  
      * Rahul Iyer
      */
 
    
      #include <Servo.h>
      #include <Wire.h>
      #include <ArduinoNunchuk.h>
 
 
      #define BAUDRATE 19200
 
 
      #define CHUCK_ZERO 133
      #define CHUCK_MAX 255
      #define ESC_ZERO 90
      #define SPEED_MAX 130
 
      ArduinoNunchuk nunchuk = ArduinoNunchuk();
 
 
      int escOutputValue = ESC_ZERO;
      float currentOutputValue = ESC_ZERO;
 
 
      int resetCounter = 0;
      Servo ESC;
 
 
      void setup()
      {
      ESC.attach(9);
      Serial.begin(BAUDRATE);
 
 
      nunchuk.init();
      delay(100);
      }
 
 
      void loop()
      {
 
      resetCounter++;
 
 
 
      if (resetCounter==40)
      {
         resetCounter=0;
         nunchuk.init();
         delay(100);
      }
 
 
      nunchuk.update();
 
 
      // Serial.print(nunchuk.analogX, DEC);
      // Serial.print(' ');
      // Serial.print(nunchuk.analogY, DEC);
      // Serial.print(' ');
      // Serial.print(nunchuk.accelX, DEC);
      // Serial.print(' ');
      // Serial.print(nunchuk.accelY, DEC);
      // Serial.print(' ');
      // Serial.print(nunchuk.accelZ, DEC);
      // Serial.print(' ');
      // Serial.print(nunchuk.zButton, DEC);
      // Serial.print(' ');
      // Serial.print(nunchuk.cButton, DEC);
      // Serial.print(' ');
 
 
      int yValue = nunchuk.analogY;
 
      if (yValue<CHUCK_ZERO)
      {
         yValue = CHUCK_ZERO; // no backwards
      }
    
      // escOutputValue = map(yValue, CHUCK_ZERO, CHUCK_MAX, ESC_ZERO, SPEED_MAX); //linear relationship between joystick value and ESC output value--deemed not good enough :P
 
      if (yValue == CHUCK_ZERO)
      {
         escOutputValue = ESC_ZERO; //if joystick is at zero, no power to motor (coast)
         currentOutputValue = ESC_ZERO; //reset
      }
      else
      {
         int maxPossibleSpeed = map (yValue, CHUCK_ZERO, CHUCK_MAX, ESC_ZERO, SPEED_MAX);
 
         if (escOutputValue > maxPossibleSpeed)
         {
           escOutputValue = maxPossibleSpeed;
         }
         else
         {
           float increment = (1.0 * (yValue - CHUCK_ZERO)) / (CHUCK_MAX - CHUCK_ZERO);
 
 
 
           currentOutputValue += increment;
           escOutputValue = (int) currentOutputValue;
 
           if (escOutputValue > maxPossibleSpeed)
           {
             escOutputValue = maxPossibleSpeed;
           }
         }
      }
 
 
      ESC.write(escOutputValue);
      Serial.println(escOutputValue); //for debugging
      }

1 2 3 4 5
Rahul Iyer
Rahul Iyer
Studying Electrical Engineering at UCLA, Rahul loves to work on electronics and robotics projects as a hobby. He is especially enthusiastic about electric vehicle technology and assistive robotics.

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • UCLA “AirMouse” using ROHM Sensor Evaluation Kit – Part 2UCLA “AirMouse” using ROHM Sensor Evaluation Kit – Part 2
  • Step By Step Guide To Your First Project With ArduinoStep By Step Guide To Your First Project With Arduino
  • UCLA “AirMouse” using ROHM Sensor Evaluation Kit – Part 1UCLA “AirMouse” using ROHM Sensor Evaluation Kit – Part 1
  • DIY RepRap 3D Printer for Beginners – Part 1: BuildDIY RepRap 3D Printer for Beginners – Part 1: Build
  • How to integrate an RFID module with Raspberry PiHow to integrate an RFID module with Raspberry Pi
  • DIY Tip: How to Set Up Your Raspberry PiDIY Tip: How to Set Up Your Raspberry Pi
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2022. Device Plus - Powered by ROHM
© 2022 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort