Você está na página 1de 22

1

UNIVERSITY OF DUNDEE
DIEGO VARALDA DE ALMEIDA -

PROJECT OF A SMART SPRINKLER USING


BASIC STAMP
Paperwork of the discipline Software
Applications
for
mechanical
engineering design, submitted to the
mechanical engineering course at the
University of Dundee.

Professor: Alan Hood


November of 2014.

LIST OF SYMBOLS

Current, [A]

Resistance, [ ]

Voltage, [V]

LIST OF FIGURES
Figure 1 - Diagram fragment ................................................................................................................................... 6
Figure 2 - LED indicating device ON ......................................................................................................................... 7
Figure 3 - 7-Segment display ................................................................................................................................... 8
Figure 4 - Display connected with the BASIC stamp ................................................................................................ 9
Figure 5 - Diagram fragment ................................................................................................................................. 12
Figure 6 - Diagram fragment ................................................................................................................................. 14
Figure 7 - A garden sprinkler rotated by the reaction of the water jets. ............................................................... 17

SUMMARY
1

INTRODUCTION ......................................................................................................................... 5
1.1

THE PBASIC LANGUAGE .................................................................................................................... 5

1.2

THE SPRINKLER PROJECT ................................................................................................................... 5

DEVELOPMENT.......................................................................................................................... 6
2.1

SPRINKLER ...................................................................................................................................... 6

2.2

ELECTRONIC CIRCUIT AND PROGRAM ................................................................................................... 6

2.2.1

Slide Switch ........................................................................................................................ 6

2.2.2

Light indication of device ON ............................................................................................. 7

2.2.3

7-Segment Display ............................................................................................................. 8

2.2.4

The Rotation Control ....................................................................................................... 11

2.2.5

Timer ............................................................................................................................... 12

2.2.6

Starting the motor ........................................................................................................... 14

PROJECT IMPROVEMENTS ........................................................................................................16


3.1

DELAY THE START OF THE MOTOR FOR BIG SPRINKLERS ........................................................... 16

3.2

CONTROLLING OUTPUT ................................................................................................................... 16

3.3

SPRINKLER PLATFORM FOR LARGE GARDENS ........................................................................................ 17

1 INTRODUCTION
Electronics nowadays is present in most products used by people. Some are more
advanced, such as mobile and computers, provides convenience, entertainment and leisure for
the consumer, and most of these devices have a microcontroller incorporated.
A microcontroller (sometimes abbreviated C, uC or MCU) is a small computer on a
single integrated circuit containing a processor core, memory, and programmable input/output
peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on
chip, as well as a typically small amount of RAM.
A very used microcontroller is the Basic Stamp. Produced by the Parallax Inc., the Basic
Stamp is a tiny microcontroller easily programmable and widely used in technology education
and in industries including manufacturing, process control, and robotics

1.1 THE PBASIC LANGUAGE


One of the most fundamental component of an electronic device is the program. The
program is a bunch of instruction that tells what the microcontroller should do in a language
that the microcontroller understands.
The Basic stamp utilize the PBasic language to allow the user to communicate with the
microcontroller. PBASIC is a microcontroller-based version of BASIC created by Parallax,
Inc. It was created to bring ease of use to the microcontroller and embedded processor world.
PBASIC is used for writing code for the BASIC Stamp microcontrollers. After the code is
written, it is tokenized and loaded into an EEPROM on the microcontroller. These tokens are
fetched by the microcontroller and used to generate instructions for the processor.

1.2 THE SPRINKLER PROJECT


A sprinkler is a device that sprays water. Despite simple it is a useful device and is
widely used within gardens and crops. Most of the sprinklers work mechanically, that is, there
is not an electronic device capable to manage the device, turning it on when the soil is too dry,
turn off when it is not necessary, controlling the flow of water and so on.
This project intends to use the Basic stamp in order to automate the sprinkler.

2 DEVELOPMENT
2.1 SPRINKLER
Since the number of pins in a Basic stamp microcontroller is limited, the functionalities
of the project is limited as well. The features that the sprinkler will have are the following:

Setting working time: the sprinkler will turn off after the set time is up.
Setting sprinkler velocity: The motor that controls the rotation of the sprinkler
will have many a range of rotation speed. The rotation of motor will determine
how far the water will reaches. The water sweep radius will be larger for a
higher motor speed
Setting Automatic speed for the sprinkler

In section 3, will be discussed some improvements that the sprinkler device may have.

2.2 ELECTRONIC CIRCUIT AND PROGRAM


The device consists of a slide switch that turns the device on and off. A green LED will
turn on when the switch is slide to the on position, to warn the user that the device is on; a
display where shows the device parameters will display the letter S, allowing the user to choose
the speed of the motor using the rotary knob.

2.2.1 Slide Switch


A slide switch is used to turn the device on and off. It is connected to the Pin4 of the
microcontroller using a pull-down resistor.
A pull-down is a technique used to avoid the input to receive a floated value (high or
low). When a pin of the microcontroller is connected to a resistor of 10K and then connected
to the ground the input is always low, until the user slide the switch or push the button. The
figure bellow show the microcontroller connected to a slide switch using a pull-down resisitor.

Figure 1 - Diagram fragment

(Author)

All section of the program needs to verify if the switch is in the on position, if not the
microcontroller needs to turn off all output pins. The command that checks the value of a pin
in a microcontroller is the IN[pin_number] command. This command basically transform a pin
in input and checks if the value is low or high. The value is stored in a variable.

Program Fragment 1

Because the program needs to check whether the switch is on or not multiple times, a
subroutine was used to write that part of the program.
A subroutine is a set of instructions designed to perform a frequently used operation
within a program. In PBasic it is possible to call a subroutine at any time by using the command
GOSUB [tag].

2.2.2 Light indication of device ON


A green LED is connected to the Pin0 and is on when the slide switch in on the on
position. The purpose of this LED is to indicate the user that the device is on.

Figure 2 - LED indicating device ON

(Author)

A LED is a light-emitting diode (a semiconductor diode which glows when a voltage is


applied). To be used within a microcontroller a resistor is required to limit the current in the
LED to a safe value. To determine which resistor should be used, it is used Ohms law:

V IxR

(2.1)

For a green LED a common resistance used is 470. This resistor will be used for all
LED within the device.
Since this LED is related with the slide switch and only turns on if the pin which the
switch is connected (Pin4) is accusing 1, then the code that turns the LED on will be together
in the same subroutine of the slide switch (see Program Fragment 1).
Another application for this LED will be discussed on section 2.2.4

2.2.3 7-Segment Display


The 7-segment display is formed basically of LED, where each segment is connected to
a pin of the microcontroller and works independently. For each segment (LED) it is necessary
to connect a resistor, anyone between 100 and 1k will work, the lower the resistance, the
brighter the segment. It is recommended to use the same resistor value for all segments, so all
of them would light up evenly. The figure below shows how the digit is divided in segments.

Figure 3 - 7-Segment display


(Parallax website, accessed on November 10th)

The DP shown in Figure 4 - Display connected with the BASIC stamp is a dot point, an
application for this segment is presented in section Error! Reference source not found.. The

igure below shows the diagram for the display connected with the microcontroller.

Figure 4 - Display connected with the BASIC stamp


(Author)

If we wanted, for example, the number 2 to be displayed we could turn on the segments
A, B, G, E, and D and turn off all the other, the program for the number two would be:

Program Fragment 2

Although simpler to understand, this approach is laborious and time consuming, besides
it lets the code slow to be read by the BASIC stamp. There is a better alternative for displays.
We first clean the display, then we set the pins 8 to 15 to be output, as can be seen below.

Program Fragment 3

10

Then the command LOOKUP is used to search a number stored in a variable in a set of
binary codes. The binary code correspondent to the number is then read by the microcontroller,
setting the pins 8 to 15 high or low depending on the binary number. The fragment below shows
another subroutine with the Lookup command that display the number on the 7-segment
display.

Program Fragment 4

Each number in the binary sequence correspond to a pin in the microcontroller. For
instance the first number that is displayed is the number zero and corresponds to 11101111.
The first 1 of this sequence of character is the pin 8, the second number (1) corresponds to the
pin 9 and so on until the last number that correspond to the pin 15.
If we wanted the letter A to be displayed, we would have to set as HIGH (1) the pins 8,
9, 10, 11, 13 and 15. All the other would be LOW (0). The signal % is to notify the
microcontroller that the sequence of digits is in binary form, rather than hexadecimal.
The table below shows all characters used by the sprinkler device and the corresponding
binary code.
#

CHARACTER

BINARY CODE

CHARACTER

BINARY CODE

0
1
2
3
4
5
6
7
8
9
10
11

0.
1.
2.
3.
4.
5.
6.
7.
8.
9.
0
1

%11101111
%10001100
%11011011
%11011110
%10111100
%01111110
%01111111
%11001100
%11111111
%11111110
%11100111
%10000100

12
13
14
15
16
17
18
19
20
21
22

2
3
4
5
6
7
8
9
A
S
t

%11010011
%11010110
%10110100
%01110110
%01110111
%11000100
%11110111
%11110110
%11110101
%01110110
%00110011

Table 1 Characters used on the display

11

2.2.4 The Rotation Control


The rotation of the sprinkler will be controlled by a DC motor connected with a
potentiometer which will allow the user to choose among 5 different levels of speed. As soon
as the user turns the device on a letter S will be shown on the display, indicating the user to
choose the speed for the motor. As commented in section 2.1, the speed of the motor will
determine how far the water leaving the sprinkler will reach.
The range of speed goes from 1 to 5, where 1 is the lowest speed and 5 the highest.
Besides that it is also possible to select an Automatic speed, where the motor will vary
automatically from 1 to 5 in a determining time, calculated by the program. The variation will
allow the sprinkler to cover all the five sweep radius.

Program Fragment 5

12

2.2.5 Timer
Another feature of the device is a timer which has the function to turn the sprinkler off
after a time set by the user. When the user chooses the sprinklers rotation and presses the push
button Set Parameter, the display changes immediately and starts to exhibit a letter t,
indicating the user to choose how long he wants the sprinkler to be working.
Once the microcontroller detects a variation of the potentiometer (when the user starts
spinning the potentiometer to select the time) the display will change from the letter t to a
number going from 1 to 9. Since the display is limited for one digit only, the DP will represent
the number zero, so when the user rotates the potentiometer to choose the time, the first 9
numbers shown will have the DP segment on. If the DP is on it means that the time chosen is
the number shown on the display times 10 (E.g.: suppose the user chooses the number 3
3x10 =30 minutes). If the DP is not on (it will be off after the user exceed 90 minutes), it means
the time shown on the display is in hours rather than in minutes and will start from 2 hours to 9
hours. This increases significantly the range of choices.
After selecting the minutes or hours that the user wants the device to be working, he
must to press the button Set Time again, so then the time chosen will be stored in the
microcontrollers memory as a variable (working_time). The figure below shows the electronic
diagram for the Set time button connected with the microcontrollers Pin2.

Figure 5 - Diagram fragment


(Author)

13

The code for this functionality is shown below:

Program Fragment 6

A potentiometer is used to vary the numbers on the display. A potentiometer is an


instrument for measuring an electromotive force by balancing it against the potential difference
produced by passing a known current through a known variable resistance.
The signal of the potentiometer is analogic, therefore the device TLC548, which is an Analogic
to Digital converter is necessary. The A/C reads the analogue voltage, convert it into an 8-bit
digital value, and then pass this information to the Basic Stamp. The command for that is the
SHIFTIN, which Shift data in from a synchronous serial device.

14

2.2.6 Starting the motor


To vary the motors speed the technique Pulse Width Modulation will be used in order
to divide the full speed in five different rotation. Since the rotation does not need to be highly
accurate, the use of a stepper motor for this purpose is not necessary. In section
A DC motor works with a higher current than the microcontroller can provide. Therefore
it is needed to connect a NPN transistor, in order to amplify the current that exits the output pin
of the microcontroller. A diode also makes necessary, once this will avoid the bounce of the
current. The diagram below shows the motor connected with the transistor and the diode.

Figure 6 - Diagram fragment

The PWM is a command which Converts a digital value to analogue output via pulse-width
modulation. The syntax of the command is: PWM Pin, Duty, Cycles, where:
Pin is a variable/constant/expression (0 15) that specifies the I/O pin to use. This pin will be
set to output mode initially then set to input mode when the command finishes.
Duty is a variable/constant/expression (0 - 255) that specifies the analog output level (0 to
5V).
Cycles is a variable/constant/expression (0 - 255) that specifies the duration of the PWM
signal.
The program below show the command PWM applied to vary the rotation of the motor

15

according to the speed chosen.

Program Fragment 7

Program Fragment 8

16

3 PROJECT IMPROVEMENTS
In this chapter will be discussed some of the improvements this project may have, to
become smarter and effectively marketable. Since some of these improvements are too complex
to demonstrate practically, the group decided not to deploy in the physical prototype, therefore,
it will be discussed theoretically only.
The following improvements, together with the other features in the circuit, require more
than 16 pins from the microcontroller, therefore a change of microcontroller to one with more
than 16 pins or the use of more than one microcontroller, should be considered in order to admit
all necessary features.
1 - Use a LCD display instead of a 7-segment display
2 - Controlling Output;
3 Moisture Sensor: To turn the device on and off automatically depending on the soil
humidity.

3.1 DELAY THE START OF THE MOTOR FOR BIG SPRINKLERS


For big sprinkler used in crops, it is possible that the device is embedded with the
sprinkler. If the user turns the device on, by sliding the switch, there is a high chance that she
or he will become wet by the water exiting the sprinkler. So, in order to protect the user
whenever this interacts with the device two features will be incorporated to the program,
allowing the user to configure the sprinkler without getting wet.
One of these tools is the interval provided from the moment the user presses the button
to start the sprinkler, to the time it effectively begins to rotate. Meanwhile the LED that indicates
the device is on will start flashing, informing the user that all settings has been done and that
he should move away from the device.
Since the microcontroller has a limiting amount of pins and since the display requires 8
pins to work properly, it is not possible to make use of a speaker, therefore the display will also
change for a meaningful character and will be flashing for 30 seconds, which is sufficient time
to allow the user to move away.

3.2 CONTROLLING OUTPUT


In section 1.2 it was shown that the sprinkler would work with a controlled rotation

17

using a stepper motor, but nothing has been said about the water output. The original
mechanical sprinkler created in 18was designed to use the water for propulsion, letting the water
output generate a torque that would rotate the sprinkler. It means that the sprinklers rotation
can be controlled by the water output. The figure bellow shows the water leaving the sprinkler
and the direction of the force that the water propulsion applies in the sprinkler.

Figure 7 - A garden sprinkler rotated by the reaction of the water jets.


(Rotorywing website, Accessed on November 8th)

As illustrated, each arm of the sprinkler works as a jet that propels the arm in the
opposite direction of the water, rotating the sprinkler. This is the mean reason for avoiding the
use of motor in this region of the sprinkler, the motor should be strong enough to resist the
propulsion force, which would increase the energy consumption.
To control the output instead of the rotation is a more efficient approach and should be
considered as an improvement.

3.3 SPRINKLER PLATFORM FOR LARGE GARDENS


The last and most difficult improvement, would be a platform that consists in a car
driven automatically by the microcontroller.

18

BIBLIOGRAPHY
Hood, Alan - Lecture Notes - University of Dundee, 2014.
Dr Jon Rogers - Components Notes - University of Dundee, 2014.
BASIC Stamp Syntax and Reference Manual V2.2 Parallax Inc. -

http://rotorywing.wikispaces.com/JET+PROPULSION+THEORY
November 8th

Accessed

on

19

APPENDIX A PROGRAM FOR THE SPRINKLER DEVICE

20

APPENDIX B ELECTRONIC DIAGRAM

21

22

APPENDIX C DEVICE INSTRUCTIONS

Você também pode gostar