th annual mechatronics contest – 2019 - mechatronic… · 6th annual mechatronics contest –...

32
6 th ANNUAL MECHATRONICS CONTEST – 2019 www.scarborough.peo.on.ca Project Guidelines & Notes Junior Project (Grade 9 & 10) Prepared by Stephan Shatara, P. Eng. [email protected]

Upload: others

Post on 17-Mar-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

6th ANNUAL MECHATRONICS CONTEST – 2019 www.scarborough.peo.on.ca

Project Guidelines & Notes Junior Project (Grade 9 & 10)

Prepared by Stephan Shatara, P. Eng.

[email protected]

Page 2: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan
Page 3: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

MECHATRONICS CONTEST 2019, JUNIOR PROJECT GUIDELINES & NOTES

Stephan Shatara, P. Eng., © 2019 i PEOSC

Contents Welcome ....................................................................................................................................................... 1

Supplied Parts ............................................................................................................................................... 1

Crane Layout ................................................................................................................................................. 2

Contest Points ............................................................................................................................................... 2

Beyond the Project ........................................................................................................................................ 3

Getting Started .............................................................................................................................................. 4

Recommended Reading Material .............................................................................................................. 4

Breadboards for Prototyping ..................................................................................................................... 4

What is a Microcontroller ......................................................................................................................... 5

What is the Uno Board? ............................................................................................................................ 5

Programming the Uno ............................................................................................................................... 5

Base Programs .............................................................................................................................................. 7

Push Button ............................................................................................................................................... 8

Schematic .............................................................................................................................................. 8

Short Circuit Considerations ................................................................................................................. 8

Breadboard Diagram ............................................................................................................................. 9

Sample Code ....................................................................................................................................... 10

Breakdown of Code ............................................................................................................................ 11

Program Summary .............................................................................................................................. 13

Arduino IDE ........................................................................................................................................ 14

For the offline (downloaded) Arduino IDE: Navigate to Tools Serial Monitor. This will open the serial monitor on a separate window. Rain Detector Circuit .................................................................. 15

Schematic ............................................................................................................................................ 15

Voltage Divider ................................................................................................................................... 15

How Transistors Work ........................................................................................................................ 16

Breadboard Diagram ........................................................................................................................... 20

Sample Code ....................................................................................................................................... 21

Breakdown of Code & Program Summary ......................................................................................... 21

Page 4: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

PEOSC ii Stephan Shatara, P. Eng., © 2019

Driving a DC Motor ................................................................................................................................ 22

Schematic ............................................................................................................................................ 22

DC Motor Basics – Torque & Speed .................................................................................................. 23

Breadboard Diagram ........................................................................................................................... 25

Sample Code ....................................................................................................................................... 26

Breakdown of Code & Program Summary ......................................................................................... 26

Arduino IDE ........................................................................................................................................ 27

Design of Mechanical Items ....................................................................................................................... 28

Page 5: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

MECHATRONICS CONTEST 2019, JUNIOR PROJECT GUIDELINES & NOTES

Stephan Shatara, P. Eng., © 2019 PEOSC Page 1 of 28

Welcome You have chosen to participate in Professional Engineers Ontario Scarborough Chapter’s (PEOSC) 2019 Mechatronics contest. This year’s junior teams will be building an electrical crane system, triggered to pull a load after detecting rain. Through this contest, you will learn about basic concepts of electronics, programming microcontrollers (using Uno board), mechanical design considerations, as well as speed vs torque of DC motors.

Welcome and good luck.

Supplied Parts All the electronics and gears required to go through the sample programs and build your electrical crane system have been provided, including the following:

• x1 Uno R3 board • x1 breadboard • x1 DC Motor • x1 2N3904 NPN Transistor for the rain detector circuit • x1 pack of miscellaneous gears

Besides the gears, mechanical parts to build the crane have not been provided. Each team is responsible for designing and building the mechanical parts required for the crane. Students are not allowed to make substitutions with the provided electronics and DC motor.

Page 6: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 2 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Crane Layout Your team is responsible for building the gear / pulley arrangement. PEOSC will provide the pulley as well as the load.

Contest Points Each team’s submission will be subject to the following guidelines and point system. Failure to comply with any item will result in deduction of points, and up to 0 points in each sub-category.

Each team will be assigned points in the following categories, totaling 30 points:

1. Program code – 5 points 2. Project innovation – 5 points 3. Performance – 10 points 4. Questions – 10 points

Further Rules, Conditions & Specifications are posted on our PEO Scarborough Chapter website:

http://www.scarborough.peo.on.ca/2019/MECHATRONICS2019/Mechatronics%202019%20-%20Rules.pdf

Each team shall arrive to the contest with their project and the supporting material described in the guidelines below. Students are advised to save a soft copy of the materials requested on a USB flash drive in case they misplace the printed copies.

Program Code – 5 Points Maximum

1. The project code shall be printed on letter-sized paper and brought to the contest. 2. Each sheet shall have the team and individual team members names on it. 3. The code will be compared to the submitted circuit, to determine the accuracy of the program, as well

as review the team’s contributions beyond the supplied sample code.

Gear / Pulley arrangement designed by

students

Pulley – supplied by PEOSC

100 gm weights at 5 cm intervals – supplied by PEOSC

Supplied DC Motor

Arduino

Table

Page 7: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 3 of 28

4. The Arduino sketch will also be exported, saved on a USB flash drive, and brought to the contest. If there are any discrepancies, PEO will request from the team to reprogram the Uno with the sketch saved on the flash drive for verification (computer will be provided by PEO).

5. Failure to submit the code will result in 0 points in this category.

Project Innovation – 5 Points Maximum

The kit is provided with many electronic parts, including a buzzer, LEDs, servo motors, etc. The submitted circuit and program code will be reviewed to determine how innovative it is. Can you make use of any additional components to build e.g. a visual and audible warning system after detecting rain?

Performance – 10 Points Maximum

The gears provided will form the basis of your crane system. When used with the supplied DC motor, different gear ratios will change the speed and torque of the drive shaft. Students are required to explore the tradeoff of speed versus torque, to lift the largest load in the least amount of time. The loads are made of up 100 gm weights at 5 cm intervals.

1. With each run, the maximum weight and time will be recorded 2. Each team will be allowed two (2) runs, and the best of either run will be considered the final team’s

performance

Questions – 10 points

Students will be asked 5 questions to test their general knowledge in electronics, software coding, as well as mechanical design. The questions will be derived from this document, as well as from the submitted project.

Beyond the Project The kit provided has additional parts you may or may not need, however, you are encouraged to experiment with integrating additional parts, once you have completed the core project and if there is time left.

As an example – building a warning system:

• Audible alarm using a piezoelectric buzzer (included in the kit) • Visual alarm using LEDs (included in the kit) • Mechanical flag using a servo motor (included in the kit)

Page 8: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 4 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Getting Started Recommended Reading Material Before you get started with building your prototype, it is important to understand the basic concepts of electricity and electronics. PEOSC has compiled material covering these topics as recommended reading.

These materials can be found on our website, under Mechatronics: http://www.scarborough.peo.on.ca/.

Additional reading material can be found online. PEOSC does not endorse specific websites. Examples are provided below:

https://learn.sparkfun.com/tutorials/voltage-current-resistance-and-ohms-law/all

https://simple.m.wikipedia.org/wiki/Voltage

https://simple.m.wikipedia.org/wiki/Electric_current

https://simple.m.wikipedia.org/wiki/Electrical_resistance

https://simple.m.wikipedia.org/wiki/Ohm%27s_law

Check your school or local library for additional reading material to help you understand the concepts.

Breadboards for Prototyping We will be using a breadboard to build our prototype. The breadboard is wired internally to allow electrically connecting components together without soldering wires.

On the center of the board, you will find sets of rows with 5 holes. Each of these five holes are electrically connected. However, the 5-hole rows are not connected to each other (electrically isolated). On either side of the breadboard, you will find two columns labelled with + and –. These columns are typically used for your positive (5V) and negative voltage (0V, also known as ground).

Figure 1: Internal wiring of a breadboard.

Page 9: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 5 of 28

Additional reading on breadboards:

https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard/all#introduction

What is a Microcontroller A microcontroller (or MCU) is an integrated circuit (IC), or chip, that can be programmed to perform various functions. The Uno board is built around a specific model of a microcontroller (ATMEGA328P), which we will be programming in this document to read various sensors.

Microcontrollers come in various package sizes and shapes. The version on the Uno board comes with a DIP-type package, which also allows you to use directly on a breadboard.

What is the Uno Board? The Uno board provides easy access to the onboard ATMEGA328P microcontroller pins, as well as a serial-to-USB interface. The latter allows communication between the chip and the Arduino IDE software, using a USB port on a PC, to program the chip, or transmit and receive serial data to / from the chip.

In addition, the Uno board has onboard voltage regulators, to supply a constant 3.3V or 5V DC source and a programmable onboard LED.

Put together, the board simplifies programming and communicating with the ATMEGA328P microcontroller, allowing you to build electronics projects much quicker.

For a description of the UNO board, its voltages, pins etc. refer to our “Part 3 Reading” presentation on our PEOSC website http://www.scarborough.peo.on.ca

Programming the Uno To program the Uno R3 board, we will use Arduino’s programming platform (or Integrated Development Environment, IDE for short). In this document, we will be using the online version of their IDE, which is accessible via a web browser and does not require any software download. However, the online version requires reliable access to the Internet, as well as an account registration (for free). Alternatively, you are welcome to use the offline version instead, which requires downloading the software (for free) and installing it on a PC.

Figure 2: DIP-Type Integrated Circuit (IC).

Page 10: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 6 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Your school may have blocked software downloads. Please request from your teacher to work with the IT department to gain access to the site.

Online Version: https://create.arduino.cc/editor

Offline Version: https://www.arduino.cc/en/Main/Software

Refer to these guidelines to get started:

https://www.arduino.cc/en/Guide/HomePage

https://www.arduino.cc/en/Guide/ArduinoUno

Page 11: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 7 of 28

Base Programs You are supplied with some base programs showing the functionality of the provided sensors. In this section, we will explain the circuits and code.

It is recommended you build each circuit and program included in this document, to familiarize yourself with the programming the Uno. After you complete all these projects, you will be in a good position to build your crane system:

1) Using a push button to turn on an LED, and understanding open circuits, closed circuits and short circuits

2) Building a simple rain detector circuit using a low-signal transistor, and understanding voltage dividers

3) Driving a DC motor using a power transistor

In addition, the supplied kit comes with a CD loaded with sample projects and code (from the manufacturer of the kit), which you are welcome to explore.

For additional help on coding with Arduino, refer to the following link:

https://www.arduino.cc/reference/en/

Page 12: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 8 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Push Button This first project will use a push button to turn on the onboard LED for a predefined time.

Schematic

Figure 3: Push Button Schematic Diagram.

The 5V DC source is supplied by the Uno board. When the push button is not pressed, the circuit is incomplete (open circuit), and no current can flow. The voltage measured by the Uno Digital Input would thus be 0V. In the digital world, 0V is represented as “LOW”, “FALSE”, “OFF” or the bit value “0”.

When the push button is pressed, the circuit is completed (closed circuit). Current flows through the circuit from the positive voltage (5V) to ground (0V). The voltage measured by the Uno Digital Input would thus be 5V. In the digital world, a high voltage (5V in this case) is represented as “HIGH”, “TRUE”, “ON” or the bit value “1”.

Short Circuit Considerations

The 10 kΩ resistor is connected between the voltage source and ground to limit the amount of current flowing through the circuit when the circuit is completed. The actual current (I) can be calculated using Ohm’s Law:

Equation 1: Ohm's Law

𝑉𝑉 = 𝐼𝐼 × 𝑅𝑅,

where V (voltage) is in Volts (V), I (current) is in Amperes (A) and R (Resistance) is in Ohms (Ω).

With V = 5V, and R = 10 kΩ, and solving for I, you will find that 0.5 mA will flow through the circuit when the push button is pressed. Remember that 1 kΩ = 1,000 Ω and 1 A = 1000 mA.

If you connect your positive voltage directly to ground without a resistor, you will create a short circuit. Using Ohms Law to calculate I when V = 5V and R = 0 Ω, you will find that I becomes infinite. Realistically, the DC source will supply the maximum current it can provide due to internal resistance (and not infinite). This current flow can be extremely high and damaging to your circuit.

Page 13: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 9 of 28

Never short circuit any of the circuits.

Breadboard Diagram

The schematic diagram is an electrical representation of the breadboard diagram below.

Figure 4: Push Button Breadboard Diagram.

Page 14: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 10 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Sample Code

/******************************** PEO Scarborough Chapter Mechatronics 2019 Ontario, Canada Button Sample Code ********************************/ #define buttonPin 2 int buttonState = 0; void setup () { pinMode(LED_BUILTIN, OUTPUT); pinMode(buttonPin, INPUT); Serial.begin(9600); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { digitalWrite(LED_BUILTIN, HIGH); Serial.println("Hello World"); delay(1000); digitalWrite(LED_BUILTIN, LOW); } }

Variables – the Uno executes these lines of code only once after power up

Setup – the Uno executes these lines of code only once after power up

Main Program – this is the main program of the Uno and is continuously executed

Label / Comment – this is not executed. Multiline comments start with /* and end with */ (as in this case). Single line comments start with //. Th d t th d f th li

Page 15: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 11 of 28

Breakdown of Code

#define buttonPin 2

The variable “buttonPin” is mapped to physical pin 2. Any references to “buttonPin” in the program will automatically mean Pin 2 on the Uno. In this example, the push button is connected to Pin 2 on the Uno.

int buttonState = 0;

A variable called “buttonState” is defined and initialized with a value 0. The data type is set to integer (or int for short). This means that this variable can accept whole numbers (no decimal places) from -32,768 to +32,767. However, in our code, this variable will only be assigned the state of the push button, which is 0 or 1.

pinMode(LED_BUILTIN, OUTPUT);

pinMode(buttonPin, INPUT);

With Arduino, we must define a pin as either an input or output. Here, we define the on-board LED as an output (since we will be writing to it an ON or OFF), and “buttonPin” as an input (since we will be reading the state of the push button via this pin).

Serial.begin(9600);

We will be using the Serial monitor built into the Arduino IDE to help us troubleshoot our program as it runs. With serial communication, we must configure the rate at which we are transmitting and receiving bits. Since serial communications sends data one bit at a time (hence the serial designation), the receiving end needs to know how quick the data is coming in. Here we initialize the Uno serial port with a rate of 9600 bits per second, also known as 9600 baud rates.

buttonState = digitalRead(buttonPin);

To read the state of a digital pin, we use the digitalRead() function. Here we read the state of “buttonPin”. Once read, the state of the pin is assigned to our variable “buttonState”. When the push button is pressed, the push button circuit is completed, the voltage on “buttonPin” will be 5V, and the state of “buttonState” will be read as “HIGH”. Note that one equal sign is used, which is an assignment operator, and is used to assign a value to a variable.

if (buttonState == HIGH) {

}

Page 16: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 12 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

An IF loop is nested in our main program loop. If the value of “buttonState” equals “HIGH”, the IF statement is considered true, and the program will enter this loop, to execute the code within this loop. Note that two equal signs are used, which is a relational operator, and is used to compare two variables.

digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, LOW);

The “digitalWrite” function takes two arguments, the pin and the state. In this case, we are supplying voltage to “LED_BUILTIN” (the on-board LED) when we write a “HIGH”, and thus the LED turns on. We ground the pin (0V) when we write a “LOW”, and thus the LED turns off. Note that “LED_BUILTIN” is already defined by Arduino library, and thus is not defined in our code (like e.g. “buttonPin”).

Serial.println("Hello World");

The “Serial.println” prints the text in the parenthesis, followed by a new line (like pressing the Enter key on the keyboard). Alternatively, Serial.print(“X”) just prints the text in the parenthesis and is not followed by a new line. This text shows up in the serial monitor within the Arduino IDE.

delay(1000);

This command adds a delay amount in milliseconds, in this case 1000 milliseconds (or 1 second). With the delay command, the freezes in its current state and pauses on the delay() code for the duration indicated in the parenthesis. During this time, the program cannot process anything else for the duration of the programmed delay. For this reason, the delay function should be used sparingly.

Page 17: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 13 of 28

Program Summary

When the Uno is first powered on, the program creates the variables and initializes them with the defined values.

Next it executes the items in the setup() function, in this case, we’re initializing the serial monitor with a specific baud rate, and the two pins we will be using – “LED_BUILTIN” as an output and “buttonPin” as an input.

Finally, the program reaches the main loop. In the main loop, it first reads the state of “buttonPin”. If the push button is not pressed, “buttonState” will read as “LOW”. Next it encounters the IF statement. The IF statement is checking if “buttonState” is HIGH. In this case it will not be true, and the IF loop is skipped. The program starts again at the top of the main loop, reading the state of “buttonPin”. This loop continues until the user presses the push button.

When the user presses the push button, the “buttonPin” goes high, and “buttonState” is assigned a state of “HIGH”. The IF statement is now true, and the code enters the IF loop. In the IF loop, the program first turns on the on-board LED, prints “HELLO WORLD” to the serial monitor, waits 1 second (with the LED on), then turns off the on-board LED. The IF loop exits, and the program starts again at the beginning of the main loop, reading the state of “buttonPin”.

Page 18: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 14 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Arduino IDE

Select Monitor from the left menu and select 9600 baud as the communication rate. When you press the push button, “Hello World” will show up in the serial monitor.

Figure 5: Arduino Online IDE with Push Button Sample Code.

Page 19: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 15 of 28

For the offline (downloaded) Arduino IDE: Navigate to Tools Serial Monitor. This will open the serial monitor on a separate window. Rain Detector Circuit In this project, you will build a rain detector using a transistor. Once the circuit detects rain, the program prints text to the Serial Monitor.

Schematic

Figure 6: Rain Detector Schematic Diagram.

This simple rain detector makes use of the fact that water is a fair electrical conductor (a few MΩ of resistance), while air is a poor conductor (thousands of MΩ of resistance). You will also need to build a probe, such as this:

Two pieces of wire are wound around screws. When water is present between the two screw heads, current can flow between the two wires due to the conductivity of water, creating a short circuit. Otherwise, it’s treated as an open circuit.

Voltage Divider

Before we proceed, we are going to explain how a simple voltage divider circuit works, as we will encounter that in our rain detector circuit. You can read more about voltage dividers here:

https://en.wikipedia.org/wiki/Voltage_divider

+5V

Screws

Wires

Figure 7: Rain Detector Probe.

Page 20: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 16 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

A typical voltage divider circuit is represented with the following schematic, and equation:

Figure 8: Typical Voltage Divider Circuit.

Equation 2: Voltage Divider Equation.

𝑉𝑉𝑂𝑂𝑂𝑂𝑂𝑂 = 𝑉𝑉𝐼𝐼𝐼𝐼 × �𝑅𝑅2

𝑅𝑅1 + 𝑅𝑅2�

Consider R1 and R2 as a 10kΩ resistor and VIN as 5V. The voltage at VOUT is calculated as follows:

𝑉𝑉𝑂𝑂𝑂𝑂𝑂𝑂 = 5𝑉𝑉 × �10𝑘𝑘𝑘𝑘

10𝑘𝑘𝑘𝑘 + 10𝑘𝑘𝑘𝑘� = 2.5𝑉𝑉

How Transistors Work

To understand the rain detector circuit, we need to understand how NPN transistors work. Transistors are the most basic form of a ON/OFF electronic switch. Transistors have three pins, one called Base, one called Collector, and one called Emitter. In the schematic, these are labeled with B, C and E. The current at the Base pin is what controls the ON / OFF state of the transistor.

You can read more on transistors here:

https://learn.sparkfun.com/tutorials/transistors/all

Page 21: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 17 of 28

Figure 9: 2N3904 General Purpose NPN Transistor.

When the probe is dry, it acts as an open circuit, and no current flows into the Base. The transistor is OFF in this case. We can represent the transistor as an open circuit.

Figure 10: NPN Transistor in the OFF State when Probe is Dry.

Due to the open circuits, current is forced to flow from the 5V power supply and into the digital input pin. The internal resistance of the Uno digital input pin is extremely high (100s of MΩ), and so this circuit becomes a basic voltage divider.

+5V

Page 22: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 18 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Figure 11: Voltage Divider Circuit when Transistor is OFF.

Referring to our voltage divider equation with VIN is 5V, R2 is 100 MΩ and R1 is 10 kΩ, we calculate VOUT:

𝑉𝑉𝑂𝑂𝑂𝑂𝑂𝑂 = 𝑉𝑉𝐼𝐼𝐼𝐼 × �𝑅𝑅2

𝑅𝑅1 + 𝑅𝑅2�

𝑉𝑉𝑂𝑂𝑂𝑂𝑂𝑂 = 5.0 × �100𝑀𝑀𝑘𝑘

10𝑘𝑘𝑘𝑘 + 100𝑀𝑀𝑘𝑘� ≈ 5.0 𝑉𝑉

When the probe is dry, the voltage present at the Uno Digital Input Pin 8 will be around 5V.

When the probe is wet, current flows from the 5V power supply and into the Base. This forces the transistor into an ON state. In the ON state, the transistor connects the Collector to the Emitter.

Figure 12: NPN Transistor in the ON State when Probe is Wet.

+5V

+5V

Page 23: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 19 of 28

This creates a simple circuit with the 10 kΩ resistor. Due to the extremely high resistance of the input pin, current will choose the path of lowest resistance, and flow directly to ground.

Figure 13: Basic Circuit when Transistor is ON.

Since the Uno Digital Input Pin 8 is connected directly to ground, the voltage present at the pin will be 0V.

+5V

Page 24: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 20 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Breadboard Diagram

Figure 14: Rain Detector Breadboard Diagram.

Page 25: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 21 of 28

Sample Code

/******************************** PEO Scarborough Chapter Mechatronics 2019 Ontario, Canada Rain Detector Sample Code ********************************/ #define sensorPin 8 int sensorState = 0; void setup() { pinMode(LED_BUILTIN, OUTPUT); pinMode(sensorPin, INPUT);

Serial.begin(9600); } void loop() {

sensorState = digitalRead(sensorPin); if (sensorState == LOW) { digitalWrite(LED_BUILTIN, HIGH); Serial.println("Rain Detected"); delay(1000); digitalWrite(LED_BUILTIN, LOW); }

}

Breakdown of Code & Program Summary

The code for the rain detector project is almost identical to the push button code. Refer to the push button project for more details.

Page 26: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 22 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Driving a DC Motor This project will use the push button to turn on a DC motor for a specified amount of time. For the push button circuit, see the Push Button program.

Schematic

Figure 15: DC Motor Schematic Diagram.

This circuit uses a power NPN transistor TIP120 to provide enough current to the DC motor. It is really two (2) transistors integrated into the casing, known as a Darlington Transistor. It provides high gain and high current. The 2N3904 cannot provide enough current when it’s in the ON state. With a current limitation, the motor may not be able to provide enough torque to overcome its internal resistance and the shaft may not rotate at all.

Figure 16: TIP120 General Purpose NPN Power Transistor.

If you notice, we’re using four (4) external AA batteries. DC motors require a lot of current, a lot more than what the Uno can provide.

Do not power the DC motor directly from your Uno as it may damage your board.

When the Uno Pin 9 outputs a LOW (driving the pin to 0V), current does not flow into the transistor base. This forces the transistor to an OFF state, and acts as an open circuit. The circuit is incomplete, and the motor is OFF.

Page 27: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 23 of 28

Figure 17: DC Motor Circuit with NPN Transistor in OFF State.

When the Uno Pin 9 outputs a HIGH (driving the pin to 5V), current flows into the transistor base. This turns the transistor to an ON state, and acts as a short circuit. The circuit is completed, and the motor turns ON.

Figure 18: DC Motor Circuit with NPN Transistor in ON State.

DC Motor Basics – Torque & Speed

Torque defines the rotational force of a lever, in this case, the shaft of our DC motor. Torque is the rotational equivalence of a push or pull force on an object travelling in a straight line. The higher the torque, the more force it has, and can overcome larger resistances. The lower the torque, the less force the shaft has, and can handle less resistance. The resistance in this case will be provided by the weights as part of the contest.

You can read more on DC motor basics here:

http://www.me.umn.edu/courses/me2011/arduino/technotes/dcmotors/motor-tutorial/

You can experience this resistance by simply gripping the shaft of the DC motor while it’s ON. The more resistance you provide (the harder you squeeze), the slower the shaft will rotate. Eventually, with enough resistance, the shaft will stop rotating altogether. This is known as stalling.

What we find is that the rotational speed of the DC shaft (rotations per minute) is inversely proportional to the torque. In other words, the faster the DC motor shaft rotates, the less torque it can provide.

Page 28: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 24 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Figure 19: Torque vs Speed of DC Motors.

In this contest, we need to drop the speed of the DC motor to increase the torque, allowing the crane to carry a bigger load.

To drop the motor’s RPM, you will need to use different sized gears to step down the rotational speed. You can read more about gear ratios here:

https://sciencing.com/calculate-speed-ratio-7598425.html

Page 29: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 25 of 28

Breadboard Diagram

Figure 20: DC Motor Breadboard Diagram.

Page 30: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 26 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Sample Code

/******************************** PEO Scarborough Chapter Mechatronics 2019 Ontario, Canada DC Motor Sample Code ********************************/ #define buttonPin 2 #define motorPin 9 int buttonState = 0; void setup() { pinMode(LED_BUILTIN, OUTPUT); pinMode(motorPin, OUTPUT); Serial.begin(9600); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { digitalWrite(LED_BUILTIN, HIGH); digitalWrite(motorPin, HIGH); Serial.println("DC Motor ON"); delay(5000); Serial.println("DC Motor OFF"); digitalWrite(LED_BUILTIN, LOW); digitalWrite(motorPin, LOW); } } Breakdown of Code & Program Summary

The code for the rain detector project is almost identical to the push button code. Refer to the push button project for more details.

Page 31: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Stephan Shatara, P. Eng., © 2019 PEOSC Page 27 of 28

Arduino IDE

Select Monitor from the left menu and select 9600 baud as the communication rate. When you press the push button, the motor will rotate for 5 seconds and print to the serial monitor.

Figure 21: Arduino Online IDE with DC Motor Sample Code.

Page 32: th ANNUAL MECHATRONICS CONTEST – 2019 - Mechatronic… · 6th ANNUAL MECHATRONICS CONTEST – 2019 . . Project Guidelines & Notes . Junior Project (Grade 9 & 10) Prepared by Stephan

Mechatronics Contest 2019, Junior Project Guidelines & Notes

Page 28 of 28 PEOSC Stephan Shatara, P. Eng., © 2019

Design of Mechanical Items One important item for this project is the design of the mechanical parts.

In order to lift high weights, the speed of the motor must be reduced. The speed can be adjusted by reducing the voltage or using Pulse Width Modulation (PWM). However, this will also reduce the torque that can be applied by the motor. The best method is to use reduction gears or pulleys.

To understand this design, we must learn about:

• Gears and their properties • Pulleys and their properties. • Relationship between torque and speed. • Work done and power etc.

My colleague and Mechatronics team member has prepared excellent notes covering these very topics, and I strongly recommend you reading this. See Part 1 Reading: Guidelines, Questions and Answers under the Mechatronics project page on our PEO Scarborough Chapter website:

http://www.scarborough.peo.on.ca/2019/MECHATRONICS2019/mechatronics.html

I wish you all the very best and consider that all are winners.