getting started - robotshop | robot store | robots | robot …€¦ ·  · 2016-02-05breadboard...

53
Getting Started With Cuteduino 10 simple projects to get you started CUTEDUINO PWR LED RESET V1 R 3 4 G G 0 1 2 5V GND Ver 1.0 Last Revised October 2015

Upload: lyanh

Post on 22-May-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

GettingStartedWith Cuteduino10 simple projects to get you started

CU

TED

UIN

O

PWR

LED

RESET

V1

R

3

4

G G

01

2

5V

GND

Ver 1.0Last Revised October 2015

Page 2: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

2

(C) 2015 Arus Academy Jointly published 2015 by Arus Academy and CytronRevision History:1) First published October 2015

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. You are free to share and remix this work under the conditions that the appropriate credit is attributed approriately to Arus Academy and will be used for non-commercial purpose. For legal details, please refer to http://creativecommons.org/licenses/by-nc/4.0/

The illustrations in this manual are produced with the us of Fritzing (http://fritzing.org) and other open source initiatives. All images used in this manual are sourced from the internet. We’ve tried our best to source images from public domain. However, in the event that we’ve violated your rights for use of the image, please do not hesitate to contact us at [email protected]

Page 3: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

Table of Content

Section 1: Preparation What is Cuteduino Pg4 What is in this kit Pg7 Getting Started Pg8 Arduino IDE Basic Pg14 Breadboard Basic Pg17

Section 2: Simple Projects Project 1: Twinkle Little Star Pg19 Project 2: Counting Stars Pg22 Projecr 3: Neonlight Pg26 Project 4: Set Fire to the Rain Pg30 Project 5: Somewhere over the Rainbow Pg33 Project 6: Do-Re-Mi Pg36

Section 3: Interactive Projects Project 7: Flashlight Pg39 Project 8: Thank you for the Music Pg43 Project 9: Hot N Cold Pg46 Project 10: Shake it Off Pg49 What’s Next? Pg51

Page 4: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

4

What is CuteduinoA microcontroller is a mini computer that processes inputs given to it and produces suitable outputs for a specific task. Examples of microcontrollers used in our world includes washing machines and car consoles

A computer/laptop is able to process many different types of processes like computer games, or graphic designing. A microcontroller can only do a specific task at a time. (Like switching an LED on and off when a room becomes dark.) A microcontroller is very suitable to be used with electronic components like LEDs, resistors, transistors, capacitors, as well as mini sensors like LDR and infrared.

CuteDuino is a small microcontroller about the size of your thumb. It is suitable for small projects that require simple instructions. This microcontroller can be programmed multiple times over using the Arduino IDE platform. For ease of use, a common handphone USB cable can be used to power and program the CuteDuino because it can be powered with as little as 5V. Designed by Cytron Technologies, the Cuteduino is based on Digispark.

To date, the Cuteduino is the lowest cost Arduino IDE programmable controller board. The ‘brain’ of the Cuteduino uses a tiny chip called ATtiny85 which is powerful for its size. For more information about the Cuteduino, visit http://www.cytron.com.my/p-cuteduino.

Page 5: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

5

Label FunctionA Micro USB B type (female)B Power indicator LEDC Programmable LED (connected

to Pin 1, active high)D 5V voltage regulatorE ATtiny85F Pad for header pinG Reset buttonH 3mm hole

A) Micro USB B type (female)This connector is for USB connection to upload program or power it via USB cable. A USB Mi-cro-B type cable is needed.

B)Power LEDPower LED will light ON once the board is powered.

C) Programmable LEDProgrammable LED is active HIGH and it is connected to pin 1 (Arduino designation).

D) 5V voltage regulatorThis type of voltage regulator can handle up to 1A maximum.

E) ATtiny85CuteDuino uses ATtiny85 as the main controller running with 16MHz internal oscillator.

F) Pads for header pinCuteDuino pins can be plugged into the breadboard by soldering the header pin to these pads.

G) Reset buttonReset button can be used to enter bootloader mode or restart program.

H) 3mm holeThis hole can fit standard PCB stand.

Page 6: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

6

There are a total of 5 digital pins we could use for Cuteduino. Pin 0, 1 and 4 allow us to write data using analogWrite where as pin 2 and pin 4 allows us to read analog data using analogRead (Pin A1, pin A2). When we are using pin 2 and pin 4 as analog input, we need to address them as pin A1 and pin A2 instead of 2 and 4.

Please unplug the cuteduino from the breadboard when uploading a program if pin 3 & 4 is being used because these pins are shared with the USB communication and may interfere with program uploading.

For more information about Cuteduino: http://www.cytron.com.my/p-cuteduino

GNDPOWER

SPECIAL FUNCTIONDIGITAL PIN

SERIAL PWM

ADC PINATTINY85 PORT

CUTEDUIN

O

PWR

LED

RESET

V1R34G G

012

5V

GND

EXTERNAL POWER:7V-15V

USB D+4A2PWMPB4USB D-3PB3RESETPB2

5V

GND

LED 1 PWM PB1I2C_SCL 2 A1 PB2

0 I2C_SDA PB0PWM

Page 7: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

7

What’s in this Kit?

Cuteduino X 1 Breadboard X 1220 Ω

Resistor X 3

Red LED X 3 10kΩ Resistor X 1 Yellow LED X 2

Light Dependent Resistor (LDR) X 1 Piezo Buzzer X 1

Common Anode RGB LED X 1

SW 180 Vibration Sensor

LM35 Temperature Sensor X 1

9V Battery Snap X 1

Jumper Wires

Page 8: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

8

Getting StartedInsert the cuteduino into breadboard

1 2

3

Connecting Cuteduino to computer

Cuteduino can be connected to the computer via a USB Micro-B which is commonly used for Android phones. This also means that you can power up a cuteduino with an android phone charger or even a powerbank

Page 9: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

9

Install Cuteduino USB Driver

Visit https://github.com/CytronTechnologies/CuteDuino to download the driver. Extract the zip file.

Using Micro-B USB cable, connect CuteDuino to computer. Once connected, the PWR LED will turn ON.

For the first time connection, computer will not recognize CuteDuino (Unknown device).

Right click on Unknown device (CuteDuino), choose Update Driver Software...

1

2

3

4

Page 10: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

10

Choose Browse my computer for driver software.

Click Browse… and point to the DigisparkWindowsDriver folder. Click Next.

For Windows 8, user might need to disable the “driver signature enforcement” before proceed with the driver installation.

Windows Security will popup, choose Install driver software anyway. Reminder, for Windows 8 user, if driver signature enforcement is not disable, Windows Security will not popup and driver installation will not succeed.

Windows has successfully updated your driver software.

5

6

7

8

Page 11: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

11

Install Arduino IDE

Download and install the latest Arduino Software (Currently it’s 1.6.5) from https://www.arduino.cc/en/Main/Software

1

Go to File – Preferences, (or press ctrl + comma) copy and paste this link

https://raw.githubusercontent.com/CytronTechnologies/Cytron-Arduino-URL/master/package_cytron_index.json

at Additional Boards Manager URLs.

Hit OK.

2

Open board manager (Click on Tools - Board - Board Manager)3

Page 12: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

12

Wait a few seconds as Board Manager downloading the platforms index4

Once done, you can see Cytron AVR Boards at the bottom of Board Manager list. Click on the area and hit Install.

5

It will take a few seconds/minutes to complete the board installation.6

After the installation complete, you will see INSTALLED label at the side of board’s title.7

Page 13: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

13

Restart the Arduino IDE. Now you can see Cytron Arduino compatible board, Cuteduino and CT UNO under the Board list.8

To program Cuteduino, you need to select Board and Programmer to Cuteduino and program as normal

9

Page 14: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

14

Arduino IDE Basic

Label Description Label DescriptionA Menu Bar E Code AreaB Button Bar F Status BarC Serial Monitor G IDE OutputD Sketch Name H Board Name and COM Number

Page 15: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

15

A Verify Compiles and approves your code. It will detect errors in syntax (e.g. miss-ing semi colon or parentheses).

B Upload Sends your code to the CT UNO. When you click it, you should see the lights on your board blink rapidly.

C New Sketch This button opens up a new code window tab.D Open This button will let you open an existing sketch.E Save This saves the currently active sketch.F Serial Monitor Open Serial Monitor.

A B C D E F

Start the program by clicking this icon

1

2Select the right board(If you don’t see Cuteduino, please refer to the “Getting Started” chapter to install the baord)

Page 16: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

16

3Write your program in the space in E. You should have a standard program template such as this:

4Click upload when you are done

5When you see this message, press the reset button on Cuteduino (G)

Voila, you are done!6

Page 17: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

17

Breadboard BasicBreadboards are one of the most fundamental pieces when we build circuits. It allows us to prototype a circuit easily and does not turn our circuits into a mess of spaghetti-like wires (picture on the left). Instead, all of the wirees can be arranged neatly on the breadboard (picture on the right) for ease of troubleshooting later on.

The holes on the breadboard are connected in the following pattern. They are connected together like a wire

Dots linked by red lines are connected together

Figure 1: Spaghetti-like wires Figure 2: Wires arranged neatly within the breadboard

Page 18: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

18

Are these two circuits equivalent?

The circuit below is wrong. Why?

The circuit below is also wrong. Why?

Which of the following circuit is similar to the one in the box?

A

B C

Answer On Page 53

Page 19: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

19

Project 1: Twinkle Little StarYou will be able to:1) Use LEDs in projects2) Understand basic Arduino program structure2) Use digitalWrite and delay in arduino programming

Time required: 15 minutes

What do you need:1) Breadboard2) 220 Ω Resistor3) 1 Red LED4) Jumper Wires

Longer leg is +ve terminal and should connect to pin 0

LED has polarity. The longer leg is the positive (+ve) terminal and should be connected to Pin 0. The shorter leg is the negative (-ve) terminal and is connected to the Pin G (Ground)

Based on your understanding of the breadboard (Refer to Page 19), can you connect the same circuit using as many jumper wires as possible?

Page 20: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

20

Connect and CheckAlways put a resistor in series with an LED. If you fail to do this, you will supply too much current to the LED and may burn or damage the LED

Code and DebugYou may refer to “Arduino IDE Basic” on Page 14 for further explanation on the how to use the IDE and upload the code

This line defines which pin is the LED at. In this case, the LED is connected to Pin 0

pinMode sets Pin 0 (led1) to an output pin

Click upload when you are done programming

digitalWrite sends high signal to Pin 0 (led1) which tunrs on the LED

delay tells the Cuteduino to wait for 1000 milliseconds (1 second)

What happens when you change the number in delay? What do you think will happen when you change the delay to 10? What do you see?

Press the reset button when the IDE prompt shows up (Refer to Page 16)

Page 21: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

21

Reflect and LearnWhat happens if you keep reducing the delay duration? At what number does the light stop blinking and appear to be stationary? This is due to an effect called Persistence of Vision (POV). Whenever the light strikes our eye, it forms an impression in our brain for about 10th or 15th of a second, even after the light is removed from our sight. As a result, the eyes cant distinguish changes in the eye that is faster than this retention period.

Because of that, light that blinks faster than the retention period appears to be not blinking. This is the explanation behind how animation works. The early animation works by flipping images in rapid succession, causes an illusion that the objects are actually moving.

Explore and ExperimentMorse code is a system of representing letters, numbers and punctuations by means of code transmitted. The original Morse code consisted of dots (*) and dashes (-) that is arranged in specific manners to convey the letter it represented. When it was first invented by Samuel Morse in 1836, the information was transmitted using wires with a series of electric signals. Short signals are referred to as dits (*) and longer signals are referred to as dahs (-). However, any two different signals can be used to convey morse code such as radio signals switching on and off, or even different length of light flashing.

One of the most famous use of Morse Code is the S.O.S code. S.O.S code is transmitted to convey danger and to call for help. In Morse Code, S.O.S is represented by dot dot dot, followed by dash dash dash and dot dot dot (* * * - - - * * *).

Imagine if you were caught in a flash flood and you are stuck on the second floor of your house, and all you have is your Cuteduino Project 1 and the way to program it. Can you figure out a way to use your Project 1 to convey the morse code for S.O.S? You may use longer period of blinking to represent dash and a shorter period of blinking to represent dot.

Watch the following video to understand more about POVhttps://youtu.be/YismwdgMIRc

To learn more about Morse Code: http://cryptomuseum.com/radio/morse/

Page 22: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

22

Project 2: Counting StarsYou will be able to:1) Understand that different program may be loaded into the same circuit2) Understand and use while loop in programming3) Use analogWrite in programming

Time required: 15 minutes

What do you need:1) Breadboard2) 220 Ω Resistor3) 1 Red LED4) Jumper Wires

Longer leg is +ve ter-minal and should con-nect to pin 0

Page 23: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

23

Connect and Check

Code and Debug

This is the exact same circuit as before. However, if you would like to strengthen your understand of breadboard, try con-necting the circuit with at least 5 jumper wires. Refer to page 17 for further explanation on the breadboard

digitalWrite can either write a HIGH (5V) signal or LOW (0V) to the pin. analogWrite on the other hand can have any value between 0 to 5V. Thus, the LED brightness varies depending on how much voltage is supplied to the pin. The value supplied range from 0 (0V) to 255 (5V)

Fill in the blank while referring to the sample above. At each analogWrite, the analog value should increase by 20

Page 24: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

24

Sometimes it can be a little bit tedious to type and keep track of all the codes. We can use a while loop to automate this whole process.

while syntax:

while (test condition) //statement(s)

while the test condition is true, execute the statement in the curly brackets

1 int hungryLevel = 100;2 while (hungry != 0 )3 eat()4 hungry = hungry - 105

Line 1 initiates hungry level at 100. While hungry is not 0 (line 2), the software will eat (line 3). Everytime after it eats, it will reduce the hungry level by 10 (line 4).

Eventually, hungry level will be at 0 and that’s where we will stop the statement

while fade amount is less than 250 (line 9), write to the LED with whichever current fade amount is (line 10). Everytime after we do that, we add the fade amount by 10 (line 12).

Reflect and Learn

Page 25: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

25

You can also pulsate the light using something call Sine function. Sine is a function that generates a sine wave that is very smooth over time. You will probably realize that the LED in our project fades in a very unnatural way. It does not seem very smooth. We can use the sin function in Arduino programming library. The function takes in decimal number as input and returns another decimal number. For example: sin(1.5) will return 0.997, and sin(0.5) will return 0.479.

If we were to use angles as the input, the wave will complete one full cycle. As shown in the example at the side, if you were to put in 90 degrees, the sine function will return 1.0. By skipping all of these intermediate values, we can generate a nice smooth wave form.

However, sine function cannot do this when the angle is given to it in degrees (°). It can only do this if the angle is given to it in radians. Radians are units of angles measure in Pi (π). When you start from the angle of 0, at half way around the circle (180°), the radian value is Pi (3.141) and all the way around the full circle, the value will be at 2 π (6.283). Long story short, by using the radian value as input to the sine function, we will be able to generate the

same natural wave form. This way, we will be able to reach the maximum value (in this case, 1) at the the supplied value of π / 2 which is 1.57.

However, our job is still not done. This function feeds out maximum value at 1 and the minimum value at -1. This is not quite what we want for our analogWrite function which ranges from 0 to 255. For this, we will need to apply a little bit more mathematics to the program, which will multiply and shift our sine function range to whatever range that we want.

analogWriteValue = sin (radian) * 127.5 + 127.5

By multiplying the output value of sine function with half of our maximum analog value (255), we will get a range of -127.5 to 127.5. By adding the offset value (127.5) at the end of the formula, we will get a range from 0 to 255.

Explore and Experiment

-1

-0.5

0

0.5

1

0 90 180 270 360

Sine Function

-1

-0.5

0

0.5

1

0 1.57 3.14 4.71 6.28

Sine Function with Radians

0

64

128

192

256

0 1.57 3.14 4.71 6.28

Sine Function with Range Shift

Do note that in order for this to work, you will need to change all the int in your programme to float. Int data stores only integer number (numbers without decimal points, where as float data stores decimal number (for example, 3.17)

With this additional information, can you remake the program with the sine function?

To learn more about Sine function: https://www.mathsisfun.com/algebra/trigonometry.html

Page 26: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

26

Project 3: Neon LightYou will be able to:1) Understand parallel circuits2) Use multiple pins at the sametime

Time required: 30 minutes

What do you need:1) Breadboard2) 3 X 220 Ω Resistor3) 3 Red LEDs4) Jumper Wires

Page 27: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

27

Connect and Check

Code and Debug

Declare the third LED and its pin

Instead of typing out the delay time, we can use a variable to store the delay time. At line 4, we declare the delay time to be 300. At line 14, when the programme is running, it will substitute variable delay time with 300. That way, if we change the number at line 4, everything that follows will change.

Try using different numbers for the delay time to get just the light to ap-pear to be chasing each other.

Set the pin mode for the third LED

Turn on for the second LED and then give it a delay and then turn it off, do the samthing for the third LED

Page 28: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

28

Reflect and LearnThe reason why this project works is something called parallel circuits. Each of the LEDs are connected in parallel to each other. And each pin controls the individual circuits.

If you may recall from your science lessons, circuits can be connected in two ways: series or parallel.

Here’s how you would connect the circuit in series:

Now, try to write a program to turn on Pin 0. Compare the brightness of this circuit with the one you’ve made previously. What do you see? You’ll probably see that in this circuit, the LEDs are much dimmer. This is because the LEDs are connected in series (a series circuit) whereas the one you’ve made previously is a parallel circuit.

One of the biggest difference between a series circuit and a parallel circuit is in a series circuit, the voltage needs to be shared among the three LED. In a series circuit, more LEDs means more resistance, means more load to the circuit. In a parallel circuit however, adding more LEDs would not increase the resistance as much. The more resistance there is in a circuit, the dimmer the LEDs would be.

Think of it as the electric charge moving along the wires as cars moving on a highway. And each LED is a toll booth (resistance that slows the cars down)

Case 1:

1 toll booth. Car slows down slightly, but not too slow. Each time the car pass through, they pay up 60 cents

Case 2:

3 toll booths in series. Car slows down by a lot. Each time the cars pass through, instead of pay 60 cents at 1 booth, they have to make 3 stops and pay 20 cents at each of the stops.

Case 3:

3 toll booths. The movement of car is not affected as each of the car still passes through only 1 toll booth like in case 1. More cars get to pass through the road and the car flow rate is not affected as much.

To learn more about Series and Parallel circuit: https://learn.sparkfun.com/tutorials/se-ries-and-parallel-circuitsmorse/

Page 29: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

29

Explore and ExperimentLighting up multiple LEDs have many real life usage. Below are some of the examples:

1) Moving neon lights

2) Shop signs

3) Christmas lights / Festive lights

There are many cool projects you could do once you’ve mastered lighting up multiple LEDs, Here are some of the different things you could do to master this skills

1) Music dance lightImagine each of the LEDs to be an individual note. For example, the first LED could be “DO”, the second “RE” and the third “MI”. By turnining on the three LED light in sequence, it looks as if they are playing out “DO” “RE” “MI”. For example, “DO RE MI DO DO RE” will be LED 1, LED 2, LED 3, LED 1, LED 1, LED 2 again. We will learn to add sound to this in later chapter, but it is good to get some practice

2) Use all the LEDsThere are five LEDs included in this kit. Try to use all five LEDs in your project

3) Different light patternTry to use different pattern for the chase light. It could be going forward and then backward, or it could be lighting up the LEDs from the outermost LEDs to the innermost LED. It’s all up to your own creativity

Page 30: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

30

Project 4: Set Fire to the RainYou will be able to:1) Understand and use random functions

Time required: 30 minutes

What do you need:1) Breadboard2) 3 X 220 Ω Resistor3) 1 Red LED4) 2 Yellow LEDs5) Jumper Wires

This is the exact same circuit as before. Just substitute the left and right red LEDs with yellow LEDs

Page 31: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

31

Connect and Check

Code and Debug

Declare the other two LED pins just like Project 2

Set the pin mode for the other two LEDs

Repeat the code in line 12 and 13 for led3

For extra realism, put a piece of white paper over the LEDs

Page 32: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

32

Reflect and Learnrandom(number)This is an example of a function. We make functions in programming for things that we are likely going to repeat. For example, pinMode is a function that takes in two input, the pin number and the pin mode. pinMode (1,OUTPUT) would set the mode for pin 1 to be output.

The function random takes in 1 input and returns a random number with the input as maximum number (exclusive). For example, random(3) would return 0,1,and 2 with equal chances. random(1) could either return 1 or 0. random(120) would return a random number that ranges from 0 to 119.

Sometimes we could put function within another function. For example, the function delay(random(100)) at line 15. We first generate a random number between 0 to 99 and then this number is then used as input to the delay function as the time delay

Explore and ExperimentOne very interesting project you could make with a random function is a slot machine. The LEDs would turn on and off randomly. Here are some of the hints you could use:

1) In programming, 1 is synonymous with HIGH and 0 with LOW

2) random(1) would generate either 1 or 0

3) It is possible to use a function in another function

What other projects can you make with the random functions?

Page 33: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

33

Project 5: Somewhere Over the Rainbow

You will be able to:1)Use RGB LED in projects2)Program RGB LED to form different colours

Time required: 15 minutes

What do you need:1) Breadboard2) 1 220 Ω Resistor3) 1 RGB LED4) Jumper Wires

There are two types of RGB LEDs, common anode and common cathode. Common anode means that the longest leg (the leg that is not Red, Green, or Blue) is connected to 5V where as common cathode, the longest leg is connected to Ground (GND)

Longer leg is should connect to pin 5V

Page 34: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

34

Connect and Check

Code and Debug

Make sure each color pin has a resistor to the cuteduino

By writing 0 value on the Blue LED (bled), we are turning on the BLUE led with maximum brightness in the RGB LED. 255 value for Green LED and Red LED would turn off the LED completely

What will happen if we write 0 on Green LED (gled) only?

How do we turn on Red LED (rled) only?

How do we make yellow color? Which two LEDs must we turn on?

How do we turn off all LEDs?

4

Pin 4 shares with the USB pin. Make sure that you remove the cuteduino from the breadboard before you upload the program

With the common anode version of the RGB LED, we turn on the respective LED pins by writing LOW instead of HIGH. Similarly, LOWER number in analogWrite would mean a brighter LED

014 AnalogWrite can only work with

PWM pins, which are Pin 0, 1 and 4

Page 35: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

35

Reflect and LearnAs you can see from the RGB LED, the colours of red, green and blue can be mixed by adjusting the colour brightness. Different combinations of red, green and blue can produce a rainbow of colours. This is what is known as the primary colors. Addition of primary colors produces secondary colors which can be mixed again to produce tertiary colors.

Giant electronic screens used as advertisements use RGB LEDs to produce vivid advertisements. Each pixel in a screen is a single RGB LED that can produce a variety of colours. When many of these pixels are programmed together, they can produce an image. The more RGB

used in a screen, the clearer the picture just like an LED TV. High definition TV (720p) has 1280 (in width) x 720 (in height) of pixels which means that it has a total of 921, 600 pixels.

Explore and ExperimentYou can also think of each individual LEDs in the RGB LED as different paint bucket. The lower value I used in the analogWrite, the more color I pour into the color mix. For example, by mixing a lot of red and a little bit of green, I will be able to make orange color.

Try to make a rainbow lamp by showing colors in rainbow order (Red, Orange, Yellow, etc).

You can visit http://www.rapidtables.com/web/color/RGB_Color.htm to see a list of different color combination you can use to generate different colors. Do note that in order to use the numbers on the website, you will need to do a little bit of experimentation yourself.

For example, the color orange is made with R255, G165, and B0. Thus, we know that to make orange color, we would need to mix a lot of red with a a little bit of green. Thus, we can play around with this propotion to create orange color

Page 36: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

36

Project 6: Do-Re-MiYou will be able to:1)Use the piezoelectric in a circuit.2)Program using tone to produce sound.

Time required: 30 minutes

What do you need:1) Breadboard2) Piezoelectric Buzzer3) Jumper Wires

Piezoelectric buzzer has no polarity. This means that it does not matter which wire goes to pin and ground

The piezoelectric buzzer in the kit do not have wires. Therefore, plug the piezoelectric buzzer directly into the breadboard and connect two jumper wires for each leg of the piezoelectric buzzer.

Page 37: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

37

Connect and Check

Code and Debug

tone(pin number, frequency, duration)

tone generates a specified frequency on a pin.

The different number in frequency will generate different music note

What is the song that you hear?

0

Page 38: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

38

Reflect and LearnA piezo can produce sound from electrical signal because of vibration. Vibration is produced because there is an electromagnetic effect happening in the piezo when it receives signal. Vibration is what produces sound.

The speed of the signal, called frequency will determine what type of sounds are produced. The faster it vibrates, the higher the frequency.

In fact, this is how modern speakers work. Electric signals will cause the magnetic component within the speaker to vibrate and thus producing different frequen-cies.

Explore and Experiment

How does loud speaker works: http://www.explainthatstuff.com/loudspeakers.html

Piezo buzzer is capable of generating frequency that sound like a specific music notes. The ta-ble here is a table of the more commonly used notes in musc. For a full list of music notes and its corresponding frequencies, visit: https://code.google.com/p/rogue-code/wiki/ToneLibraryDocu-mentation

Music Notes Frequency (Hz)

NOTE_B2 123

NOTE_C3 131

NOTE_D3 147

NOTE_E3 165

NOTE_F3 175

NOTE_G3 196

NOTE_A3 220

NOTE_B3 247

NOTE_C4 262

NOTE_D4 294

NOTE_E4 330

NOTE_F4 349

NOTE_G4 392

NOTE_A4 440

NOTE_B4 494

NOTE_C5 523

NOTE_D5 587

NOTE_E5 659

NOTE_F5 698

NOTE_G5 784

NOTE_A5 880

NOTE_B5 988

Similarly, the duration of the notes can be adjusted to correspond to the length of a note. A whole note (4 quar-ters) would be 1000, a half (2 quarters) would be 1000 X 1/2 which is 500. Other duration may be calculated by multiplying the fraction with 1000 to get the desired lengthCan you complete the twinkle-

twinkle little star song?

Page 39: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

39

Project 7: FlashlightYou will be able to:1)Use a Light Dependant Resistor in a circuit.2)Understand the concept of analog signal.3)Program using analogRead to receive analog input

Time required: 30 minutes

What do you need:1)Breadboard2)1 x 220Ω resistor3)1 x Red LED4)1 x 10kΩ resistor5)1 x Light Dependant Resistor 6)Jumper Wires

LDR has no polarity. This means that it does not matter which wire goes to pin and ground.

Page 40: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

40

Connect and Check

Code and Debug

Turn off the light now. What happens?

analogRead reads analog value from an analog pin. In Cuteduino, the analog pin is shared with Pin 2 and Pin 4. Pin 2 is known as A1 when it’s being used as an ana-log pin. Analog values range from 0 to 1023

This number varies for each invidual. 380 should be the normal brightness. If the room becomes darker, this number will go down. You may need to experiment with this number to get the desired result.

Page 41: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

41

An intelligent mind makes decision based on what is the condition. In this project, we are introduced to an important syntax in programming, the if syntax to allow program to make decisions based on what information it receives

if syntax:

if (test condition) //statement 1 else //statement 2

if the test condition is true, execute the statement 1 in the curly brackets. Or else, execute the statement 2 in the curly brackets else

1 int temperature = analogRead(thermometer);2 if (temperature > 30 )3 say “It’s too hot”4 else 5 say “It’s not that hot”6

Line 1 checks the temperature with a thermometer. Line 2 decides what to do. If it’s too hot (more than 30 celcius) it will say “It’s too hot” (Line 3). Or else, it will say “Its not that hot” (Line 5).

Reflect and Learn

Reminder x == y (x is equal to y) x != y (x is not equal to y) x < y (x is less than y) x > y (x is greater than y) x <= y (x is less than or equal to y) x >= y (x is greater than or equal to y)

Page 42: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

42

Light Dependent Resistors

An LDR is a resistor that changes its resistance value based on how much light it receives. Therefore the LDR can produce a variety of values to the microcontroller. This variable value is considered analog signal.

Explore and Experiment

Analog signal VS Digital SignalAnalog signal is different from digital signal. Digital signal only can send out or receive “on” or “off”. The only range of value that the microcontroller will understand from digital signal is 0 to 1. Analog signals have a range from 0 – 1023. That’s more than one thousand different num-bers! Similarly, when we do digitalWrite, we can only turn on or turn off a LED. Where as with an analogWrite, we can give the LED a range of brightness from 0 to 255

Page 43: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

43

Project 8: Thank You for the Music

You will be able to:1)Combine what you have learnt in Project 1, 6 and 7 to make a music box

Time required: 30 minutes

What do you need:1)Breadboard2)1 Piezoelectric Buzzer3)1 X 220Ω Resistor4) 1 X LED5)1 x 10kΩ Resistor6)1 x Light Dependant Resistor 7)Jumper Wires

Page 44: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

44

Connect and Check

Code and Debug

What do you think should go inside here?

Put in your favourite song (Project 5) and blink the LED (Project 1)

noTone(speaker); noTone would stop all tone at the specified pin

Pin 4 shares with the USB pin. Make sure that you remove the cuteduino from the breadboard before you upload the program

Page 45: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

45

Reflect and LearnLDR forms a voltage divider circuit with the 10kΩ resistor. The 10kΩ forms a pull down resistor circuit. Remember from Project 6 that a LDR changes resistance value based on the light it receives. The brighter the light is, the lower the resistance of the LDR, resulting in higher voltage going into the analog pin (higher value read). When the brightness decrease, the resistance of the LDR increase, and the voltage going into the analog pin decreases too (lower value read).

The 10kΩ resistor serves as a pull down resistor. What it basically means is that it will pull the “floating” charges back into the ground. Without a pull down resistor, these floating charges will affect the reading at the analog pin.

Explore and ExperimentCan you make an actual music box with the box that comes with the Cuteduino? Per-haps to spice up your music box, consider using RGB LEDs to light up different color for different notes.

Page 46: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

46

Project 9: Hot N ColdYou will be able to:1) Use LM35 temperature sensor

Time required: 30 minutes

What do you need:1)Breadboard2)1 X LM35 Temperature Sensor4)1 x 220Ω resistor5)1 x LED6)Jumper Wires

1 - 5V2 - Pin A1 (2)3 - GND

Page 47: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

47

Connect and Check

Code and Debug

Unlike int, float variable is capable of storing numbers with decimal places.

LM35 is sensitive to the voltage supplied. If you are using batteries to power up the cuteduino, please change the input voltage at line 4 accordingly.

This formula converts the analog input into degree celcius reading and then storing it in temp

Connect the LM35 pins carefully. If you were to connect the LM35 incorrectly, the LM35 would heats up and becomes very hot

Page 48: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

48

Reflect and LearnThe temperature sensor works when the internal resistance in the sensor changes according to temperature. It works similarly like an LDR which changes internal resistance with light. When there is a change in resistance, there will be a change in output voltage. This change in voltage will be read by the microcontroller to be converted into temperature values.

Explore and ExperimentHow about using an RGB to indicate different colours for different temperatures? It is possible to stack multiple if cases with the following syntax and following example:

if (test condition) //statement 1 else if (test condition 2) //statement 2 else if (test condition 3) //statement 3 else if (test condition 4) //statement 4 else //statement 5

1 int weather = currentWeather()2 if (weather == sunny)3 playFootball()4 else if (weather == rainy) 5 bringUmbrella()6 else if (weather == snow) 7 buildSnowman()8 else if (weather == windy) 9 playKite()10 else 11 stayHome() 12

Page 49: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

49

Project 10: Shake It OffYou will be able to:1) Use SW180 vibration sensor

Time required: 30 minutes

What do you need:1)Breadboard2)1 X SW180 Vibration Sensor3)1 x 220Ω resistor4)1 x LED5)Jumper Wires

Page 50: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

50

Connect and Check

Code and Debug

Turn on LED if the current vibration state is high

Be very careful with the soft leg of the vibration sensor as it may be easily damaged.

Turn off LED if the current vibration state is low

Unlike analogRead which reads a range of values from 0 to 1023, digitalRead only reads two values, either it is a 1 (HIGH) or a 0 (LOW)

Page 51: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

51

Reflect and LearnTo understand how the vibration sensor works, we need to understand what happens inside. There is a stiff spring that is coiled around a soft wire. It does not touch unless it is shaken. The contact time of the stiff spring to the soft wire is very short.

Explore and ExperimentThis is a toggle switch program. Try to use this program.

What do you think will happen?

Source: Adafruit.com

Page 52: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

52

What’s Next?If you are sharing any of your projects on social media (Twitter, Facebook, Instagram, etc), please

use the follwing hashtag

#ArusCuteIf at any point you have any enquiries about the projects or any feedbacks about the projects in

this book, please do not hesitate to write to us at [email protected]

Portability of ProjectsYou can provide power to the project without the use of a laptop either via a mobile phone charger with a micro USB head, or with a battery. The following diagram shows how to provide power to the Cuteduino without the use of micro USB. This way, you can pack your project into a self-contained decoration

Sample Projects

You may use the container that comes with the Cuteduino kit as a container for your project. You can also attach the battery snap with the project so that the project can become a portable gift or decoration to be put in your house.

Page 53: Getting Started - RobotShop | Robot Store | Robots | Robot …€¦ ·  · 2016-02-05Breadboard Basic Pg17 Section 2: Simple Projects ... LDR and infrared. ... refer to the “Getting

53

Yes they are equivalent.

LED cannot be connected as such. Its legs must not share the same row on the breadboard.

Check the red circle

A

B C