Beruflich Dokumente
Kultur Dokumente
Course
Date
: 2 BEKM
: 1 1 AUGUST 2015
OBJECTIVE
By the end of this session, student should be able :
1. To understand the concept of digital input-output, analog input, Pulse-Width-Modulation
(PWM) method, and LCD interfacing for Arduino microcontroller.
2. To write a basic Arduino microcontroller program.
3. To simulate basic Arduino microcontroller circuit using Proteus software.
4. To design a simple mechatronics or electronic control system using a Arduino
microcontroller
METHODOLOGY
EXERCISE 1 (BASIC ARDUINO INPUT/OUTPUT)
For the first task, Arduino UNO R3, two resistors, one push button and one LED were used to
construct the circuit using Proteus ISIS program
1. For the first exercise, the circuit of the task 1 was modified by the following, that are
needed to write a new program:
Two LED and push button was needed
The first LED light up when the push button was pressed once
The second LED light up when the push button pressed twice. The LED turn off
when the push button presses in third time.
The cycle was repeated when we pressed it.
2. The example program file>example>digital>button was uploaded
3. Click Verify to compile the program. The program is compiling at the end of the bottom
part of IDE. When the program is successfully compiled, copy the hex file and paste to
the Proteus.
4. Run the simulation and observe the result.
Figure 1 : Exercise 1
Figure 2 : Exercise 2
1) For the task 3 Interactive potentiometer, a virtual oscilloscope and virtual terminal are
needed to construct the following task using Proteus ISIS software.
2) For the third exercise, the circuit of the task 3 was modified by the following, that are
second time.
The cycle was repeated.
3) The example program file>example>servo>Knob was uploaded.
4) Click Verify to compile the program. The program is compiling at the end of the bottom
part of IDE. When the program is successfully compiled, copy the hex file and paste to
the Proteus.
5) Run the simulation and observe the result.
Figu
re 3 : Exercise 3
2) For this exercise, the circuit of the task 4 was modified by the following, that is needed
to write a new program:
A potentiometer are need that are connect to the analog input and a LCD.
Write a program that will output the analog voltage of the potentiometer in the LCD.
3) The example program file>example>Liquid Crystal>Hello World was uploaded.
4) Click Verify to compile the program. The program is compiling at the end of the bottom
part of IDE. When the program is successfully compiled, copy the .hex file and paste to
the Proteus.
5) Run the simulation and observe the result.
Figure 4 : Exercise 4
OPEN GATE
When the push button will press the LED will turn off and LCD will display CLOSE
GATE
The cycle was repeated when we started the program.
6. The coding program was uploaded
7. Click Verify to compile the program. The program is compiling at the end of the bottom
part of IDE. When the program is successfully compiled, copy the hex file and paste to
the Proteus.
8. Run the simulation and observe the result.
Figure 5 : Project
RESULT
EXERCISE 1 :
Figure 1 : Exercise 1
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
count++;
delay(1000);
}
switch(count){
case 0:
digitalWrite(ledPin,LOW);
digitalWrite(ledPin2,LOW);
break;
case 1:
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin2,LOW);
break;
case 2:
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin2,HIGH);
break;
default:
count = 0;
break;
}
}
Figure 1 : Coding 1
EXERCISE 2 :
Figure 2 : Exercise 2
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
}
else if(limit >=341&& limit<=682)
{ digitalWrite(led, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
}
else if(limit > 682)
{ digitalWrite(led, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
}
}
Figure 2 : Coding 2
EXERCISE 3:
Figure 3 : Exercise 3
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pushButton=2; // analog pin used to connect the potentiometer
int buttonState; // variable to read the value from the analog pin
int count =0;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(pushButton,INPUT);
}
void loop()
{
buttonState =digitalRead(pushButton);
if (buttonState == HIGH)
{ count++;
delay(300);
}
switch(count){
case 0:
myservo.write(0);
break;
case 1:
myservo.write(180);
break;
case 2:
count=0;
break;
}
}
Figure 3 : Coding 3
EXERCISE 4 :
Figure 4 : Exercise 4
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystalSerial
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
lcd.setCursor(0,0);
lcd.print("Voltage:");
lcd.setCursor(0,1);
lcd.print(voltage);
lcd.print("V");
delay(1000);
}
Figure 4 :Coding 4
Exercise 5
Figure 5 : Exercise 5
{
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
lcd.begin(16, 2);
lcd.print(You Are Busted!!!);
}
Void loop ( )
{
digitalWrite(redPin, HIGH); // turn the red light ON
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, LOW); // turn the red light OFF
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, HIGH); // turn the red light ON
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, LOW); // turn the red light OFF
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, HIGH); // turn the red light ON
delay(ledDelay); // wait 50 ms
digitalWrite(redPin, LOW); // turn the red light OFF
delay(ledDelay); // wait 50 ms
delay(100); // delay midpoint by 100 ms
}
Figure 5 : Exercise 5
5) For exercise 5 which is our project named Auto Gate. After running the simulation, the
message on the LCD will display Gate Open, followed by LED light up. After press the
push button, LCD will display Gate Closefollow by LED light off.then simulation will
be repeat.