More on LED’s with Arduino

Slides:



Advertisements
Similar presentations
Wireless Cue Light Project
Advertisements

EMS1EP Lecture 6 Digital Inputs
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
Lab7: Introduction to Arduino
Re-programming the Simon Says with Arduino Linz Craig, Brian Huang.
Digital & Analog Inputs. Review Fundamental parts of an Arduino program are … Setting output types using pinMode. Declaring variables Can write a digital.
Introduction to Arduino Programming January MER-421:Mechatronic System Design.
Intro to Programming and Microcontrollers. Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will.
Finish your programs from last week STOPLIGHT CIRCUIT! You may need … – int – void setup() – void loop() – pinMode – digitalWrite – delay.
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
chipKit Sense Switch & Control LED
ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Code The Arduino Environment.
ARDUINO 1. Basics  Comments  /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We.
Microcontrollers, Microcomputers, and Microprocessors
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Microcontroller basics Embedded systems for mortals.
Week 5: Microcontrollers & Flow Control Bryan Burlingame 2 March 2016.
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
INTERNET OF EVERYTHING SDU 2016 Week 12. Remotely Controlling Devices  interact with almost any device that uses some form of remote control  TVs, audio.
:Blink Blink: Er. Sahil Khanna
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Arduino.
Servo’s and Motor’s with Arduino
Lab 7 Basic 1: Game of Memory
Electronics Ohm’s law & Resistance..
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Breadboards and LED’s with Arduino
Assist. Prof. Rassim Suliyev - SDU 2017
Val Manes Department of Math & Computer Science
Microcontroller basics
Wireless Cue Light Project
Microprocessors Tutorial 1: Arduino Basics
Arduino & its hardware interfacing
Arduino Programming Part II
UTA010 : Engineering Design – II
An Arduino Workshop A Microcontroller.
Welcome to Arduino A Microcontroller.
Exploring more with LED’s and Arduino
European Robotic LABoratory
UCD ElecSoc Robotics Club 2017/2018
Arduino Part 1 Topics: Microcontrollers Programming Basics
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Lecture 2-2: Arduino Programming
Arduino - Introduction
How to avoid catching things on fire.
ARDUINO     What is an Arduino? Features 14 Digital I/O pins 6 Analogue inputs 6 PWM pins USB serial 16MHz Clock speed 32KB Flash memory 2KB SRAM.
Continuing with LED’s and Arduino
IoT Programming the Particle Photon.
Arduino 101 Credit(s):
1 Code
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Welcome to Digital Electronics using the Arduino Board
Programming 2: The Arduino IDE & First Sketches
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Multiplexing seven-segment displays
Aeroponic Engineering and Vertical Farming
Arduino Uno circuit basics
Setting up a basic program with Arduino
Introduction to arduino
Arduino程式範例.
Introduction to Arduino IDE and Software
Interrupts.
Presentation transcript:

More on LED’s with Arduino A Microcontroller

Notes This material has been put together by the Outreach coordinator of the School of Engineering and Computer Studies (SECS) at Victoria University of Wellington (VUW), New Zealand. It is free to distribute and pass on to all who may find it useful. The author of this presentation and supporting documents can be reached at: john.barrow@vuw.ac.nz

Learning Objectives Students can explain more of the IDE’s tools Students can configure and use a pull up resistor (button) Students can configure and two buttons (pull down) Students can configure and use a button with a traffic light configuration (combining the last lesson and this lesson on buttons)

More on the IDE As we progress lets explore a few more things about the IDE before moving on Serial monitor has what is called a ‘baud’ rate, which relates to how many characters it sends 9600 baud = 9600 bits There is 8 bits (1 byte) per character So 9600/8 = 1200 bytes or characters per second Before the routers we use in our homes we had modems (MOdulator DEMmodulator’s) which worked like phones dialling up connections, this is what the serial monitor is using to connect.

IDE – tools menu Autoformat in the tools menu colour codes your sketch to help you trouble shoot it Archive sketch in the tools menu compresses the file in a ZIP format Burn bootloader in the tools menu we can use, when connecting with the ISCP pins, to permanently burn the code to the chip Why would burn a chip in and do this? This leads to… Library – a collection of code you can include in your sketch to enhance the functionality of your project (we will start using more libraries later).

Exercise 10 - Push Button (Pull up resistor) <File>, <examples>, <0.2 digital>, <button>

Exercise 11 - Push Buttons <File>, <Examples>, <SIK_Guide_Code_32>, <Circuit_05>

The code, note this… // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH);

Notes on concepts in the code: A == B means "EQUIVALENT". This is true if both sides are the same. A && B means "AND". This is true if both sides are true. A || B means "OR". This is true if either side is true. !A means "NOT". This makes anything after it the opposite (true or false).

Buttons A button is a tactile switch, which ca be a pull up or pull down resistor Pull down – when the button is pushed the electricity takes the path of least resistance (there is 2 resistors in a button, one with a much higher resistance than the other) and 5v passes through, otherwise it will ground and you get 0v Pull up – press the button it will ground = 0v We have used these already – the Arduino has built in 20kΩ resistors on the pin connections which we activate with software; To activate an internal pull-up we set pinMode to and INPUT and set it to HIGH with a digitalWrite

Exercise 12 - Traffic light with button

Traffic light with button Script //Exercise 12 - Traffic light with button // Sourced from McRoberts, Michael. 'Beginning Arduino. 2nd Ed.' Project 4 int carRed = 12; // assign the car lights int carYellow = 11; int carGreen = 10; int pedRed = 9; // assign the pedestrian lights int pedGreen = 8; int button = 2; // button pin int crossTime = 5000; // time alloyoud to cross unsigned long changeTime; // time since button pressed void setup() { pinMode(carRed, OUTPUT); pinMode(carYellow, OUTPUT); pinMode(carGreen, OUTPUT); pinMode(pedRed, OUTPUT); pinMode(pedGreen, OUTPUT); pinMode(button, INPUT); // button on pin 2 // turn on the green light digitalWrite(carGreen, HIGH); digitalWrite(pedRed, HIGH); } void loop() { int state = digitalRead(button); /* check if button is pressed and it is over 5 seconds since last button press */ if (state == HIGH && (millis() - changeTime) > 5000) { // Call the function to change the lights changeLights(); } void changeLights() { digitalWrite(carGreen, LOW); // green off digitalWrite(carYellow, HIGH); // yellow on delay(2000); // wait 2 seconds digitalWrite(carYellow, LOW); // yellow off digitalWrite(carRed, HIGH); // red on delay(1000); // wait 1 second till its safe digitalWrite(pedRed, LOW); // ped red off digitalWrite(pedGreen, HIGH); // ped green on delay(crossTime); // wait for preset time period // flash the ped green for (int x=0; x<10; x++) { digitalWrite(pedGreen, HIGH); delay(250); digitalWrite(pedGreen, LOW); // turn ped red on digitalWrite(pedRed, HIGH); delay(500); digitalWrite(carRed, LOW); // red off delay(1000); digitalWrite(carGreen, HIGH); // record the time since last change of lights changeTime = millis(); // then return to the main program loop

Notes on the code: More on int’s: Unsigned long changeTime – This is a data type variable as we need a wider range of numbers than an integer can give us on an Arduino. Why use different ones? They take up differing amounts of memory in the Arduino and we are limited in how much memory we have Atmega 168 has 1KB, ATmega328 has 2Kb of SRAM Integer can go from -32,768 to 32,767 An unsigned long can go from -2,147,483,648 to 2,147,483,647 What types of data variables are there? See the table…

Data Type RAM Number Range Void keyword N/A Boolean 1 byte 0 to 1 (True/false) Byte 0 to 255 Char -128 to 127 Unsigned char Int 2 byte -32768 to 32767 Unsigned int 0 to 65535 Word Long 4 byte -2147483648 to 2147483647 Unsigned long 0 to 4294967295 Float -3.4028253E+38 to 3.4028235E+38 Double String 1 byte + x Array of chars array Collection of variables