The introduction to Arduino labs at Malmö University. These slides have been handed down since the beginning of Arduino. They have more authors then i can remember and should by no means be considered mine.
2. millis()
• millis(); returns the number of milliseconds the
arduino has been on
• Useful when you want two things to happen at once
”semi threading”
• Returns a long
• Examples/Digital
/Blinkwithoutdelay
Made by: David Sjunnesson
3. micro()
Returns the number of microseconds since the
Arduino board began running the current
program
Returns a long
Works the same way as millis()
4. Random
• random(min, max)
• Returns a pseudorandom number
between min and max.
• random(10,50) returns a number
between 10-49
• randomSeed();
• randomSeed(analogRead(4)); Gives you
a better random value
5. Try it out
• Create a program that randomly in time sends a
random value to the computer.
6. map()
Re-maps a number from one range to another
Useful when a sensor sends one range of
values but you need it in another.
map(value, fromLow, fromHigh, toLow, toHigh)
7. constrain()
Constrains a number to be within a range.
Helps to make sure a value is in a certain range
constrain(value, minimum, maximum)
8. Try it out!
Create a program that maps your value from a
potentometer from the read range into another
and sends it back to the computer.
9. MOTOR
• Actuator that transforms electricity into movement
• Motors can be of different kinds: DC, stepper, servos, etc. Each type has a different
way of being driven
• New motors can be very expensive. In many cases we will not be interested in high
accuracy and precission, just in showing the basic functionality
• It is in those cases when dismounting some kind of motor-driven device will be
useful to acquire the basic components for our design
• Car-toys, electric razors, printers, CD-drives, old hard drives, cash registers, and
many devices contain motors that we should be able of using
10. TYPES OF MOTORS
• There are three main types of motors
– DC motors: they are used in toys and devices that do not need high degrees of
accuracy in terms of speed or angle. With certain circuits that can be improved
– Stepper motors: they can move to a very precise position. We find them in
printers, scanners, etc
– Servo motors will move and stop at a certain angle on request. They are used in
car models to control the direction, model-planes for the flaps, etc
11. TYPES OF MOTORS
• DC motors:
– run freely
– hard to control their position/speed
– can use as less as 2,5Volts
– speed can be controlled using PWM
– we use relays, transistors or H-bridges to control them from Arduino
– with encoding circuits can become very precise
13. STEPPER MOTORS
• Stepper motors:
– 2 types: unipolar or bipolar
– rotate a certain amount of degrees at each pulse
– typical values of angles are 1,8 - 3,6 - 7,2 ...
– we use transistors, transistor chips, and H-bridges to control them
– they have 4 or more wires
– RepRap
15. SERVO
• they will rotate to a certain angle depending on a PWM value we push into them
• recently there are continuous rotation servos
• broadly used in robotics
16. SERVO/Continuous
• Connect the servo to the arduino
• Black ----> Arduino ground
• Red -----> Arduino 5v+
• White ----> Arduino motorPin
• Make it move Clockwise or Counter-clockwise
depending on the values read from a potentiometer
• Usefull functions is map()
17. SERVO/Standard
• Connect the servo to the arduino
• Black ----> Arduino ground
• Red -----> Arduino 5v+
• White ----> Arduino motorPin
• Make it move to a specified angle depending on the
values read from a analog input
• Usefull functions is map()
19. Transistor
• The transistor is considered by many to be the
greatest invention of the twentieth century. It is
the key active component in practically all
modern electronics.
20. Transistor
• A transistor is a semiconductor device,
commonly used to amplify or switch electronic
signals. The transistor is the fundamental
building block of computers, cellular phones,
and all other modern electronic devices.
21. Transistor
• We use transistors for:
– turning DC devices on/off: motors, lamps, etc
– dimming DC lights
– changing the speed of motors seamlessly (using
PWM)
22. How to hook up a motor
using IRF Z24
Copyright Kajsa Sahlström and Matilda Marcelius
25. Relay
• A relay is an electrical switch that opens and closes under the
control of another electrical circuit
• Makes it possible to control big stuff with Arduino
• Control up to 220V with 5v from Arduino
• Cant control speed...
26. Hook it UP!
Connect a DC motor and control the speed with
a analog sensor
Create a gaspedal!
Hinweis der Redaktion
Encourage people to interrupt you so you can help them immediately. Explain they do you a favor.
It’s good to time the duration of the presentation.
Millis() gives you the amount of time the arduino has been running in milliseconds.
Use a long variable to store this information, int is too small to hold the data.
Show blink without delay example
Picture: use an arduino to control the flash of a camera to do high speed photography based on the sound. (In the case of the picture the bulb breaking)
If you would use delay() it would not work because you would hit the actual kaboom. (the moment you want to photograph)
Micro works the same as millis, but returns the time in microseconds.
You use it when generating sound with arduino.
Explain random, give minium and maximum value.
The value returned is always in between the minimum and maximum specified.
You use static electricity of the physical world on an analog port to get a true random number.
Read the values in the serial monitor.
Explain everything again, random and randomseed.
You use this value often to constrain the value of sensors to get rid of their random behaviour.
Example: LDR. It fluctuates a lot, so you can constrain it’s value to make it more accurate.
Read the value in the serial monitor. Remap the value of 0-1023 to something else 0-255 for instance.
Explain DC-motors
Stepper motors
Servo motors
Every piece of electronics which moves has a motor.
There is a trade of between price, easiness to connect and accuracy.
Retarded brother of the other two motors.
If you switch the cables around it runs in the other direction.
You can use PWM on a low power motor to make it run at different speeds.
If it’s a high power motor you need a transistor to control it at different speeds.
When you need some sort of precision servo motors are the way to go.
An H-bridge not only allows you to change the speed but also the direction of turning.
H-bridge is a bunch of transistors connected
You put the motor as the bridge in the letter H, the center piece.
You can tell it’s a stepper motor because it has 4 more wires then the DC motor.
They need a transistor chip to be controlled. They need more power.
They can be moved at very specific angles.
You can use the steps
7,2 degrees per step for a normal stepper motor.
They also exist in 3,6 degrees per step.
They are used in scanners to scan the picture at the same speed for the whole picture.
Reprap is an open source 3D printer.
Magnets activate in turn and make the piston turn.
You control them with PWM, don’t use the motor library.
All robots use servo motors, and model airplanes.
There are two kinds, a standard servo motors, the standard one only turns 180 degrees, and a continuous rotation servo.
Continuous rotation servos are slower and they can’t be turned to a specific angle.
With a continuous rotation servo you can influence the speed by pulsing it at a specific speed.
500--------1000--------1500
If you pulse it at 1000 it will stop, 500 it will spin left way around and 1500 the right way around.
Map the values from the
They have a small potentiometer hole at the connector You can distinguish them this way from 180 degrees servos.
The standard servo, you pulse it, and the length of the pulse determines the angle to which it will turn.
If you pulse it with a delay of 500 milliseconds it will go to 0 degrees.
You can buy batteries to power the arduino so you don’t need the USB cable
Safe is: 6-17 volts.
Direct current
Most important electronic invention.
31 years old.
It’s the basis of all modern computers.
In prototyping they are usufally used to switch a lower power circuit to a higher power circuit.
So for instance you can control a high power lamp or solenoid indirectly from the Arduino with a transistor.
The IRF Z24 is a good transistor to use.
Some operate at lower power.
The IRF Z24 handles up to 80 volts, so it’s good for anything.
This one is about 15 SEK
This is a smaller cheaper one.
The BC547 is low voltage
Talk about 220 volts.
IF you go above 80 volts, you have to switch to a Relay instead.
If you want to control AC power you also need a Relay.
Transistors are only for Direct Current.
They are not allowed to experiment with this in school.
You can blow out the wall sockets.
If you want to control 220 volts,
Most relays only start to work from 12 volts. You have to activate an electro magnet inside the relay to close the high power circuit.
You use an arduino to control the transistor and the transistor to control the relay. You can experiment with this by buying a Relay kit.
IF you are unsure of what you’re doing with Relays then you’re not supposed to work with them.