Explanation
An Arduino program, called a sketch, has two mandatory functions. setup() runs once after power-on and specifies, for example, which pins are inputs or outputs. loop() then runs in an endless loop: read inputs, decide, switch outputs. Basic commands are pinMode(), digitalWrite() and digitalRead() for digital signals, analogRead() for analogue voltages and analogWrite() for a pulse-width modulated signal.
The logic voltage matters for the build. Classic Arduino boards work with 5 V, many newer ones with 3.3 V. The Arduino Nano 33 IoT is a 3.3 V board; according to its data sheet its pins are not 5 V tolerant. A microcontroller pin supplies only a few milliamps. Motors, relays or larger loads therefore always need a driver stage such as a transistor or a motor driver.
The Nano 33 IoT also has a Wi-Fi and Bluetooth module. It can therefore join a network or create its own network through which a smartphone controls it.
In practice: Design & Make – Mecanum rover, Control and programming (Arduino Nano 33 IoT)
In the Mecanum rover from the Design & Make workshop an Arduino Nano 33 IoT controls two L293D motor drivers and thus four motors via twelve signal lines. The rover is operated via the Arduino Cloud or via its own Wi-Fi access point with a virtual joystick in the smartphone browser. The project data require a safety watchdog: if no drive command arrives for 500 ms, all motors switch off.
To the training project Design & Make – Mecanum rover
Common mistakes
- Connecting a motor directly to a pin. The pin is overloaded and can be destroyed.
- Applying 5 V signals to a 3.3 V board.
- No common ground between microcontroller and driver. The control signals then have no reference.
- Running a radio-controlled vehicle without a watchdog. If the connection drops it carries on with the last command.