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

Its secret power lies in its code, a special language that brings it to life. Each line of code is like a command in a spaceship’s control system, guiding the board on how to read the world around it. Some instructions tell it to measure the waves using sensors, others help it display messages on its OLED screen, and some even make it move with precision using its servo motor. Just like an intelligent navigator, the Blue Elixir Board follows its code to make decisions, light up LEDs, and communicate with its surroundings. As you explore its code line by line, you'll uncover how technology and creativity come together—turning simple instructions into an incredible journey across the seas of innovation

/*
  ------------------------------------------------------------
                         JumpLabs®
  Follow us on Instagram: jumplabs.co
             LinkedIn: JumpLabs
  "Bringing Families Closer!"

  ------------------------------------------------------------
*/

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <dht11.h>
#include <Servo.h>

// Initialize DHT11 sensor and Servo motor
dht11 DHT;
Servo myservo;

// Define OLED screen dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// Pin assignments for components
#define DHT11_PIN 11
#define OLED_RESET -1
#define trigPin 10
#define echoPin 12
#define ledPin1 4
#define ledPin2 5
#define ledPin3 6
#define ledPin4 7
#define ledPin5 8

// Create an instance of the OLED display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Variable to store servo position
int pos = 0;

void setup() {
  // Start serial communication for debugging
  Serial.begin(9600);

  // Set up pin modes for ultrasonic sensor
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // Set up pin modes for LEDs
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);

  // Attach servo motor to pin 9 and set initial position
  myservo.attach(9);
  myservo.write(90);
  delay(1000);
  myservo.detach();  // Detach to prevent jittering

  // Initialize OLED display
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Loop indefinitely if the display fails to initialize
  }

  // Display startup message on OLED screen
  display.clearDisplay();
  display.setTextSize(5);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("LEAP");
  display.display();
  delay(1000);
}

void loop() {
  // Read temperature and humidity data from DHT11 sensor
  int chk = DHT.read(DHT11_PIN);

  // Display sensor data on OLED screen
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("TEMPERATURE IS");
  display.println(DHT.temperature);
  display.println("HUMIDITY IS");
  display.println(DHT.humidity);
  display.display();

  // Ultrasonic Sensor Distance Measurement
  long duration, distance;

  // Clear the trigger pin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  // Send a 10-microsecond pulse to trigger pin
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Read the time it takes for the echo signal to return
  duration = pulseIn(echoPin, HIGH);

  // Convert time into distance in cm
  distance = duration * 0.034 / 2; // Speed of sound = 0.034 cm/µs

  // Print the distance to the serial monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // LED Control Based on Distance
  if (distance < 10) {
    // If object is closer than 10 cm, turn on all LEDs
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, HIGH);
    digitalWrite(ledPin5, HIGH);
  } 
  else if (distance >= 10 && distance < 40) {
    // If object is between 10 cm and 40 cm, turn on three LEDs
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
  } 
  else {
    // If object is farther than 40 cm, turn on only one LED
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin5, LOW);
  }
}

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

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <dht11.h>
#include <Servo.h>

These libraries enable communication with external components:

  • Wire.h → Handles I2C communication for the OLED.

  • Adafruit_GFX.h & Adafruit_SSD1306.h → Used to control the OLED display.

  • dht11.h → Provides temperature and humidity sensor support.

  • Servo.h → Enables servo motor control.

dht11 DHT;      // Create DHT sensor object
Servo myservo;  // Create Servo object

DHT is used to read temperature and humidity.

myservo is used to control a servo motor.

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.

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define DHT11_PIN 11
#define OLED_RESET -1
#define trigPin 10
#define echoPin 12
#define ledPin1 4
#define ledPin2 5
#define ledPin3 6
#define ledPin4 7
#define ledPin5 8

Defines pin numbers for sensors, LEDs, and OLED display settings.

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

Creates an instance of the OLED display object.

void setup() {
  Serial.begin(9600)

Initializes serial communication at 9600 baud for debugging.

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT)

Configures ultrasonic sensor pins.

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT)

Configures LED pins as outputs.

  myservo.attach(9);
  myservo.write(90);
  delay(1000);
  myservo.detach()

Attaches servo to pin 9, moves it to 90 degrees, then detaches it.

  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }

Initializes OLED display and checks if it’s working.

void loop() {

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

  int chk = DHT.read(DHT11_PIN);

Reads temperature & humidity from the DHT11 sensor.

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2

Measures distance using the ultrasonic sensor.

  if (distance < 10) {...} else if (distance >= 10 && distance < 40) {...} else {...}

Turns LEDs ON/OFF based on measured distance.

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!

Fun Activity: The Arduino Heartbeat Simulator!

In this fun activity, you'll program your Arduino Nano to simulate a heartbeat using its built-in LED! Just like a real heartbeat, the LED will blink in a special rhythm—a short blink followed by a longer blink—mimicking the way a heart pumps blood. This is a great way to explore timing, loops, and simple coding concepts using just your Arduino Nano.

/*
  ------------------------------------------------------------
                         JumpLabs®
  Follow us on Instagram: jumplabs.co
             LinkedIn: JumpLabs
  "Bringing Families Closer!"

  ------------------------------------------------------------
*/

pinMode(LED_BUILTIN, OUTPUT);

digitalWrite(LED_BUILTIN, HIGH); // Short blink (heartbeat contraction)
delay(200); // Hold light for 200 milliseconds
digitalWrite(LED_BUILTIN, LOW);
delay(100); // Short pause

digitalWrite(LED_BUILTIN, HIGH); // Long blink (stronger heartbeat pulse)
delay(500); // Hold light for 500 milliseconds
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Longer pause before next heartbeat cycle

Code Explanation

setup() Function – Getting Ready!

This runs once when your Arduino starts.

pinMode(LED_BUILTIN, OUTPUT);

This tells the Arduino, "We will control the built-in LED!" (which is usually connected to pin D13).

loop() Function – The Heartbeat!

This part runs forever, just like a real heartbeat!

digitalWrite(LED_BUILTIN, HIGH); // Short blink (heartbeat contraction)
delay(200); // Hold light for 200 milliseconds
digitalWrite(LED_BUILTIN, LOW);
delay(100); // Short pause

digitalWrite(LED_BUILTIN, HIGH); // Long blink (stronger heartbeat pulse)
delay(500); // Hold light for 500 milliseconds
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Longer pause before next heartbeat cycle

First blink (200ms ON, 100ms OFF): A quick beat.

Second blink (500ms ON, 1000ms OFF): A stronger beat followed by a longer pause—just like a real heartbeat!

What Happens?

When you upload this code to your Arduino Nano, the built-in LED will blink in a heartbeat rhythm—a quick pulse followed by a stronger pulse. It's like giving your Arduino a heartbeat!

Challenge:
Try changing the delay values to make your Arduino "heartbeat" faster or slower. What happens if you make the pauses longer or shorter?

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