SunFounder 3in1 Kit
(continued from previous page)
moveBackward();
delay(2000);
stopMove();
delay(500);
...
• digitalWrite(pin, value)
– pin: the Arduino pin number.
– value: HIGH or LOW.
Write a HIGH or a LOW value to a digital pin. If the pin has been configured as an OUTPUT with
pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for
HIGH, 0V (ground) for LOW.
• pinMode(pin, mode)
– pin: the Arduino pin number to set the mode of.
– mode: INPUT, OUTPUT, or INPUT_PULLUP.
Configures the specified pin to behave either as an input or an output.
• delay(ms)
– ms: the number of milliseconds to pause. Allowed data types: unsigned long.
Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000
milliseconds in a second.)
5.4 3. Speed Up
In addition to the digital signal (HIGH/LOW), the input of L9110 module can also receive PWM signal to control the
speed of the output.
In other words, we can use AnalogWrite() to control the moving speed of the car.
In this project, we let the car gradually change its forward speed, first accelerating and then decelerating.
Wiring
This project is the same wiring as 2. Move by Code.
Code
Note:
• Open the 3.speed_up.ino file under the path of 3in1-kit\car_project\3.speed_up.
• Or copy this code into Arduino IDE.
• Or upload the code through the Arduino Web Editor.
After the program runs, the car will gradually accelerate and then gradually decelerate.
How it works?
The purpose of this project is to write different PWM values to the input pins of the L9110 module to control the
forward speed of the car.
238 Chapter 5. Car Projects