1. Bluetooth Controlled Car


This  chapter contains different approaches how to program a bluetooth controlled car.

For more info regarding the different components used and how to program them:

Problems encountered:

  1. Ultrasonic sensor randomly gives a low reading (in our case exactly the value 3).
  2. Motors drain a large amount of current from the batteries.
  3. Bluetooth messaging causes jittering in the servo motor.
  4. Integers go below the minimum value, underflowing to the maximum value.
  5. Calling a function recursively too many times makes the call stack too big, which crashes the Arduino.
  6. The loop taking too long triggers the Watchdog Timeout interrupt, which resets the Arduino.
  7. The servo doesn't have enough time to move and take measurements before it has to move again.

Solutions:

  1. Calculate a running average on the ultrasonic sensor readings and/or discard outliers to get more correct results.
  2. Use a fitting power source, e.g rechargeable batteries or a power bank. Also try not to change from one direction to another instantly. Doing so wastes a lot of power.
  3. Detach the servo motor when it's not in use. This will solve interference with the SoftwareSerial library used for bluetooth.
  4. Make sure you use fitting data types for your variables, e.g not unsigned if the value can be negative.
  5. Don't make recursive calls that can loop many times. Depending on the size of your program, the Arduino might crash after only a few recursive calls.
  6. Call the yield() function to allow the micro controllers background functions to run if you have a long blocking function. This will also reset the watchdog timer.
  7. Give a sufficient delay after each servo move so it has enough time to reach its end position.