Friday 20 November 2015

Arduino Basics

Today the STEM class connected their arduino boards to the computer and programmed for the first time this school year.

Here are some of the basic programs we wrote today and ways the students then were asked to modify the programs.

Here were the basic instructions the students were given to get started.



Program #1


After you load this program go to the Tools menu and select Serial Monitor.  You will see Hello World getting printed in the serial monitor. 

Student's were then asked to make this program better by making it print "Hello World" on a separate line in the serial monitor.
They changed the line "Serial.print("Hello World");" to "Serial.println("Hello World");"
Students also added a delay in the program by adding a line after the print "delay(1000);"
This made the program print out "Hello World" every second on a new line.

Program #2

Plug an LED into your arduino board.  Put the long leg into port 13 and a short leg into GND.
This is the first time students were introduced to the digitalWrite command.  Some student's projects were not blinking the LED on and off because they forgot to set up port 13 as an OUTPUT.  Student's then were asked to modify the program to make the light blink faster and slower.

Program #3

In the third programs students setup a variable that is an integer.  If they want to change the value of the variable they can do it once in the start of the program.  Students were asked to add a line to this code to print the value of the variable blinkTime.

Program #4

In program #4 students are introduced to a math operator.  Every time the program goes through the loop 20 is added to the value of the variable.  Students were asked to change this math operator to make the LED blink faster and faster.

Program #5


In program #5 students are introduced to an if statement.  Students were asked to change this program so that the LED blinked faster and faster.  When it reached the value of 0 use an if loop to reset the LED to the original value.

Program #6




In Program #6 students make an LED fade.  A digitalWrite will set the LED to HIGH or LOW, which is ON or OFF.  A analogWrite will turn an LED on to a certain value.  This is how you can dim the LED.  This program does have an error.  Port 13 does not work with the command analogWrite.  Students change the number 13 to 11 and plugged the long leg of the LED into 11 and the short into GND.