Experiment of controlling the moving direction and the speed of the 4-wheel smart car

Experiment of controlling the moving direction and the speed of the 4-wheel smart car

In this article we will explain how to control the 4-wheel smart car to go forward and backward, turn left and right. We can refer to the manual https://www.adeept.com/learn/detail-4.html to connect the wiring of the car.

After connecting according to the picture above, insert two 18650 batteries. Download the following code to UNO. Click AdeeptMotor to download the code.

/***********************************************************
File name:  AdeeptMotor.ino
Description:  

Website: www.adeept.com
E-mail: support@adeept.com
Author: Tom
Date: 2019/03/04 
***********************************************************/
#include <Servo.h>

Servo dirServo;                   // define servo to control turning of smart car
int dirServoPin = 2;              // define pin for signal line of the last servo
float dirServoOffset = 0;         // define a variable for deviation(degree) of the servo
int dirServoDegree;

const int dirAPin = 7;    // define pin used to control rotational direction of motor A
const int pwmAPin = 6;    // define pin for PWM used to control rotational speed of motor A
const int dirBPin = 4;    // define pin used to control rotational direction of motor B
const int pwmBPin = 5;    // define pin for PWM used to control rotational speed of motor B

#define FORWARD HIGH
#define BACKWARD LOW

void setup() {
  dirServo.attach(dirServoPin);  // attaches the servo on servoDirPin to the servo object
  pinMode(dirAPin, OUTPUT);   // set dirAPin to output mode
  pinMode(pwmAPin, OUTPUT);   // set pwmAPin to output mode
  pinMode(dirBPin, OUTPUT);   // set dirBPin to output mode
  pinMode(pwmBPin, OUTPUT);   // set pwmBPin to output mode
}
void loop()
{
      dirServoDegree = 90; 
      int motorSpd = 200;
      bool motorDir = motorSpd > 0 ? FORWARD : BACKWARD;
      motorSpd = abs(constrain(motorSpd, -512, 512));
      motorSpd = map(motorSpd, 0, 512, 0, 255);
      // control the steering and travelling of the smart car
      ctrlCar1(dirServoDegree,motorDir, motorSpd); 
}
void ctrlCar1(byte dirServoDegree, bool motorDir, byte motorSpd) {
  dirServo.write(dirServoDegree + dirServoOffset);
  digitalWrite(dirAPin, motorDir);
  digitalWrite(dirBPin, motorDir);
  analogWrite(pwmAPin, motorSpd);
  analogWrite(pwmBPin, motorSpd);
}

Now we give you the explanation of the code.

  1. To control the servo of the car, you need to use the servo control function. Add the header file of the servo control function at the beginning of the code.
#include <Servo.h>

After adding the header file, you need to set which port of the UNO the servo is connected to and the servo angle, the code is as follows:

Servo dirServo;                   // define servo to control turning of smart car
int dirServoPin = 2;              // define pin for signal line of the last servo
float dirServoOffset = 0;         // define a variable for deviation(degree) of the servo
int dirServoDegree;

Next we need to add the function of the initialization configuration in the function initialization (setup()), as follows:

dirServo.attach(dirServoPin);  // attaches the servo on servoDirPin to the servo object

Then modify the value of dirServoDegree in the loop() function to control the motion direction of the servo. The input range of dirServoDegree is 0~180.

dirServoDegree = 90;

Finally, we add the following function to “ctrlCar1”.

dirServo.write(dirServoDegree + dirServoOffset);

Then we can control the rotation angle of the servo.

  1. Control the speed at which the car moves forward and backward. First we need to define the port where UNO controls the operation of the motor. The definition function is as follows:
const int dirAPin = 7;    // define pin used to control rotational direction of motor A
const int pwmAPin = 6;    // define pin for PWM used to control rotational speed of motor A
const int dirBPin = 4;    // define pin used to control rotational direction of motor B
const int pwmBPin = 5;    // define pin for PWM used to control rotational speed of motor B

Next add the function of initialization configuration in the initialization function (setup()).

 pinMode(dirAPin, OUTPUT);   // set dirAPin to output mode
  pinMode(pwmAPin, OUTPUT);   // set pwmAPin to output mode
  pinMode(dirBPin, OUTPUT);   // set dirBPin to output mode
  pinMode(pwmBPin, OUTPUT);   // set pwmBPin to output mode

Then we can modify motorSpd to control the speed and direction of the car. The input range of this function is -512 to 512. When the speed value is negative, the car goes backward, and when the speed value is positive, the car goes forward.

     int motorSpd = 200;
      bool motorDir = motorSpd > 0 ? FORWARD : BACKWARD;
      motorSpd = abs(constrain(motorSpd, -512, 512));
      motorSpd = map(motorSpd, 0, 512, 0, 255);
      // control the steering and travelling of the smart car
      ctrlCar1(dirServoDegree,motorDir, motorSpd);

1,096 Replies to “Experiment of controlling the moving direction and the speed of the 4-wheel smart car”

  1. Pingback: app club games
  2. Pingback: register joker123
  3. Pingback: what is blockchain
  4. Pingback: bitcoin to dollar
  5. Pingback: robotics examples
  6. Pingback: joker123 website
  7. Pingback: televicentro
  8. Pingback: toto casino
  9. Pingback: login dewapoker99
  10. Pingback: bandarq pkv
  11. Pingback: voc filter meaning
  12. Pingback: bandar sakong
  13. Pingback: pm 2.5 map
  14. Pingback: mariobola
  15. Pingback: sarms supplement
  16. Pingback: cnc wood router
  17. Pingback: scbet88
  18. Pingback: pusatqq
  19. Pingback: rajawaliqq
  20. Pingback: langitqq
  21. Pingback: sports newscricket
  22. Pingback: nile cruises 2021
  23. Pingback: live stream
  24. Pingback: live stream
  25. Pingback: live sports tv
  26. Pingback: lottoland
  27. Pingback: 1xbet casino
  28. Pingback: lk21 website
  29. Pingback: snooze off meaning
  30. Pingback: bandarqq365
  31. Pingback: bandarqq88
  32. Pingback: smart iptv premium
  33. Pingback: white runtz
  34. Pingback: movie prop money
  35. Pingback: glock 19 gen 5
  36. Pingback: air purifier argos
  37. Pingback: air cleaner
  38. Pingback: online casino
  39. Pingback: adq digital bank
  40. Pingback: freebet number
  41. Pingback: glide design
  42. Pingback: youtube views free
  43. Pingback: glock 19 holster
  44. Pingback: mann filter india
  45. Pingback: airfilterusa
  46. Pingback: honey extension
  47. Pingback: Feedback
  48. Pingback: best iptv app 2021
  49. Pingback: iowa ask a lawyer
  50. Pingback: Follow This
  51. Pingback: new homes for sale
  52. Pingback: gambling sites
  53. Pingback: best rv for sale
  54. Pingback: toto india
  55. Pingback: get it now}
  56. Pingback: bet88 login
  57. Pingback: free goats near me
  58. Pingback: Get it here
  59. Pingback: file manager
  60. Pingback: product branding
  61. Pingback: shibori tie dye
  62. Pingback: bet soccer team
  63. Pingback: Get IT Support
  64. Pingback: get clean air
  65. Pingback: check out this
  66. Pingback: situs judi kartu
  67. Pingback: find now
  68. Pingback: crowdfund republic
  69. Pingback: airfree tulip 80
  70. Pingback: www u16822
  71. Pingback: nifty's nft
  72. Pingback: idn texas poker
  73. Pingback: bigsloto
  74. Pingback: poker online
  75. Pingback: search anything
  76. Pingback: w88 malaysia
  77. Pingback: prop money near me
  78. Pingback: vlone runtz strain
  79. Pingback: Read more
  80. Pingback: auto pg slot
  81. Pingback: lava slot 888
  82. Pingback: sports369 togel
  83. Pingback: benefits of weeds
  84. Pingback: buy wow gold
  85. Pingback: bet88 login
  86. Pingback: judi bola
  87. Pingback: sbobetasia wap
  88. Pingback: Read it
  89. Pingback: free online tools
  90. Pingback: bulk sms marketing
  91. Pingback: viagra 100
  92. Pingback: kamagra 100mg
  93. Pingback: More Info
  94. Pingback: sbobet makati
  95. Pingback: pg slot myanmar
  96. Pingback: gd lotto app
  97. Pingback: pasaran hk pools
  98. Pingback: slot jokerbet303
  99. Pingback: joker123 download
  100. Pingback: mmojugg
  101. Pingback: bonus bursa303
  102. Pingback: sa gaming88
  103. Pingback: slot online free
  104. Pingback: celebrity bakery
  105. Pingback: fafa855 slot
  106. Here at Leslie’s Pugsland Breeder, Our beautiful fawn pug has given birth to 4 healthy Pug puppies.
    She is our beloved family dog and this is her 1st litter.
    Both mum and dad are AKC registered with 5 gen pedigree certificate. Both from Top Champion bloodlines.Mum and Dad can be seen. Puppies have been wormed weeks 2,4,6,8 and will have had a flea preventative treatment before leaving us.
    They will have their vet check, 1st vaccinations and microchip.
    To view all available puppies and recent pictures, Search us in google as LESLIE’S PUGSLAND BREEDER or click on our website link bellow : https://pugslandbreeder.company.com/

    Pug Puppies for sale | pug for sale near me | pug puppy for sale | pug puppy | pug for sale | pug puppies for sale in va | black pug puppies for sale

  107. Pingback: pokercc77
  108. Pingback: pokercc asia
  109. Pingback: sa gaming login
  110. Pingback: domino qiu qiu apk
  111. Pingback: k2researchchems
  112. Pingback: judi slot booming
  113. Pingback: Oxycodone pills
  114. Pingback: pkv games
  115. Pingback: sbobet register
  116. Pingback: Shop It
  117. Pingback: download pkv games
  118. Pingback: olansi group
  119. Pingback: sports news
  120. Pingback: olansi alibaba
  121. Pingback: oem air purifier
  122. Pingback: oem air purifier
  123. Pingback: k08 air purifier
  124. Pingback: cadr 600
  125. Pingback: k08 air purifier
  126. Pingback: buy goat online
  127. Pingback: Find goats here
  128. Pingback: Visit Here
  129. Pingback: best nepal tour
  130. Pingback: glock 19 gen 5
  131. Pingback: bitcoin price
  132. Pingback: Buy Crystal Meth
  133. Pingback: china mold makers
  134. Pingback: givegab login
  135. Pingback: situs judi
  136. Pingback: Read More
  137. Pingback: beer777 sbobet
  138. Pingback: olansi group
  139. Pingback: pkv judi qq
  140. Pingback: nurse prose review
  141. Pingback: olansi global
  142. Pingback: olansi group
  143. Pingback: cadr 600
  144. Pingback: cadr 600
  145. Pingback: olansi group
  146. Pingback: olansi alibaba
  147. Pingback: k08 air purifier
  148. Pingback: olansi group
  149. Pingback: Judi Poker Online
  150. Pingback: pomeranian white
  151. Pingback: olansi global
  152. Pingback: olansi group
  153. Pingback: ip camera viewer
  154. Pingback: goat buy online
  155. Pingback: prop money near me
  156. Pingback: k08 air purifier
  157. Pingback: kiukiu
  158. Pingback: real pink runtz
  159. Pingback: olansi k08a
  160. Pingback: croma air purifier
  161. Pingback: oem air purifier
  162. Pingback: vintage kilim rugs
  163. Pingback: pubg diamond hack
  164. Pingback: gift items online
  165. Pingback: cavapoo full grown
  166. Pingback: olansi k08a
  167. Pingback: jeremy hughes hsbc
  168. Pingback: what is nembutal
  169. Pingback: nembutal canada
  170. Pingback: floor marking tape
  171. Pingback: Go to This Website
  172. Pingback: Taylan Evrenler
  173. Pingback: bloom vape battery
  174. Pingback: daftar slot online
  175. Pingback: singapore pools
  176. Pingback: Visit Here
  177. Pingback: Skin Care Products
  178. Pingback: sollift machine
  179. Pingback: today news bihar
  180. Pingback: ceriabet
  181. Pingback: here wee read
  182. Pingback: Golf cart battery
  183. Pingback: cbd oil uses
  184. Pingback: webm to.mp4 api
  185. Pingback: photo funny love
  186. Pingback: bvlgari ring price
  187. Pingback: off white edibles
  188. Pingback: cbd oil
  189. Pingback: royal funny status
  190. Pingback: screw kit for pc
  191. Pingback: cam lock screws
  192. Pingback: self locking screw
  193. Pingback: world globe price
  194. Pingback: world globe price
  195. Pingback: ev battery cell
  196. Pingback: cheese price
  197. Pingback: best online casino
  198. Pingback: online casino
  199. Pingback: cbd products
  200. Pingback: dominoqq apk
  201. Pingback: howto site
  202. Pingback: 100% free essays
  203. Pingback: click here#
  204. Pingback: ev12-180x battery
  205. Pingback: write articles
  206. Pingback: media files
  207. Pingback: mp4 converter
  208. Pingback: mp3 converter app
  209. Pingback: pepperfry
  210. Pingback: sot gambling site
  211. Pingback: virtual visa card
  212. Pingback: vaping aerosol
  213. Pingback: layar kaca 21
  214. Pingback: cassino online
  215. Pingback: live casino online
  216. Pingback: judi bola 88
  217. Pingback: gout definition
  218. Pingback: get scholarship
  219. Pingback: 888 casino
  220. Pingback: Buy Oxycodone
  221. Pingback: dog care website
  222. Pingback: sheet mask at home
  223. Pingback: poker stars
  224. Pingback: sheet mask online
  225. Pingback: list of anime
  226. Pingback: buy osrs gold safe
  227. Pingback: sofradom
  228. Pingback: anime tv
  229. Pingback: dark web login
  230. Pingback: goa casino online
  231. Pingback: Find food for pet
  232. Pingback: buy dog supplies
  233. Pingback: lightsaber toy
  234. Pingback: ffp2 mask amazon
  235. Pingback: best pet food
  236. Pingback: pyrenees spain
  237. Pingback: lip balm himalaya
  238. Pingback: home cash app
  239. Pingback: dark web browser
  240. Pingback: healthy food
  241. Pingback: dewa4dku
  242. Pingback: pandora188
  243. Pingback: win88
  244. Pingback: Microswitch
  245. Pingback: mini-limit switch
  246. Pingback: PREMIUM CBD OIL
  247. Pingback: Testing57
  248. Pingback: Testing56
  249. Pingback: Testing 55
  250. Pingback: Zastave Arms CZ999
  251. Pingback: sahabatpoker
  252. Pingback: hondaqq
  253. Pingback: official site
  254. Pingback: tutoring online
  255. Pingback: homework helper
  256. Pingback: THC Carts for sale
  257. Pingback: buy DMT
  258. Pingback: Dylan Sellers
  259. Pingback: tor web pages
  260. Pingback: click here
  261. Pingback: care credit
  262. Pingback: sex toys
  263. Pingback: m88 bi chan
  264. Pingback: mansion88
  265. Pingback: lesbian strapon
  266. Pingback: keluaran hk pools
  267. Pingback: rajapoker88
  268. Pingback: DotNek Tech Blog
  269. Pingback: CBD Spray
  270. Pingback: 21 dukes
  271. Pingback: bitcoin price
  272. Pingback: debian vpn
  273. Pingback: togel seoul
  274. Pingback: ufabet
  275. Pingback: more
  276. Pingback: Car Rental Deals
  277. Pingback: seo cambridge
  278. Pingback: Nagad
  279. Pingback: verlobungsring
  280. Pingback: gclub
  281. Pingback: 먹튀검증
  282. Pingback: gclub

Leave a Reply