0% found this document useful (0 votes)
26 views18 pages

Arduino Hardware Setup and Programming

This document provides a comprehensive guide on setting up and programming Arduino hardware, including basic examples like blinking an LED and controlling sensors. It outlines step-by-step tasks for circuit setup, LED and buzzer control, sensor integration, and advanced projects such as a smart temperature monitor and automatic plant watering system. Additionally, it includes instructions for using Tinkercad for simulations and connecting Arduino with ArduinoDroid for mobile programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views18 pages

Arduino Hardware Setup and Programming

This document provides a comprehensive guide on setting up and programming Arduino hardware, including basic examples like blinking an LED and controlling sensors. It outlines step-by-step tasks for circuit setup, LED and buzzer control, sensor integration, and advanced projects such as a smart temperature monitor and automatic plant watering system. Additionally, it includes instructions for using Tinkercad for simulations and connecting Arduino with ArduinoDroid for mobile programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

ARDUINO HARDWARE SETUP AND PROGRAMMING

INTRODUCTION
/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/

#include <Arduino.h> // Include the core Arduino library

// Define a constant for the LED pin


const int LED_PIN = 13;

void setup() {
// Initialize the digital pin as an output
pinMode(LED_PIN, OUTPUT);
}

void loop() {
// Turn the LED on
digitalWrite(LED_PIN, HIGH);
// Wait for one second
delay(1000);
// Turn the LED off
digitalWrite(LED_PIN, LOW);
// Wait for one second
delay(1000);
}
Breakdown of the Sketch Components
1. Header Comment Block
/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
 Purpose: Provides a description of the sketch.
 Details: Enclosed between /* and */, this multi-line comment explains what
the program does and includes any pertinent information.
2. Library Inclusion
#include <Arduino.h> // Include the core Arduino library
 Purpose: Incorporates external libraries that provide additional
functionality.
 Details: The #include directive adds the specified library to the sketch. In
this case, <Arduino.h> is the core library that includes essential functions
for Arduino programming.
3. Global Variable Declaration
// Define a constant for the LED pin
const int LED_PIN = 13;
 Purpose: Declares global variables or constants accessible throughout the
sketch.
 Details: const int LED_PIN = 13; defines a constant integer LED_PIN with
a value of 13, representing the pin number connected to the LED.
4. setup() Function
void setup() {
// Initialize the digital pin as an output
pinMode(LED_PIN, OUTPUT);
}
 Purpose: Configures initial settings; runs once when the sketch starts.
 Details: The setup() function is called once when the program starts. Here,
pinMode(LED_PIN, OUTPUT); sets the LED pin as an output.
5. loop() Function
cpp
CopyEdit
void loop() {
// Turn the LED on
digitalWrite(LED_PIN, HIGH);
// Wait for one second
delay(1000);
// Turn the LED off
digitalWrite(LED_PIN, LOW);
// Wait for one second
delay(1000);
}
 Purpose: Contains the main code to be executed repeatedly.
 Details: The loop() function runs continuously after setup(). In this
example:
 digitalWrite(LED_PIN, HIGH); turns the LED on.
 delay(1000); pauses the program for 1000 milliseconds (1 second).
 digitalWrite(LED_PIN, LOW); turns the LED off.
 Another delay(1000); pauses the program for another second
before repeating the cycle.
Summary
This basic "Blink" sketch demonstrates the fundamental structure of an Arduino
program, comprising:
 Comments: For documentation and code clarity.
 Library Inclusions: To extend functionality.
 Global Variables/Constants: For configuration and easy maintenance.
 setup() Function: For initialization.
 loop() Function: For the main logic that runs repeatedly.

I. Steps to Set Up Tinkercad for Arduino Projects


1. Go to Tinkercad Circuits and log in.
2. Click “Create New Circuit.”
3. Drag and drop an Arduino Uno R3 onto the workspace.
4. Add components from the sidebar (e.g., LEDs, sensors, buzzers).
5. Connect the components using wires on the virtual breadboard.
6. Click "Code" → "Text" Mode and paste the Arduino code.
7. Click "Start Simulation" to test.
8. Adjust the circuit or debug the code if needed.

Task 1: Basic Circuit Setup (10 mins)


Components Needed:
 Arduino Uno
 Breadboard
 Jumper Wires
Steps:
1. Drag and drop an Arduino Uno into the Tinkercad workspace.
2. Add a breadboard and connect the 5V pin of Arduino to the positive rail and GND
to the negative rail of the breadboard.
3. Use a multimeter tool in Tinkercad to check voltage levels.
4. Click "Start Simulation" to verify power distribution.

Task 2: LED and Buzzer Control (15 mins)


Components Needed:
 Arduino Uno
 Breadboard
 1 x LED
 220Ω Resistor
 1 x Buzzer
 Jumper Wires
🔧 Steps:
1. Drag and drop an Arduino Uno into the Tinkercad workspace.
2. Connect LED:
o Anode (long leg) → Digital Pin 9
o Cathode (short leg) → GND (via 220Ω resistor)
3. Connect Buzzer:
o Positive → Pin 8
o Negative → GND
4. Paste this code in the Tinkercad code editor:
int ledPin = 9;
int buzzerPin = 8;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}

void loop() {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
delay(1000);
}
5. Click "Start Simulation" → Observe LED and buzzer alternately turning on/off.

Task 3: Sensor Integration (25 mins)


Components Needed:
 Arduino Uno
 DHT11 Temperature & Humidity Sensor
 Breadboard
 Jumper Wires
🔧 Steps:
1. Drag and drop an Arduino Uno into the Tinkercad workspace.
2. Connect the DHT11 Sensor:
o VCC → 5V, GND → GND, Data → Pin 2
3. Paste this code in the Tinkercad code editor:
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
dht.begin();
}

void loop() {
float temp = dht.readTemperature();
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" °C");
delay(2000);
}
4. Click "Start Simulation" → Check Serial Monitor for temperature readings.

Task 4: Motor or Advanced Sensor (Optional - 20 mins)


Components Needed:
 Arduino Uno
 Object Avoidance Sensor
 LED (Indicator)
 Breadboard & Jumper Wires
🔧 Steps:
1. Drag and drop an Arduino Uno into the Tinkercad workspace.
2. Connect the Object Avoidance Sensor:
o VCC → 5V, GND → GND, Output → Pin 7
3. Connect an LED to indicate detection:
o Anode → Pin 13, Cathode → GND
4. Paste this code in the Tinkercad code editor:
int sensorPin = 7;
int ledPin = 13;

void setup() {
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
int state = digitalRead(sensorPin);
if (state == LOW) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
delay(500);
}
5. Click "Start Simulation" → LED should turn on when an object is detected.

II. Materials Needed to Connect Arduino with ArduinoDroid


Hardware:
 Arduino Board (LAFVIN R3 CH340, Uno, Mega, or Nano)
 USB OTG Cable (Micro-USB/USB-C to USB-A)
 USB Cable (Standard Arduino USB Cable)
 Power Bank (optional for extra power)
Software:
 ArduinoDroid App (Download from Google Play Store)
Steps to Connect:
1. Install ArduinoDroid from the Play Store.
2. Connect Arduino to your phone using a USB OTG cable and USB cable.
3. Allow USB permission when prompted.
4. Write or open an Arduino sketch in ArduinoDroid.
5. Compile the code by tapping the checkmark icon.
6. Upload the code to the Arduino by tapping the right arrow icon.
Troubleshooting:
 USB not detected? Try another OTG cable or enable USB debugging.
 Compilation errors? Check if the correct Arduino board and libraries are selected.
III. Arduino Hands-On Training: Sensor and Actuator Integration
Objective:
1. Demonstrate proficiency in assembling Arduino circuits and connecting
components correctly.
2. Write and upload Arduino code to control various sensors, LEDs, and buzzers.
3. Develop a functional mini-project integrating multiple components and logical
conditions.

Test Components:
Each Group will prepare the following materials and components:
 Laptop/ desktop/ android phone
 Arduino Board (LAFVIN R3 CH340)
 Breadboard
 USB Cable
 Jumper Wires (M-M Dupont Wire)
 Resistors (Assorted)
 LEDs (RGB and Individual Red, Yellow, Green)
 Passive and Active Buzzers
 Potentiometer (10K)
 Sensors:
 DHT11 Temperature and Humidity Sensor
 Soil Moisture Sensor
 Water Level Sensor
 Sound Sensor Module
 Object Avoidance Module
 Photoresistor (LDR)
 Thermistor
 Tilt Switch
 Displays and Switches:
 7-Segment Display (1-Digit)
 Button Switches (Assorted Colors)

Task 1: Basic Circuit Setup (10 mins)


Procedure:
1. Connect the Arduino board to the breadboard.
2. Connect the power (5V) and ground (GND) rails.
3. Verify the connections with a multimeter.

Task 2: LED and Buzzer Control (15 mins)


Procedure:
1. Connect the LED (anode to digital pin 9, cathode to GND via a 220Ω resistor).
2. Connect the passive buzzer (positive to pin 8, negative to GND).
3. Upload the following code to the Arduino:
int ledPin = 9;
int buzzerPin = 8;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}

void loop() {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
delay(1000);
}

Task 3: Sensor Integration (25 mins)


Procedure:
1. Install the DHT11 library in the Arduino IDE:
o Go to Sketch → Include Library → Manage Libraries
o Search for DHT sensor library by Adafruit and install it.
o Also, install Adafruit Unified Sensor library if required.
2. Connect the DHT11 sensor:
o VCC → 5V
o GND → GND
o Data → Pin 2
3. Upload the following code to display the temperature:
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
dht.begin();
}

void loop() {
float temp = dht.readTemperature();
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" °C");
delay(2000);
}

Task 4: Motor or Advanced Sensor (Optional - 20 mins)


Procedure:
1. Connect the Object Avoidance Sensor:
o VCC → 5V
o GND → GND
o Output → Pin 7
2. Connect an LED to pin 13 to indicate detection.
3. Upload the following code:
int sensorPin = 7;
int ledPin = 13;

void setup() {
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
int state = digitalRead(sensorPin);
if (state == LOW) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
delay(500);
}

Task 5: Final Project Implementation (1hr.)


Procedure:
1. Design a system using at least three components.
2. Integrate and wire the components correctly.
3. Develop and upload an Arduino program to run the system.
4. Test the system and debug as necessary.

Project 1: Smart Temperature & Humidity Monitor


Components:
 DHT11 Temperature & Humidity Sensor
 7-Segment Display
 Passive Buzzer
Procedure:
1. Connect DHT11 sensor → VCC to 5V, GND to GND, Data to Pin 2.
2. Connect 7-segment display → Data pins to digital pins 3–9.
3. Connect Buzzer → Positive to Pin 10, Negative to GND.
4. Upload the following code:
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int buzzer = 10;

void setup() {
Serial.begin(9600);
dht.begin();
pinMode(buzzer, OUTPUT);
}

void loop() {
float temp = dht.readTemperature();
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" °C");

if (temp > 30) {


digitalWrite(buzzer, HIGH);
} else {
digitalWrite(buzzer, LOW);
}
delay(2000);
}

Project 2: Automatic Plant Watering System


Components:
 Soil Moisture Sensor
 LED (Red & Green for Dry/Wet Soil)
 Passive Buzzer
Procedure:
1. Connect Soil Moisture Sensor → VCC to 5V, GND to GND, Data to A0.
2. Connect Red LED (Dry indicator) → Pin 8, Green LED (Wet) → Pin 9.
3. Connect Buzzer → Pin 10.
4. Upload the following code:
int sensorPin = A0;
int redLED = 8;
int greenLED = 9;
int buzzer = 10;

void setup() {
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}

void loop() {
int moisture = analogRead(sensorPin);
Serial.print("Soil Moisture: ");
Serial.println(moisture);

if (moisture < 500) {


digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
digitalWrite(buzzer, LOW);
}
delay(1000);
}

Project 3: Water Level Alert System


Components:
 Water Level Sensor
 7-Segment Display
 Buzzer
Procedure:
1. Connect Water Level Sensor → VCC to 5V, GND to GND, Data to A0.
2. Connect 7-segment display → Data pins to digital pins 3–9.
3. Connect Buzzer → Pin 10.
4. Upload the following code:
int sensorPin = A0;
int buzzer = 10;

void setup() {
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}

void loop() {
int level = analogRead(sensorPin);
Serial.print("Water Level: ");
Serial.println(level);

if (level < 300) {


digitalWrite(buzzer, HIGH);
} else {
digitalWrite(buzzer, LOW);
}
delay(1000);
}

Project 4: Smart Light System


Components:
 Photoresistor (LDR)
 LED (Simulated Light Bulb)
 Button Switch (Manual Override)
Procedure:
1. Connect LDR sensor → VCC to 5V, GND to GND, Data to A0.
2. Connect LED → Pin 8.
3. Connect Button Switch → One pin to Pin 9, the other to GND.
4. Upload the following code:
int ldrPin = A0;
int ledPin = 8;
int buttonPin = 9;
int buttonState = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}

void loop() {
int lightValue = analogRead(ldrPin);
buttonState = digitalRead(buttonPin);
Serial.print("Light Value: ");
Serial.println(lightValue);

if (lightValue < 300 || buttonState == HIGH) {


digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
delay(1000);
}

Project 5: Security Alarm System


Components:
 Object Avoidance Module
 Buzzer
 LED (Intruder Alert)
Procedure:
1. Connect Object Avoidance Module → VCC to 5V, GND to GND, Data to Pin 7.
2. Connect Buzzer → Pin 9.
3. Connect LED → Pin 8.
4. Upload the following code:
int sensorPin = 7;
int ledPin = 8;
int buzzer = 9;
void setup() {
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}

void loop() {
int state = digitalRead(sensorPin);
if (state == LOW) {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzer, LOW);
}
delay(500);
}
Final Project Implementation - 100 Points (1hr)
Criteria 20 Points 15 Points 10 Points 5 Points 0 Points Score
Correct All Minor Some Major Compone
Wiring & compone wiring wiring wiring nts are
Connectio nts are errors, but mistakes, issues, not wired
ns (20 correctly the requiring requiring properly,
pts) wired and system moderate significant and the
neatly still debuggin interventio system
arranged, functions g to n to work. does not
with no with slight function function.
loose adjustmen properly.
connectio ts.
ns.
Functional The The The The The
ity of the system system system system system
System works functions works functions does not
(20 pts) exactly as with minor partially poorly work at
intended inconsiste but lacks and does all.
and ncies but some not meet
meets all meets expected key
project most features. requireme
requireme requireme nts.
nts. nts.
Code The code The code The code The code The code
Efficiency is well- is is has is
& Logic structured functional somewhat multiple unorganiz
(15 pts) , with only inefficient inefficienci ed,
optimized, minor or es and is contains
and inefficienci contains difficult to numerous
follows es or redundant read. errors, or
best redundant /unnecess does not
practices lines. ary parts. run.
with no
unnecess
ary lines.
Debuggin The The The The The
g& student student student student student is
Troublesh efficiently can requires struggles unable to
ooting (15 identifies debug some help significant troublesh
pts) and fixes most with ly to oot or fix
any errors issues debuggin debug errors,
with independ g and and even with
minimal ently with troublesh needs assistanc
assistanc minimal ooting substantia e.
e. guidance. errors. l
guidance.
Project Uses at Use three Uses Uses only Uses only
Complexit least compone three two one or no
y (15 pts) three nts compone compone functional
compone effectively nts but nts or has compone
nts and and lacks an nts.
includes meets all additional incomplet
additional requireme functionali e setup.
features nts. ty or
beyond creativity.
the basic
requireme
nts.
Time Complete Complete Complete It takes Does not
Managem s the s the s the significant complete
ent (15 project project project ly longer the
pts) within the within the but to project
allotted 30 time slightly complete within the
minutes frame but exceeds the given
with time with the given project. time.
to spare minimal time.
for testing time for
and testing.
improvem
ents.

TOTAL Score: __________________________

Participant Name and Signature: ______________


Participant Name and Signature: ______________
Participant Name and Signature: ______________

Evaluator Signature: ______________

You might also like