Project Examples
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:
- Ultrasonic sensor randomly gives a low reading (in our case exactly the value 3).
- Motors drain a large amount of current from the batteries.
- Bluetooth messaging causes jittering in the servo motor.
- Integers go below the minimum value, underflowing to the maximum value.
- Calling a function recursively too many times makes the call stack too big, which crashes the Arduino.
- The loop taking too long triggers the Watchdog Timeout interrupt, which resets the Arduino.
- The servo doesn't have enough time to move and take measurements before it has to move again.
Solutions:
- Calculate a running average on the ultrasonic sensor readings and/or discard outliers to get more correct results.
- 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.
- Detach the servo motor when it's not in use. This will solve interference with the SoftwareSerial library used for bluetooth.
- Make sure you use fitting data types for your variables, e.g not unsigned if the value can be negative.
- 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.
- 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.
- Give a sufficient delay after each servo move so it has enough time to reach its end position.