LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.

Slides:



Advertisements
Similar presentations
EMS1EP Lecture 6 Digital Inputs
Advertisements

EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
EMS1EP Lecture 8 Pulse Width Modulation (PWM)
Lecture 1 – Arduino Basics
Lab7: Introduction to Arduino
ARDUINO FRAMEWORK.
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
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.
ELCT 201 week 13 Analog ON/OFF control system conversion to Digital ON/OFF control system.
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.
Beginning Arduino Session 2 AN INTRODUCTION TO HACKING THE WORLD’S MOST POPULAR MICROCONTROLLER PLATFORM
Finish your programs from last week STOPLIGHT CIRCUIT! You may need … – int – void setup() – void loop() – pinMode – digitalWrite – delay.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Physics 120B: Lecture 2 Topics and Techniques for Week 1 Lab.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
Arduino John Marcoux Christopher Lesch Thomas Dodge Unless otherwise noted, all information and pictures came from:
Lecture 9: Microcontrollers – part 1 BJ Furman 29OCT2012.
chipKit Sense Switch & Control LED
ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Pulse Width Modulation (PWM). 100% Pulse Width Modulation (PWM) 0% On the chipKIT there are 490 periods per second. Use analogWrite(pin, value) to control.
Lecture 7: Microcontrollers & I/O Bryan Burlingame 14 October 2015.
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
Arduino Circuits and Code. int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, LOW); delay(1000); digitalWrite(ledPin,
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.
Timer 1 and 2 operation, PWM Principles. Timer 1 Operation.
Embedded Programming and Robotics Lesson 11 Arduino Interrupts 1.
Motor TYWu.
Microcontroller basics Embedded systems for mortals.
Microcontroller basics Embedded systems for mortals.
Lecture 9: Introduction to Arduino Topics: Arduino Fundamentals, Bean Date: Mar 22, 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.
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
:Blink Blink: Er. Sahil Khanna
ARDUINO 실습 과제 보 고서. PWM 은 아날로그 출력이라는 함수를 사용하게 되는데 이 출력에는 3, 5, 6, 9, 10, 11 번의 핀만 사용 가능. ( 숫자 옆 에 ~ 표시 )
Pulse-Width Modulation: Simulating variable DC output
Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw.
Lab 7 Basic 1: Game of Memory
Introduction to Physical Computing
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
More on LED’s with Arduino
Microcontroller basics
Exploring lighting effects with LED’s and Arduino
Microcontroller basics
Get Your Project Started with Arduino
European Robotic LABoratory
Lab 1: Arduino Basics Topics: Arduino Fundamentals, First Circuit
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Introduction to Arduinos
Topics: Analog/Digital Read Relay control 7 segment control Buzzer
What is an Arduino ? Open Source electronic prototyping platform based on flexible easy to use hardware and software.
IoT Programming the Particle Photon.
Create a paper craft for any object that makes a sound
Servos and Stepper Motors
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Arduino : Introduction & Programming
Arduino Practice: Photoresistors, PWM, Potentiometers, Motors
Sensors and actuators Sensors Resistive sensors
(Dr. Öğr. Üyesi Deniz Dal)
Setting up a basic program with Arduino
Introduction to Arduinos
Arduino程式範例.
Interrupts.
Pulse-Width Modulation: Simulating variable DC output
Presentation transcript:

LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.

SIGNAL TYPES Digital Analogue

DIGITAL SIGNALS Only two possible values Information is transmitted by a series of HIGHs and LOWs In the case of an Arduino its 5V and 0V Beware! That not all devices use 5v

ANALOGUE SIGNALS (THE PROPER SPELLING) Can have ANY value Information can be transmitted by the amplitude as well as the order of the signal The Arduino can read an analogue signal but it cannot output true analogue (more on that in a bit)

PWM – PULSE WIDTH MODULATION

BUZZER – BACK WITH A VENGEANCE void setup() { //Nothing to see here, move along } int toneDuration = 3; //In milliseconds int buzzerPin = 2 void loop() { for (int freq = 400; freq<1500; freq+=10) { tone(buzzerPin, freq); delay(toneDuration*1.3); noTone(buzzerPin); }

DIGITAL INPUT int buttonPin = 2; int ledPin = 13; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); } void loop() { int buttonState = digitalRead(buttonPin); digitalWrite(ledPin, buttonState); }

DIGITAL INPUT int buttonPin = 2; // the number of the pushbutton pin int ledPin = 13; // the number of the LED pin int ledState = HIGH; // the current state of the output pin int buttonState; // the current reading from the input pin void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); } void loop() { int reading = digitalRead(buttonPin); // if the button state has changed: if (reading != buttonState) { buttonState = reading; // only toggle the LED if the new button state is LOW if (buttonState == LOW) { ledState = !ledState; } digitalWrite(ledPin, ledState); // set the LED }

BUTTON BOUNCE You may have noticed an issue with the last circuit/code where the led would trigger multiple times with one press. Unfortunately we don’t live in the ideal world. When you press the button it actually bounces a bit before making proper contact. This can be solved in either software or hardware. Depending on your situation each has its merits

SOFTWARE DEBOUNCE int buttonPin = 2; // the number of the pushbutton pin int ledPin = 13; // the number of the LED pin int ledState = HIGH; // the current state of the output pin int buttonState; // the current reading from the input pin int lastButtonState = LOW; // the previous reading from the input pin long lastDebounceTime = 0; // the last time the output pin was toggled long debounceDelay = 50; // the debounce time; increase if the output flickers void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); } void loop() { int reading = digitalRead(buttonPin); // If the switch changed, due to noise or pressing if (reading != lastButtonState) { lastDebounceTime = millis(); // reset the debouncing timer } if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state // if the button state has changed if (reading != buttonState) { buttonState = reading; // only toggle the LED if the new button state is LOW if (buttonState == LOW) ledState = !ledState; } digitalWrite(ledPin, ledState); // set the LED lastButtonState = reading; // save the reading }

ANALOGUE INPUT void setup() { //These are not the droids you are looking for } int potentiometerPin = A0; void loop() { int potentiometerVal = analogRead(potentiometerPin); int outputVal = map(potentiometerVal, 0, 1024, 0, 255); analogWrite(10, outputVal); }

FINAL CHALLENGES Make a button toggle between a buzzer output and a LED output Make the RGB LED fade colours based on the potentiometer (Don’t spend too long on this one, the next one is more fun) Make a “safe” using the potentiometer to enter the combination and press a button to unlock. Have a green and red LED to display whether the safe is locked or unlocked. If the wrong combination is entered 3 times an alarm should sound.