Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arduino Programming. THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER.

Similar presentations


Presentation on theme: "Arduino Programming. THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER."— Presentation transcript:

1 Arduino Programming

2 THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER

3

4

5

6 MICROCONTROLLERS DO SIMPLE THINGS WELL

7 Basic sensing and response

8 LOW POWER

9 How much power does your laptop need?

10 Most microcontrollers are capable of going into a sleep mode where they draw very little power www.raspberrypi.orgwww.mouser.com

11 ARDUINO PROGRAMMING

12 Before you begin, go to tools, and make sure the board is set to Uno, and the Serial Port is set to the highest number

13 Make sure you can upload the code blink from examples/basic. If it worked, there should be a light slowly blinking on your Arduino

14

15 Every code your write needs to have two sections, void setup and void loop, but they can be empty

16 BASIC VARIABLES AND MATH

17 The serial monitor lets you print values from your code. It is going to be your best friend when it comes to debugging your code Click here

18 You will (hopefully not) make this mistake! The serial lines are connected to digital pins 0 and 1 on the Arduino. You usually don’t want to connect anything else to these lines.

19 You can use variables to store numbers, but you might get funny results int a = 6; int b = 2; void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.print("a divided by b is: "); Serial.println(a/b); Serial.print("b divided by a is: "); Serial.println(b/a); } void loop() { // put your main code here, to run repeatedly: } float a = 6; float b = 2; void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.print("a divided by b is: "); Serial.println(a/b); Serial.print("b divided by a is: "); Serial.println(b/a); } void loop() { // put your main code here, to run repeatedly: }

20 My advice would be to use floats for all of your variables until you get better at figuring out how these work.

21 CONTROLLING YOUR CODE

22 If statements can be use to make basic decisions in your code Syntax if(conditional statement) { Your code goes here } Example if(testVal == number) if(testVal < number) if(testVal > number1 && testVal < number2 )

23 Else if and else Syntax if(conditional statement) { } else if(conditional statement) { } else { }

24 Anatomy of a for loop in Arduino Example: for(int i = 0; i<10 ; i++) { Serial.println(i); } The variable i here is our counter You need to declare the variable with “int” This section says to run the loop while the counter i is less than 10 This section says to add 1 to our counter each time through the for loop Serial monitor output This code will now run 10 times

25 You can read a sensor with the analogRead() function (see the example in basic/analogReadSerial). The Arduino gives each voltage between 0 and 5 volts a number between 0 and 1023. How could we convert from the number we get to a real voltage?

26 Use the LM35 temperature sensor to measure temperature. The voltage goes up 10 mV for each degree C. Print the temperature to the serial monitor.


Download ppt "Arduino Programming. THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER."

Similar presentations


Ads by Google