Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”

Slides:



Advertisements
Similar presentations
Wireless Cue Light Project
Advertisements

Khaled A. Al-Utaibi Interfacing an LED The Light Emitting Diode (LED) Applications DC Characteristics & Operation Interfacing to.
Button Input: On/off state change Living with the Lab Gerald Recktenwald Portland State University
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.
Electrical team Arduino tutorial I BY: JOSHUA arduini
Lab7: Introduction to Arduino
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)
Embedded Sumo 1T4 – 1T5 UTRA.
Panasonic EVE-KC2F2024B 24 pulses per revolution 6mm diameter flattened output shaft output type: quadrature (incremental) minimum life: 15,000 rotations.
Re-programming the Simon Says with Arduino Linz Craig, Brian Huang.
Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the.
Intro to Arduino with LilyPad Make a MakerSpace, Artisan’s Asylum Linz Craig, Chris Taylor, Mike Hord & Joel Bartlett.
Digital Outputs 7-Segment Display
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.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
Embedded Programming and Robotics
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
chipKit Sense Switch & Control LED
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Introduction to the Arduino
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Engineering 1040: Mechanisms & Electric Circuits Winter 2015 Interfacing Light-Emitting Diodes (LEDs) & Push Buttons to Microcontrollers.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.
Code The Arduino Environment.
Digital Inputs Interfacing Keypad
Input Interface – Microprocessor
Arduino libraries Datatekniker Udvidet hardware/software.
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.
1 Introduction to Haptics Introduction to the Hapkit board Allison M. Okamura Stanford University.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
:Blink Blink: Er. Sahil Khanna
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
Having fun with code, using Arduino in a middle school CS classroom
Arduino.
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
Wireless Cue Light Project
Arduino Programming Part II
UTA010 : Engineering Design – II
Get Your Project Started with Arduino
INC 161 , CPE 100 Computer Programming
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Arduino.
Introduction to Arduino Microcontrollers
Introduction to Arduinos
Week 5: Microcontrollers
Week 6: Microcontrollers II
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Arduino programs Arduino toolchain Cross-compilation Arduino sketches
Interfacing a Rotary Encoder with an Arduino
Arduino : Introduction & Programming
CTY SAR FCPS Shawn Lupoli, Elliot Tan
CTY SAR FCPS Shawn Lupoli, Elliot Tan
EXPRESSIONS, PAUSES AND SOUNDS
Digital INPUTS/OUTPUTS and interrupts
Lab #1: Getting Started.
Arduino Uno circuit basics
Introduction to Arduinos
SAURABH GINGADE.
Arduino程式範例.
Introduction to Arduino IDE and Software
Interrupts.
Presentation transcript:

Khaled A. Al-Utaibi

 The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy” Buttons

 The simplest form of digital input is a push button.  You can insert these directly into your breadboard as shown in the next slide.  A push button allows a voltage or current to pass when the button is pressed.  Push buttons are generally used as reset switches and pulse generators.

 A push button can be interface to a circuit using: − (1) Pull-Up Resistors: In this case, the output of the button is normally HIGH and when the button is pressed it generates a LOW pulse (Figure 1). − (2) Pull-Down Resistors: In this case, the output of the button is normally LOW and when the button is pressed it generates a HIGH pulse (Figure 2).

 Programming digital inputs/outputs involves two operations: − (1) Configuring the desired pin as either input or output. − (2) Controlling the pin to read/write digital data.

 Because you’ll generally dedicate each pin to serve as either an input or an output, it is common practice to define all your pins as inputs or outputs in the setup. // set pin 4 as a digital input void setup() { pinMode(9, INPUT); }

 The pinMode() function configures the specified pin to behave either as an input or an output. − Syntax:  pinMode(pin, mode) − Parameters:  pin: the number of the pin whose mode you wish to set.  mode: INPUT or OUTPUT − Returns:  None

 Because the loop() function runs over and over again, inputs are usually read in this function. // read the state of pin 4 int pinState; void loop() { pinState = digitalRead(4); }

 The digitalRead() function reads the value from a specified digital pin, either HIGH or LOW. − Syntax:  digitalRead(pin) − Parameters:  pin: the number of the digital pin you want to read (int). − Return:  HIGH or LOW

 Write an Arduino program that repeatedly reads the state of a push button connected to pin 4 and display the message “Button Pressed” on the Arduino environment’s built-in serial monitor whenever the button is pushed.

// Repeatedly Reads the state of a bush button connected to pin 4, // and displays the message “Button Pressed” whenever the button // is pushed. int buttonState; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an input. pinMode(4, OUTPUT); // initialize and start the serial port Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { buttonState = digitalRead(4); // read the state of pin 4 if (buttonState == HIGH) { // if pin state is HIGH Serial.println(“Button Pressed”); // display the message } }

 Push buttons exhibit a phenomenon called switch bounce, or bouncing, which refers to a button’s tendency to turn on and off several times after being pressed only once by the user.  This phenomenon occurs because the metal contacts inside a push button are so small that they can vibrate after a button has been released, thereby switching on and off again very quickly.  Switch Bounce can cause wrong behavior of digital circuits due to reading multiple values for a single press of the button.

Ideal Switch (No Bounce)Switch Bounce

 There are two approaches for cleaning up switch bounce: − (1) Hardware Debounce − (2) Software Debounce  It is relatively straightforward to deal with switch bounce problem in software.  Hence, we will cover only software switch debouncing.

 Basic Idea: − look for a button state change, wait for the bouncing to finish, and then reads the switch state again.  This software logic can be expressed as follows: − 1. Store a previous button state and a current button state (initialized to LOW). − 2. Read the current button state. − 3. If the current button state differs from the previous button state, wait 5ms because the button must have changed state. − 4. After 5ms, reread the button state and use that as the current button state. − 5. Set the previous button state to the current button state. − 6. Return to step 2.

// Modify previous program to debounce the switch int buttonState; // the current reading from the input pin int previousButtonState = 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; void setup() { pinMode(4, OUTPUT); Serial.begin(9600); } void loop() { // read the state of the switch into a local variable: int reading = digitalRead(4); // If the switch changed, due to noise or pressing: if (reading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { // the reading has been there for longer than the debounce delay, so take it if (reading != buttonState) { buttonState = reading; if (buttonState == HIGH) { // if pin state is HIGH Serial.println(“Button Pressed”); // display the message } } } // save the reading lastButtonState = reading; }

 The millis() function returns the number of milliseconds since the Arduino board began running the current program. − This number will overflow (go back to zero), after approximately 50 days. − Syntax:  millis() − Parameters:  None. − Return:  Number of milliseconds since the program started (unsigned long)