0% found this document useful (0 votes)
59 views9 pages

Ardunino Worksheet

This one-day training program on Arduino with hands-on experience will teach participants how to build their own automation projects. The workshop materials include code examples and exercises for connecting sensors, LEDs, and motors to an Arduino board using basic programming structures like if/else statements and for loops. Participants will learn to read sensor input, control outputs with code, and use timing functions to add interactive elements to their Arduino projects.

Uploaded by

Sami Wondimu
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)
59 views9 pages

Ardunino Worksheet

This one-day training program on Arduino with hands-on experience will teach participants how to build their own automation projects. The workshop materials include code examples and exercises for connecting sensors, LEDs, and motors to an Arduino board using basic programming structures like if/else statements and for loops. Participants will learn to read sensor input, control outputs with code, and use timing functions to add interactive elements to their Arduino projects.

Uploaded by

Sami Wondimu
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/ 9

Faculty of Mechanical and Industrial Engineering, BIT, Bahirdar.

ONE DAY TRAINING PROGRAM ON ARDUINO WITH HANDS ON EXPERIENCE


- Built your own automation in just one day

Worksheet

By
Mr.V.Vennishmuthu
Dr.Navaneethasanthakumar
Project - I

1) Blinking LED

Connection:

GND

Pin - 13

Code:
int led = 13;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
1a) Make the connection as per below diagram and write a code for blinking
LEDs alternatively with time interval of one second and test it.

Connection:

GND

Pin - 8

Pin - 7

___________________________________________________________

Project - II

Sensor interface
7

GND

5V
Code:
int sensor = 7;
int x;
void setup()
{
Serial.begin(9600);
pinMode(sensor, INPUT);
}
void loop() {
x = digitalRead(sensor);
Serial.println(x);
delay(1000);
}

Exercises
2a) connect a LED in 13th pin and control it by using IR sensor Note: Use if condition
2b) Write a program that LED should ON after fifth input of sensor and it should OFF after
10th input of the sensor.
Project III
3) Motor interface

Code:
int sensor = 7;
int x;
void setup()
{
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(7,INPUT);
}
void loop()
{
x =digitalRead(sensor);
if(x== 1)
{
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
delay(500);
}
else
{
digitalWrite(11,HIGH);
digitalWrite(10,HIGH);
delay(500);
}
}

Exercises
3a) Motor rotating direction should be change for every 10 seconds
3b) Motor rotating direction should change, when sensor gives input to the
controller
Annexure I
Sample programs
1) If Statement (Conditional Statement)
The if() statement is the most basic of all programming control structures. It
allows you to make something happen or not, depending on whether a given condition is
true or not. It looks like this:
if (some Condition)
{
// do stuff if the condition is true
}
There is a common variation called if-else that looks like this:
if (someCondition)
{
// do stuff if the condition is true
}
else
{
// do stuff if the condition is false
}

Example:
int led = 13;
int x = 0;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
if (x<10}
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
x++;
}
}
2) for statements
The for statement is used to repeat a block of statements enclosed in curly braces. An
increment counter is usually used to increment and terminate the loop. The for statement is
useful for any repetitive operation, and is often used in combination with arrays to operate on
collections of data/pins.
There are three parts to the for loop header:

for (initialization; condition; increment)

//statement(s);

Example:
int PWMpin = 10;
void setup()
{
// no setup needed
}
void loop()
{
for (int i=0; i <= 255; i++)
{
analogWrite(PWMpin, i);
delay(10);
}
}
3) millis() [Timmer]
Returns the number of milliseconds since the Arduino board began running the current
program. This number will overflow (go back to zero), after approximately 50 days.
Example:
unsigned long time;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print("Time: ");
time = millis();
Serial.println(time);
delay(1000);
}

References:
1) http://www.arduino.cc
2) http://www.instructables.com
3) Arduino Cookbook by Michael Margolis

You might also like