You are on page 1of 21

FACULTY OF ELECTRICAL ENGINEERING

UNIVERSITI TEKNIKAL MALAYSIA MELAKA


BEKU 2422
ENGINEERING PRACTICE 2015
ARDUINO MICROCONTROLLER SIMULATION USING PROTEUS

Group Members : MOHAMAD NAZIRUL IDZHAM BIN BAHARUDDIN


B011310331
: MUHAMAD FAIZ BIN ZULKIFLI
B011210231

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

EXERCISE 2 (BASIC ANALOG INPUT AND PWM OUTPUT)


1) For the task 2 Interactive potentiometer, a virtual oscilloscope and virtual terminal are
needed to construct the following task using Proteus ISIS software
2) For the second exercise, the circuit of the task 2 was modified by the following, that are
needed to write a new program:
Three LED and a potentiometer are needed to use for this exercise
There are three ranges for the ADC voltage that was assumed
Only one LED will light up when the value of the ADC is within the first range
Two LED will light up when the value of the ADC is within the second range
Three LED will light up when the value of the ADC is within the third range
3) The example program file>example>analog>Analog In/Out Serial 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 2 : Exercise 2

EXERCISE 3 (RC SERVO CONTROL)

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

needed to write a new program:


Push button and RC servo motor were needed to construct the circuit.
The servo motor turn clockwise at its maximum position when the push button is pushed.
The servo motor will revert it back to its original when push button is pushed for the

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

EXERCISE 4 (INTERFACING WITH LCD DISPLAY)


1) For the task 4 the Interactive potentiometer, and LCD needed to construct the following
task using Proteus ISIS software.

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

EXERCISE 5 (SIMPLE PROJECT DESIGN)


1) For this project, Arduino UNO R3, two resistors, a LCD and LED were used to construct
the circuit using Proteus ISIS program
5. For the fifth exercise, the circuit was construct by the following, that are needed to write a
new program:

One LCD, one LED, and two resistor was needed


Once the LED light up, the LCD will function synchronize will LED and will display

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

This example code is in the public domain.


http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;
// the number of the pushbutton pin
const int ledPin = 12;
const int ledPin2 = 13;
// the number of the LED pin
int count = 0;
// variables will change:
int buttonState = 0;

// variable for reading the pushbutton status

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.
*/

// These constants won't change. They're used to give names


// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached
to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
const int led=13;
const int led2=12;
const int led3=11;
int limit=0;
int sensorValue = 0 ;
// value read from the pot
int outputValue = 0;
// value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3,OUTPUT);
pinMode(analogInPin, INPUT);
pinMode(analogOutPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

// wait 2 milliseconds before the next loop


// for the analog-to-digital converter to settle
// after the last reading:
limit = sensorValue;
if (limit <341){
digitalWrite(led, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);

}
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

LiquidCrystal Library - Serial Input


Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch displays text sent over the serial port
(e.g. from the Serial Monitor) on an attached LCD.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008

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

Project 1 Car Police Alarm


Include <LiquidCrystal.h>
Int ledDelay = 50; //delay by 50 ms
Int redPin = 9;

int bluePin = 11;\


LiquidCrystal led(12, 10, 5, 4, 3, 2);
Void setup ()

{
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

ANALYSIS AND DISCUSSION


1) For first exercise, first part when the simulation is run, the LED is turn on for one second
and then was turned off for one second as well, the cycle is repeated continuously. For
second part, when push button is press down, the LED lights up, while when the push
button is not press down, the LED does not light up. For exercise 1, the required output is
obtained by modifying the circuit and coding (using switch case).
2) For second exercise, firstly, when the simulation is running, the value of ADC (in Bits)
varied when the potentiometer value is changed. The maximum value of ADC is
1023(obtained from sensor value at virtual terminal). When the dial is turned, the duty
cycle varied accordingly. When the sensor value is adjusted to 512 (approximately 50%
duty cycle), the total period is 2ms.
3) For exercise 3, when the potentiometer value is changed, for example the value is
increasing the servo motor position rotate in clockwise direction and vice versa. The
maximum and minimum value position in degree is +90 and -90 degree respectively. The
maximum and minimum pulse width is 2ms and 0.4ms respectively. For exercise 3, the
circuit and coding was modified to obtain desired output. Pushing the push button once
will cause servo motor to rotate in clockwise direction until it reach 90 degree, pushing it
second time will revert the servo motor to its original position.
4) For exercise 4, first part, after running the simulation, the message on the LCD display on
first row is hello, world ! (by the command LCD set Cursor(0,0) ),followed by
number of second since the stimulation is run (in second row). For exercise 4, the circuit
and coding was modified to obtain desired output. An additional potentiometer was added
to the analog input (A0) , when we adjusted the potentiometer, the voltage will change
and its values is indicate in LCD screen. In coding part, float are used to approximate
analog value. Since we use 5V dc supply, this 5V will be correspond to 1023 (ADC value
in Bits), to display the value of voltage on the LCD screen we need to divide the dc
supply voltage with 1023 and then multiply with sensorValue ( the voltage in Bits
correspond to the current position of potentiometer).

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.

CONCLUSION AND RECOMMENDATION


1) The objective has been achieved. We success to design a environmentally friendly
lightning system. We successfully write the program code using Arduino software, run
the simulation through Proteus software and finally transfer to the hardware.
2) We are able to troubleshoot any problem that come out when writing or editing the
coding.
3) We have learnt about Arduino and its system and what it is capable of. In other , in future
we might be able to use Arduino microcontroller to design a system capable of solving
wide variety of problem in our daily life.
4) For the exercise 5, we recommend to put a LED to indicate operatin for opening gate.
Besides, we should put a button in order to control open/close gate.

You might also like