DS smart WiFi robot car with Arduino

Arduino IDE basic usage tutorial

I . Arduino IDE interface introduction

  1. Introduction ofthe main interface

First, after opening arduino.exe, the main interface appears, with the following comments:

2. Arduino IDE basic usage tutorial

3. Edit menu

4. Introduction ofSketch Project Men

5. Tools introduction

II . Newly built project (an onboard LED as an example)

1. Hardware Introduction

The Arduino UNO R3 motherboard comes with a SMD LED light, which is connected to pin 13. We can control the LED on and off by controlling the level state on pin 13.

2. Arduino IDE parameter settings

Connect the Arduino UNO R3 motherboard to the USB port of the computer through the blue download cable. After installing the driver, you can see the corresponding COM slogan. After opening the IDE Arduino.exe, you need to set the corresponding parameters, as follows:

A. Tools→Board → arduino uno          Here is the motherboard setting

B. Tools → Port → COM slogan          Here is the COM slogan assigned by the computer to the motherboard

3. Arduino code writing

Note:  You need to use English input method when you are writing code, especially when outputting symbols. IDE does not recognize Chinese characters.

But the content of the comment can be used in Chinese, because it does not participate in the compilation process. Two // are comment characters.

A. Pin definition, define LED as pin 13;

B. Setup initialization, define LED pin as output mode, and it is high level state when booting.

 The content of the Setup function is the code to be executed first after the motherboard is started, and it is executed once in series.

C. Loop function, set the LED pin to high, set the LED pin to low after 0.5s, and then delay 1s.

The Loop function is the code executed in a loop after the initialization of setup is executed.

int led=13; //LED pin definition

D. The code content and screenshots are as follows:

int led=13; //LED pin definition

void setup() {

// put your setup code here, to run once:

pinMode(led,OUTPUT);       //Set LED to output mode

digitalWrite(led,HIGH):     //Initially set the LED pin to high level

}

void loop() {

//put your main code here, to run repeatedly:

digitalWrite(led, HIGH);     //Initially set the led pin to high

delay(500);                 //Wait for 1000 milliseconds

digitalWrite(led, LOW);     //Initially set the LED pin to high level

delay(1000);                 //Wait for 2000 milliseconds

}

4. File save

The Arduino IDE requires files must to be placed in a same name folder in order to compile. We save the file as LED, it will automatically create a folder named LED, and save the code file in it.

The steps are :  File→ Save As → Desktop → LED

At this time, there is an LED folder on the desktop, as shown in the screenshot below:

5. Program compilation and upload

After setting the motherboard parameters in step 2.2, you can directly compile and upload by clicking the upload button.

PS: It will compile first and then upload when you click upload. If you just want to verify whether the code is wrong, you can just click compile.

After the upload is successful, the status bar will display "Upload Successful", as shown in the figure below. If you encounter upload failure, you can troubleshoot from the following aspects:

    A. The motherboard model and COM port selection is wrong. Re-upload according to the correct motherboard model and port number settings; 

    B. The code is wrong and the compilation fails. Modify it according to the error prompt (usually use the Chinese input method to input ";") and upload again;

    C. The serial port is occupied (such as the status of the whole vehicle, the wifi data cable is connected and not unplugged), causing the data abnormalities and unable to upload normally. Unplug the wifi data cable and upload again.

6. Motherboard operation and program operation logic

After uploading this program, the corresponding LED on the main board will be off for 0.5s, and then on for 1s, and keep cycling.

The program runs strictly in accordance with the logical sequence of the code, including state changes and state duration. According to the existing code:

digitalWrite(led, HIGH);

Just change the pin corresponding to the led to high level, this time is very short, basically one machine cycle time is completed. If the state of this pin is not changed next, it will always keep high, which the LED is the off state. If we want the LED to be off for 0.5s, we need to add a demonstration function and then change the state:

delay(500);

Delay 500ms, the unit of the number in the delay function is ms, 1s=1000ms.

digitalWrite(led, LOW);

Change the LED pin status to low level, that is, the LED is on.

delay(1000);

The delay is 1000ms. Why do I need to add a 1000ms here? Some students said that if the state is changed at the end of the program, can it be enough? I just mentioned that the time to execute an instruction is instantaneous, while the loop function is executed in a loop. If there is no the 1s delay function, after executing the LED low, the first one is executed instantly, the LED is high, and the low level state cannot be observed.

Official website:www.xiaorgeek.com

Forum:www.wifi-robots.com

Official mall:wifi-robot.taobao.com

WeChat public account:

ArduinoHow to make robot car

Leave a comment

All comments are moderated before being published