Рет қаралды 413
In this video we introduce you to Arduino circuit designing and programming in both Block and Text C++ languages. Please subscribe for more videos like this
Exercise 2: RGB with Arduino
Scenario:
• The red, orange and green LED legs are connected to two pins on the Arduino and pin 13, pin 12 and pin 11 on the anode side, and on the cathode side they are connected to the ground (GND).
• Resistors are put between the LEDs and pin, 13, pin 12 and 11 which helps to limit the current going to the LED to prevent it from burning out.
• The LED of the device is polarized (has a positive(anode) and negative(cathode) side). The anode is wired to power (pin 13) while the cathode is wired to the ground.
• When the circuit is connected, the red LED is turn on for 4 seconds then turn off, then the orange and LEDs are turned on and off through the same process.
• This process will repeat indefinitely.
Components Required:
• Arduino Uno R3 Microcontroller Board
• Red LED
• Orange LED
• Green LED
• Connecting Jumper Wires
• 3 x 220Ω Resistor
• Breadboard
Code in Arduino C++:
int AnimationSpeed = 0;
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
AnimationSpeed = 4;
digitalWrite(13, HIGH);
delay(1000 * AnimationSpeed); // Wait for 1000 * AnimationSpeed millisecond(s)
digitalWrite(13, LOW);
delay(1000 * AnimationSpeed); // Wait for 1000 * AnimationSpeed millisecond(s)
digitalWrite(12, HIGH);
delay(1000 * AnimationSpeed); // Wait for 1000 * AnimationSpeed millisecond(s)
digitalWrite(12, LOW);
delay(1000 * AnimationSpeed); // Wait for 1000 * AnimationSpeed millisecond(s)
digitalWrite(11, HIGH);
delay(1000 * AnimationSpeed); // Wait for 1000 * AnimationSpeed millisecond(s)
digitalWrite(11, LOW);
delay(1000 * AnimationSpeed); // Wait for 1000 * AnimationSpeed millisecond(s)
}
Exercise 3: Analog (Potentiometer) for LED
Scenario:
• The LED legs are connected to two pins on the Arduino which include the ground (GND) and pin 13.
• A resistor is put between the LED and pin 13 which helps to limit the current going to the LED to prevent it from burning out.
• A potentiometer is placed on the circuit, through which its terminal 1 is connected to the 5V power source, Terminal 2 is connected to GND, and the wiper node is connected to analog signal A0.
• A multimeter is connected to the potentiometer to read the whereby the positive side of the multimeter is connected to terminal 1 and the negative side is connected to the wiper node.
• When the circuit is connected, the value of the analog signal will be read from A0 which is controlled by the value of the potentiometer, when the potentiometer is at the closed position the resistance will be at the max hence enabling low current to pass through but when the potentiometer is at the open position the resistance will be at its low hence enabling more current to pass through.
• This process is repeated indefinitely.
Components Required:
• Red LED light
• Connecting Jumper Wires
• 250Ω max Potentiometer
• 220Ω resistor
• Arduino Uno R3 microcontroller
• Breadboard
• Multimeter
Code in Arduino C++:
// C++ code
//
int POT = 0;
int LED = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(6, OUTPUT);
}
void loop()
{
POT = analogRead(A0);
LED = map(POT, 0, 1023, 0, 255);
analogWrite(6, POT);
delay(10); // Delay a little bit to improve simulation performance
}}