Getting to Know Arduino:
Arduino is a convenient, flexible, and easy-to-use open-source electronic prototyping platform. It consists of two parts: the hardware part is the Arduino circuit board used for circuit connections; the other part is the Arduino IDE, which is an application that provides a programming development environment, integrating code writing, analysis, compilation, and other functionalities into a single software.
Arduino can sense the environment through various sensors and can also control lights, motors, and other devices to respond to and influence the environment.
The main character we are discussing is: Arduino UNO R3, let’s first understand the parameters of the Arduino UNO:
Model | Arduino UNO |
Microcontroller | ATmega328P |
Operating Voltage | 5v |
Input Voltage (recommended) | 7v~12v |
Input Voltage (maximum) | 6v~20v |
Digital I/O Pins | 14 |
Analog Input Channels | 6 |
PWM Channels |
6 |
DC Output Capability per I/O | 20 mA |
3.3v Pin | 50 mA |
Clock Frequency | 16 MHz |
Flash Memory | 32 KB (0.5KB used by bootloader) |
SRAM | 2 KB |
EEPROM | 1 KB |
This is an Arduino development board based on ATmega328P, with an operating voltage of 5v, a recommended input voltage of 7~12v, and a maximum input voltage of 6~20v. It has 14 input/output pins, 6 analog input pins, a 16 MHz crystal oscillator, a reset button, an ICSP interface, a USB interface, and a DC interface.
1. Learning Objectives
1. Understand Arduino UNO
2. Learn how to light up the LED on the Arduino Uno main board.
2. Hardware Setup
Use the pins on the Arduino Uno main board directly.
3. Functions
-
void setup() Initializes variables, pin modes, and calls library functions, etc.
-
void loop() Continuously executes statements within the function.
-
pinMode(pin, mode) Defines the input/output mode for digital I/O pins, where pin ranges from 0 to 13, and mode is either INPUT or OUTPUT.
-
digitalWrite(pin, value) Defines the output level for digital I/O pins, where pin ranges from 0 to 13, and value is either HIGH or LOW. For example, defining HIGH can drive an LED.
-
delay(ms) Delay function (in ms).
-
analogWrite(pin, value) – PWM digital I/O pin PWM output function. The Arduino digital I/O pins marked with PWM can use this function, where pin is 3, 5, 6, 9, 10, 11, and value ranges from 0 to 255. For example, it can be used for motor PWM speed control or music playback.
4. Code
Function: Make the LED on pin 13 blink.
int ledPin = 13; // Set the control LED digital I/O pinvoid setup(){pinMode(ledPin, OUTPUT); // Set the digital I/O pin mode to OUTPUT}void loop(){digitalWrite(ledPin, HIGH); // Set pin 13 to HIGH = 4Vdelay(1000); // Set delay time, 1000 = 1 seconddigitalWrite(ledPin, LOW); // Set pin 13 to LOW = 0Vdelay(1000); // Set delay time}
Function: PWM makes the LED on pin 11 gradually brighten and dim.
int ledPin = 11; // Set the control LED digital I/O pinint val; // Define a variablevoid setup(){pinMode(ledPin, OUTPUT); // Set the digital I/O pin mode to OUTPUT}void loop(){for(val=0;val<255;val++) // Variable loop +1{analogWrite(ledPin, val); // PWM outputdelay(50); // Set delay time}for(val=255;val>0;val--) // Variable loop -1{analogWrite(ledPin, val);delay(50);}}
—————————
WeChat Official Account: Evergreen Maker
If you like Evergreen Maker, we hope you can share this article with your friends so that more friends can get to know us. Your every encouragement and support are the greatest encouragement and support for us.
Thank you~~
Leave a Comment
Your email address will not be published. Required fields are marked *