Assist. Prof. Rassim Suliyev - SDU 2017

Slides:



Advertisements
Similar presentations
Lab7: Introduction to Arduino
Advertisements

How to use Arduino By: Andrew Hoffmaster.
Digital & Analog Inputs. Review Fundamental parts of an Arduino program are … Setting output types using pinMode. Declaring variables Can write a digital.
Arduino. Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. It's an open-source.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
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.
PROGRAMMING WITH ARDUINO. Arduino An open-source hardware platform based on an Atmel AVR 8-bit microcontroller and a C++ based IDE Over boards.
Embedded Programming and Robotics
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Dean Brock, Rebecca Bruce and Susan Reiser, CCSC SE 2009 Using Arduino Material taken from Todbot blog Bionic Arduino Todbot blog Bionic ArduinoTodbot.
Week 10 Today 1.Homework presentations and critique. 2.Review digital and analog inputs. 3.DIY - jumpers, soldering etc.
Microprocessors Tutorial 1: Arduino Basics
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS.
Microprocessors Tutorial 1: Arduino Basics
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.
Arduino Circuits and Code. int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, LOW); delay(1000); digitalWrite(ledPin,
1 - Remove LED from 13 and GND - Bring out your breadboard from HW#4 Arduino Overview:
Rebecca Bruce and Susan Reiser, May 2015 Analog Input and Output.
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.
Embedded systems and sensors 1 Part 2 Interaction technology Lennart Herlaar.
Microcontroller basics Embedded systems for mortals.
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 “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Controlling an LED with a switch. 2 breadboard place where you can build electric circuits really quickly the magical breadboard.
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 Programming. THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER.
physical computing .2 – Day 3
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
Microcontrollers & Electronics Basics OR…
Having fun with code, using Arduino in a middle school CS classroom
Arduino.
Getting Started: Building & Programming
Application of Programming: Scratch & Arduino
Prototyping with Microcontrollers and Sensors
Microcontroller basics
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
Wireless Cue Light Project
Microprocessors Tutorial 1: Arduino Basics
Microcontroller basics
UTA010 : Engineering Design – II
Get Your Project Started with Arduino
UCD ElecSoc Robotics Club 2017/2018
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
How to avoid catching things on fire.
Analog Input through POT
Roller Coaster Design Project
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.
Week 6: Microcontrollers II
IoT Programming the Particle Photon.
Chapter 2 Push button and Potentiometer
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Arduino programs Arduino toolchain Cross-compilation Arduino sketches
Programming 2: The Arduino IDE & First Sketches
Arduino Practice: Photoresistors, PWM, Potentiometers, Motors
Arduino Part 4 Let there be more light.
Sensors and actuators Sensors Resistive sensors
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Aeroponic Engineering and Vertical Farming
Lab #1: Getting Started.
Arduino Uno circuit basics
Setting up a basic program with Arduino
Interrupts.
Presentation transcript:

Assist. Prof. Rassim Suliyev - SDU 2017 Embedded SYstems Week 4 Assist. Prof. Rassim Suliyev - SDU 2017

Simple Digital and Analog Inputs The Arduino’s ability to sense digital and analog inputs allows it to respond to you and to the world around you Digital input pins sense the presence and absence of voltage on a pin Analog input pins measure a range of voltages on a pin

Simple Digital and Analog Inputs digitalRead(pin) - tells your sketch if a voltage on a pin is HIGH (5 volts) or LOW (0 volts) pinMode(pin, INPUT) – configure pin as an INPUT 14 digital pins (numbered 0 to 13) Pins 0 and 1 (marked RX and TX) are used for the USB serial connection Need more? Analog pins 0 through 5 can be used as digital pins 14 through 19

Simple Digital and Analog Inputs Still need more? Analog pins 0 through 15 are digital pin numbers 54 through 69

Sensors & Inputs Many sensors are variations on switches Switches make or break a connection Single pole = only one circuit is being controlled Double pole = two circuits are being controlled at once Single throw = only one path for circuit Double throw = two potential paths for circuit

Many Kinds of Switches Tilt sensor has a little ball inside Magnetic switches are delicate The hex switch is actually many switches in one, and outputs 4 signals

Digital Input Switches make or break a connection But Arduino wants to see a voltage Specifically, a “HIGH” (5 volts) or a “LOW” (0 volts) How do you go from make/break to HIGH/LOW?

From Switch to HIGH / LOW With no connection, digital inputs “float” between 0 & 5 volts (LOW & HIGH) Resistor “pulls” input to ground (0 volts) Pressing switch “pushes” input to 5 volts Press is HIGH Not pressed is LOW Pull-down resistor

Pull-up and Pull-down pull-up resistors – pull the voltage up to the 5V line that the resistor is connected to pull-down resistors – pull the voltage down to 0 volts Although 10K ohms is a commonly used value, anything between 4.7K and 20K or more will work

Control the Blinking Connect a button to pin 2 with a pull-down resistor Turn on LED if button pressed and OFF if released

Control the Blinking // Pushbutton sketch a switch connected to pin 2 lights the LED on pin 13 const int ledPin = 13; // choose the pin for the LED const int inputPin = 2; // choose the input pin (for a pushbutton) void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare pushbutton as input } void loop(){ int val = digitalRead(inputPin); // read input value If (val == HIGH) { // check if the input is HIGH digitalWrite(ledPin, HIGH); // turn LED on if switch is pressed } else { digitalWrite(ledPin, LOW); // turn LED off

Let’s Wire It Up Going from schematic to physical circuit.

Solderless Breadboards

Useful Tools

Making Jumper Wires

Using Solderless Breadboards Using needle nose pliers can help push wires & components into holes

All Wired Up

Using Switches to Make Decisions Often you’ll want to choose between actions, based on a data obtained from switch-like sensor E.g. “If motion is detected, turn on the lights” E.g. “If flower pot soil is dry, turn on sprinklers” Define actions, choose them from sensor inputs Let’s try that with the actions we currently know E.g.: If button is pressed send “Hello!” to serial port, and if released send “Goodbye!”

Control the Blinking (pull-up)

Switch Without External Resistors Arduino has internal pull-up resistors that can be enabled by writing a HIGH value to a pin that is in INPUT mode const int ledPin = 13; const int inputPin = 2; void setup() { pinMode(ledPin, OUTPUT); pinMode(inputPin, INPUT); digitalWrite(inputPin,HIGH); // turn on internal pull-up } void loop(){ int val = digitalRead(inputPin); if (val == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW);

Reliably Detecting the Switch State contact bounce produces spurious signals at the moment the switch contacts close or open avoid false readings due to contact bounce - debouncing boolean debounce(int pin) { boolean state; boolean previousState; previousState = digitalRead(pin); // store switch state for(int cnt=0; cnt < debounceDelay; cnt++) { delay(1); // wait for 1 millisecond state = digitalRead(pin); // read the pin if( state != previousState) { cnt = 0; // reset the counter if the state changes previousState = state; // and save the current state } return state;

Analog Input To computers, analog is chunky

Analog Input Many states, not just two (HIGH/LOW) Number of states (or values, or “bins”) is resolution Common computer resolutions: 8-bit = 256 values 16-bit = 65,536 values 32-bit = 4,294,967,296 values

Analog Input Arduino (ATmega168) has six ADC inputs (ADC = Analog to Digital Converter) Reads voltage between 0 to 5 volts Resolution is 10-bit (1024 values) In other words, 5/1024 = 4.8 mV smallest voltage change you can measure

Analog Input Sure sure, but how to make a varying voltage? With a potentiometer. (pot)

Potentiometers Moving the knob is like moving where the arrow taps the voltage on the resistor When a resistor goes across a voltage difference, like +5V to Gnd, the voltage measured at any point along a resistor’s length is proportional to the distance from one side.

What good are pots at? Anytime you need a ranged input Measure rotational position steering wheel, robotic joint, etc. But more importantly for us, potentiometers are a good example of a resistive sensor

Arduino Analog Input Plug pot directly into breadboard Two “legs” plug into +5V & Gnd (red + & blue -) buses Middle “post” plugs into a row (row 7 here) Run a wire from that row to Analog In 2

Pot & LED Circuit

Pot Blink Rate /* Pot sketch blink an LED at a rate set by the position of a potentiometer */ const int potPin = 0; // select the input pin for the potentiometer const int ledPin = 13; // select the pin for the LED int val = 0; // variable to store the value coming from the sensor void setup(){ pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT } void loop() { val = analogRead(potPin); // read the voltage on the pot digitalWrite(ledPin, HIGH); // turn the ledPin on delay(val); // blink rate set by pot value (in milliseconds) digitalWrite(ledPin, LOW); // turn the ledPin off delay(val); // turn led off for same period as it was turned on