Date: Group: Duration:: 5 Class Hours

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

HoChiMinh City University of Technology Mechatronics Department

HoChiMinh City University of ME2009 - Control System Technology


Technology
Lab Assignment 1
Faculty Mechanical of Engineering
Arduino, LED display, Photoelectric Sensor, and
Mechatronics Department
Encoder

REPORT
Date:………………… Group:……………… Duration: 5 class
hours
Full Name Student ID

Task 1. Interfacing between a Photoelectric Sensor and Arduino


In Tinkercad (Tinkercad.com), we replace DFRobot Adjustable Infrared Sensor Switch
by a PIR (passive infrared sensor), which has similar properties and pinout.
In this task, please take Arduino Uno R3 board, PIR sensor, Micro servo motor, LED, and
100 resistor from the library and connect them using a small-size breadboard to make a
circuit as following.

ME2009 - Control system technology - Lab. 1


HoChiMinh City University of Technology Mechatronics Department

Put the code for the Arduino:

#include <Servo.h>
Servo myservo;
int led = 6;
int pir = 2;

void setup() {
pinMode(led, OUTPUT);
pinMode(pir, INPUT);
myservo.attach(9);
Serial.begin(9600);
}

void loop() {
int val = digitalRead(pir);
Serial.println(val);

if (val == HIGH) {
digitalWrite(led,HIGH);
myservo.write(70);
}
else {
digitalWrite(led,LOW);
myservo.write(10);
}

delay(10);
}
 Click the button Start Simulation and describe what happens.

Task 2. Interfacing between a Rotary Encoder and Arduino


Make a circuit as following.

ME2009 - Control system technology - Lab. 1


HoChiMinh City University of Technology Mechatronics Department

ME2009 - Control system technology - Lab. 1


HoChiMinh City University of Technology Mechatronics Department

Code:
#include <LiquidCrystal.h>
volatile int count = 0;
int interruptPin = 2;
float speedRPM = 0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void encoderPulse()
{
count++;
}

void setup() {
lcd.begin(16, 2);
lcd.print("DC Motor Speed:");
lcd.setCursor(13, 1);
lcd.print("RPM");
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), encoderPulse, RISING);
}

void loop() {

lcd.setCursor(0, 1);
count = 0;
delay(200);

speedRPM = count * 6.25;


lcd.print(speedRPM);
}

 Adjust the potentionmeter and observe the number displayed in LCD.

ME2009 - Control system technology - Lab. 1


HoChiMinh City University of Technology Mechatronics Department

Screenshot:

 Show the pulse signal displayed in the oscilloscope (screenshot).

Task 3. Interfacing between 7-segment LED and Arduino


Replace the LCD in Task 2 by an IC 74HC595 and a 7-segment LED. Reference to the
code in Appendix 5.2 and details of 74HC595 shift register in Appendix 5.5 to connect
them to make a circuit and change the code in Task 2 to display the last digit of number
of rounds on the LED (i.e. if the motor rotated 478 rounds, the LED would display
number 8).

Screenshot:

Task 4. Interfacing both Rotary Encoder and Photoelectric sensor to Arduino


Using the circuit in Task 2, add one PIR sensor to the circuit. Change the code in Task 2
to add one more function: if the PIR detect an obstacle, the speedRPM is reset to 0 (zero).

ME2009 - Control system technology - Lab. 1


HoChiMinh City University of Technology Mechatronics Department

Screenshots:

ME2009 - Control system technology - Lab. 1

You might also like