Education

Education

Arduino

What is Arduino

Imagine you have a tiny robot friend that listens to your instructions. That’s kind of like what an Arduino is!

Arduino is a small computer. It has a little brain (called a microcontroller) that can think and do tasks for you.

You write simple instructions (like a list of steps) and upload them to the Arduino. When you power it on, it follows your instructions exactly!

How It Works

  • Inputs and Outputs:
    Think of inputs like buttons, sensors, or even a little microphone. They tell the Arduino, "Hey, something happened!"
    Outputs are things like lights, buzzers, or motors. The Arduino tells them what to do like turning on a light or making a sound.

  • Making Things Happen:
    For example, you could tell your Arduino to:

    • Turn on a light when you press a button.

    • Make a buzzer beep when it hears a clap.

    • Spin a motor when it gets a signal from a sensor.

Why Is It Cool?

  • Build Fun Projects:
    You can use Arduino to build cool projects like a dancing robot, a simple game, or even a weather station to measure temperature!

  • Learn by Doing:
    With Arduino, you learn how electronics work, how to program, and how to bring your ideas to life, just like building with LEGO blocks but with lights, sounds, and movements.

  • Easy to Use:
    Even though it’s like a mini computer, Arduino uses simple commands. It’s designed so that kids and beginners can create amazing things without needing to be an expert.

In Short, Arduino is your little helper that listens to your ideas and makes them happen with lights, sounds, and motion. It’s like having a magic box that turns your cool thoughts into real-world projects!

How to connect Arduino and turn on Yellow Tyro Board

Components of Arduino

1. The LEDs

  • What They Are:
    Little lights that turn on when the board is powered up.

  • What They Do:
    They tell you, "Hey, I’m awake!" Sometimes one LED might blink when the board is sending or receiving messages.

2. The Button (Reset Button)

  • What It Is:
    A tiny button you can press on the board.

  • What It Does:
    It restarts the Arduino Nano—like rebooting a computer when you need a fresh start.

3. The Chip

  • What It Is:
    The microcontroller chip (usually an ATmega328) is the brain of the Nano.

  • What It Does:
    It listens to the instructions (code) you write and tells the board what to do—like turning on an LED or making sounds.

4. The USB Socket

  • What It Is:
    A small port where you plug in a USB cable.

  • What It Does:
    It connects your Arduino Nano to your computer. This lets you send your code to the Nano and sometimes even powers it.

Here's How the Pins Work

  • Digital Pins (labeled with D):
    These are like simple on/off switches. When you tell a digital pin to turn on, it gives power to something (like lighting up an LED). When it’s off, nothing happens.

  • Analog Pins (labeled with A):
    These pins can read different amounts of power. Imagine a volume knob that can be turned up or down; analog pins can sense changes in things like light or temperature.

  • Power Pins:
    These pins give your Arduino power (like 5V or 3.3V) or help you connect the board to the ground (GND). They are like the battery and the plug of the board.

Code Breakdown

Welcome to the magical world of the Yellow Tyro board! Think of this board as a clever robot that comes to life with its secret recipe called code. Every single line in this recipe is like a tiny instruction or a special step on a treasure map. The very first line might be the command that wakes the board up, while the next few lines tell it how to blink its lights, make funny sounds, or even decide what to do when you press a button. As you explore the code line by line, you’ll discover how these little instructions work together—just like pieces of a puzzle—to create something truly amazing. Get ready for an adventure where learning about code is as fun as uncovering hidden treasures!

/*
  ------------------------------------------------------------
                         JumpLabs®
  Follow us on Instagram: jumplabs.co
             LinkedIn: JumpLabs
  "Bringing Families Closer!"
  
  This code blinks the on-board LED every second.
  ------------------------------------------------------------
*/
// Pin definitions
const int ledPins[5] = {3, 4, 5, 6, 7};   // 5 LEDs that will be on continuously
const int buzzerPin = 8;                  // Buzzer control pin
const int motorForwardPin = 9;            // Motor forward direction pin
const int motorReversePin = 10;           // Motor reverse direction pin

// Switch inputs (using internal pull-ups; active LOW when pressed)
const int motorSwitchPin = A0;            // Motor switch now reads from A0
const int buzzerSwitchPin = A1;           // Buzzer switch now reads from A1

// Motor state: 0 = forward, 1 = reverse
int motorState = 0;

void setup() {
  // Set up LED pins as outputs
  for (int i = 0; i < 5; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
  
  // Set up buzzer and motor control pins as outputs
  pinMode(buzzerPin, OUTPUT);
  pinMode(motorForwardPin, OUTPUT);
  pinMode(motorReversePin, OUTPUT);
  
  // Set up switch pins as inputs with pull-up resistors
  pinMode(buzzerSwitchPin, INPUT_PULLUP);
  pinMode(motorSwitchPin, INPUT_PULLUP);
  
  // Initialize outputs (ensure buzzer and motor are off)
  digitalWrite(buzzerPin, LOW);
  digitalWrite(motorForwardPin, LOW);
  digitalWrite(motorReversePin, LOW);
}

void loop() {
  // Turn on all 5 LEDs continuously
  for (int i = 0; i < 5; i++) {
    digitalWrite(ledPins[i], HIGH);
  }
  
  // Buzzer: When its switch (A1) is pressed (reads LOW), beep the buzzer.
  if (digitalRead(buzzerSwitchPin) == LOW) {
    digitalWrite(buzzerPin, HIGH);  // Turn buzzer on
    delay(100);                     // Buzzer on for 100 ms
    digitalWrite(buzzerPin, LOW);   // Turn buzzer off
    delay(200);                     // Debounce delay
  }
  
  // Motor: When its switch (A0) is pressed (reads LOW), toggle motor direction.
  if (digitalRead(motorSwitchPin) == LOW) {
    if (motorState == 0) {
      // Run motor in forward direction for 2 seconds
      digitalWrite(motorForwardPin, HIGH);
      digitalWrite(motorReversePin, LOW);
      delay(2000);
      motorState = 1;  // Toggle for next press
    } else {
      // Run motor in reverse direction for 2 seconds
      digitalWrite(motorForwardPin, LOW);
      digitalWrite(motorReversePin, HIGH);
      delay(2000);
      motorState = 0;  // Toggle for next press
    }
    // Stop the motor after the run period
    digitalWrite(motorForwardPin, LOW);
    digitalWrite(motorReversePin, LOW);
    delay(300);  // Debounce delay for the motor switch
  }
  
  delay(50);  // Short delay to help with overall debouncing
}

Let's learn the line by line interpretition of our code!

const int ledPins[5] = {3, 4, 5, 6, 7};   // 5 LEDs that will be on continuously

We create a list of 5 numbers (3, 4, 5, 6, 7) for the pins that control 5 little lights (LEDs). These lights will always be turned on.

const int buzzerPin = 8;                  // Buzzer control pin

We say that pin number 8 is for the buzzer, which makes a beeping sound.

const int motorForwardPin = 9;            // Motor forward direction pin
const int motorReversePin = 10;           // Motor reverse direction pin

Pin 9 and pin 10 are for the motor. Pin 9 makes the motor turn forward, and pin 10 makes it turn backward.

const int motorSwitchPin = A0;            // Motor switch now reads from A0
const int buzzerSwitchPin = A1;           // Buzzer switch now reads from A1

The motor switch (button) is connected to analog pin A0 and the buzzer switch (button) is on A1.

// Motor state: 0 = forward, 1 = reverse
int motorState = 0

We create a little memory box called motorState that remembers if the motor should go forward (0) or reverse (1). It starts at 0, so the first time, the motor will go forward.

void setup() {

The setup() part is like the “get ready” stage. It runs one time when the robot (Arduino) is turned on.

  // Set up LED pins as outputs
  for (int i = 0; i < 5; i++) {
    pinMode(ledPins[i], OUTPUT);
  }

Here, we tell the Arduino that the pins for the LEDs (3, 4, 5, 6, 7) are “outputs” – this means the Arduino can send signals (like turning the lights on). We do this for each of the 5 LED pins using a loop (like doing the same thing 5 times).

  // Set up buzzer and motor control pins as outputs
  pinMode(buzzerPin, OUTPUT);
  pinMode(motorForwardPin, OUTPUT);
  pinMode(motorReversePin, OUTPUT)

Now we tell the Arduino that the pins for the buzzer (8) and the motor (9 and 10) are also outputs, so the Arduino can control them.

  // Set up switch pins as inputs with pull-up resistors
  pinMode(buzzerSwitchPin, INPUT_PULLUP);
  pinMode(motorSwitchPin, INPUT_PULLUP)

Here we tell the Arduino that the button pins (A1 for the buzzer and A0 for the motor) are “inputs”. With INPUT_PULLUP, it means these pins are normally HIGH (like a light on) until you press the button, which then makes them LOW (like turning off a light).

  // Initialize outputs (ensure buzzer and motor are off)
  digitalWrite(buzzerPin, LOW);
  digitalWrite(motorForwardPin, LOW);
  digitalWrite(motorReversePin, LOW)

Before starting, we make sure that the buzzer and motor are off by sending a LOW signal to them.

void loop() {

The loop() part is where the Arduino keeps doing things again and again – it never stops until you turn it off.

  // Turn on all 5 LEDs continuously
  for (int i = 0; i < 5; i++) {
    digitalWrite(ledPins[i], HIGH);
  }

Every time the loop runs, we go through the 5 LED pins and turn them on. This keeps the 5 lights on all the time.

  // Buzzer: When its switch (A1) is pressed (reads LOW), beep the buzzer.
  if (digitalRead(buzzerSwitchPin) == LOW) {
      digitalWrite(buzzerPin, HIGH);  // Turn buzzer on
      delay(100);                     // Buzzer on for 100 ms
      digitalWrite(buzzerPin, LOW);   // Turn buzzer off
      delay(200);                     // Debounce delay
}

We check if the buzzer button (on A1) is pressed. Because of the pull-up setting, if the button is pressed, it reads LOW.

If the button is pressed, we turn the buzzer on so it can make a sound.

We wait a tiny bit (100 milliseconds, which is a very short time) so the buzzer can beep. Then we turn the buzzer off so it stops beeping. We wait a little longer (200 milliseconds) to make sure the button press is clear and not too noisy. This is called “debouncing.”

  // Motor: When its switch (A0) is pressed (reads LOW), toggle motor direction.
  if (digitalRead(motorSwitchPin) == LOW) {
        if (motorState == 0) {
            // Run motor in forward direction for 2 seconds
            digitalWrite(motorForwardPin, HIGH);
            digitalWrite(motorReversePin, LOW);
            delay(2000);
            motorState = 1;  // Toggle for next press
            } 
        else {
            // Run motor in reverse direction for 2 seconds
            digitalWrite(motorForwardPin, LOW);
            digitalWrite(motorReversePin, HIGH);
            delay(2000);
            motorState = 0;  // Toggle for next press
          }

Now we check if the motor button (on A0) is pressed. Again, if it is pressed, it will read LOW. We check if our little memory box motorState is 0 (which means the motor should go forward).

If motorState is 0:

  • We turn on the motor’s forward pin (pin 9) and make sure the reverse pin (pin 10) is off.

  • We let the motor run forward for 2 seconds.

  • Then we change motorState to 1 so next time the motor will run in reverse.

If the motor button is pressed but motorState is not 0 (it must be 1), we do the reverse:

If motorState is 1:

  • We turn off the forward pin and turn on the reverse pin.

  • We let the motor run in reverse for 2 seconds.

  • Then we change motorState back to 0 for the next press.

    // Stop the motor after the run period
    digitalWrite(motorForwardPin, LOW);
    digitalWrite(motorReversePin, LOW)

After the motor has run for 2 seconds, we turn it off completely by setting both pins to LOW.

    delay(300);  // Debounce delay for the motor switch

We wait 300 milliseconds to make sure the button press is clean (debouncing) before checking again.

Some resources

For Windows

  1. Open Your Internet Browser:
    Open Chrome, Firefox, or another browser.

  2. Go to the Arduino Website:
    Type https://www.arduino.cc/en/software in the address bar and press Enter.

  3. Download for Windows:
    Click the "Windows Installer" button.
    (You can also use the ZIP file if you like, but the installer is easiest.)

  4. Install Arduino:
    When the file finishes downloading, double-click it.
    Follow the simple instructions on the screen.

  5. Start Creating:
    After installing, open Arduino and have fun making projects!

For Mac

  1. Open Your Internet Browser:
    Use Safari, Chrome, or another browser.

  2. Go to the Arduino Website:
    Type https://www.arduino.cc/en/software in the address bar and press Enter.

  3. Download for macOS:
    Click the "macOS" download button.

  4. Install Arduino:
    When the download is done, open the ZIP file.
    Drag the Arduino icon into your Applications folder.

  5. Start Creating:
    Open the Arduino app from Applications and enjoy your new projects!


Fun Activity!

In this fun activity, you'll learn how to program your Arduino Nano to make its on-board LED blink every second—like a little heartbeat that you control with your code. It's a great way to see how simple instructions can make things come alive with light! So, grab your board and let's start coding.

/*
  ------------------------------------------------------------
                         JumpLabs®
  Follow us on Instagram: jumplabs.co
             LinkedIn: JumpLabs
  "Bringing Families Closer!"
  
  This code blinks the on-board LED every second.
  ------------------------------------------------------------
*/

void setup() {
  // Initialize the on-board LED pin as an output.
  // LED_BUILTIN represents the built-in LED on the Arduino Nano (usually on pin D13).
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  // Turn the LED on (HIGH means on).
  digitalWrite(LED_BUILTIN, HIGH);
  // Wait for 1 second (1000 milliseconds).
  delay(1000);
  
  // Turn the LED off (LOW means off).
  digitalWrite(LED_BUILTIN, LOW);
  // Wait for another second before repeating.
  delay(1000);
}

Code Explanation

  • setup() Function:
    This part runs one time when the Arduino Nano starts.

    • pinMode(LED_BUILTIN, OUTPUT); tells the Arduino, "Hey, this LED is something we want to control!" The LED is usually connected to pin D13.


  • loop() Function:
    This part runs over and over, like a never-ending cycle.

    • digitalWrite(LED_BUILTIN, HIGH); turns the LED on. Think of HIGH as "power on."

    • delay(1000); makes the Arduino wait for 1000 milliseconds, or 1 second.

    • digitalWrite(LED_BUILTIN, LOW); turns the LED off. LOW means "no power."

    • The next delay(1000); waits another 1 second before the loop starts again.


    • Because the loop() function repeats endlessly, the LED will keep blinking on and off every second.

Thank you for visiting our corner of creativity and innovation. As you explore the endless possibilities with Arduino, let every project spark your imagination and guide you toward a brighter, inventive future—one brilliant idea at a time. Now, you can proceed to the next chapter, where we dive into the exciting world of LEDs.

Socials

info.jumplabs@gmail.com

Call Us

+4550142069

+91 9910566229

Damgade 82, 6400 Sønderborg

© Jumplabs Inc. 2023

Reach out to Us

Socials

info.jumplabs@gmail.com

Call Us

+4550142069

+91 9910566229

Damgade 82, 6400 Sønderborg

© Jumplabs Inc. 2023

Reach out to Us

Socials

info.jumplabs@gmail.com

Call Us

+4550142069

+91 9910566229

Damgade 82, 6400 Sønderborg

© Jumplabs Inc. 2023

Reach out to Us