Arduino Digital Out_QUICK RECAP

Similar documents
Disclaimer. Arduino Hands-On 2 CS5968 / ART4455 9/1/10. ! Many of these slides are mine. ! But, some are stolen from various places on the web

Lecture 6. Interfacing Digital and Analog Devices to Arduino. Intro to Arduino

HAW-Arduino. Sensors and Arduino F. Schubert HAW - Arduino 1

TWEAK THE ARDUINO LOGO

Yihao Qian Team A: Aware Teammates: Amit Agarwal Harry Golash Menghan Zhang Zihao (Theo) Zhang ILR01 Oct.14, 2016

Arduino. AS220 Workshop. Part II Interactive Design with advanced Transducers Lutz Hamel

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

.:Twisting:..:Potentiometers:.

Analog Feedback Servos

Computational Crafting with Arduino. Christopher Michaud Marist School ECEP Programs, Georgia Tech

Coding with Arduino to operate the prosthetic arm

Assignments from last week

Servo Sweep. Learn to make a regular Servo move in a sweeping motion.

100UF CAPACITOR POTENTIOMETER SERVO MOTOR MOTOR ARM. MALE HEADER PIN (3 pins) INGREDIENTS

Introduction to. An Open-Source Prototyping Platform. Hans-Petter Halvorsen

Arduino: Sensors for Fun and Non Profit

URM37 Ultrasonik Mesafe Sensörü - Arduino - Raspberry Pi - LattePanda Uyumlu - DFRobot

Interfacing with Other Programming Environments _Processing, _MAXMSP, _PureData,

Preface. If you have any problems for learning, please contact us at We will do our best to help you solve the problem.

Learning Objectives. References 10/26/11. Using servos with an Arduino. EAS 199A Fall 2011

You'll create a lamp that turns a light on and off when you touch a piece of conductive material

Using Servos with an Arduino

1. Introduction to Analog I/O

Attribution Thank you to Arduino and SparkFun for open source access to reference materials.

Lecture 4: Basic Electronics. Lecture 4 Brief Introduction to Electronics and the Arduino

Arduino Sensor Beginners Guide

Arduino Programming Part 3

Introduction to Mechatronics Programming a robot

Arduino Microcontroller Processing for Everyone!: Third Edition / Steven F. Barrett

Figure 1. Digilent DC Motor

URM37 V3.2 Ultrasonic Sensor (SKU:SEN0001)

Design with Microprocessors Year III Computer Science 1-st Semester

Experiment 1: Robot Moves in 3ft squared makes sound and

Community College of Allegheny County Unit 7 Page #1. Analog to Digital

Arduino Advanced Projects

ABCs of Arduino. Kurt Turchan -

LED + Servo 2 devices, 1 Arduino

Arduino Control of Tetrix Prizm Robotics. Motors and Servos Introduction to Robotics and Engineering Marist School

Programming a Servo. Servo. Red Wire. Black Wire. White Wire

Operating Mode: Serial; (PWM) passive control mode; Autonomous Mode; On/OFF Mode

Lab 5: Arduino Uno Microcontroller Innovation Fellows Program Bootcamp Prof. Steven S. Saliterman

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

Basics before Migtrating to Arduino

Servomotor Control with Arduino Integrated Development Environment. Application Notes. Bingyang Wu Mar 27, Introduction

Microcontrollers and Interfacing

Arduino and Servo Motor

CURIE Academy, Summer 2014 Lab 2: Computer Engineering Software Perspective Sign-Off Sheet

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

Understanding the Arduino to LabVIEW Interface

B RoboClaw 2 Channel 30A Motor Controller Data Sheet

FABO ACADEMY X ELECTRONIC DESIGN

Rodni What will yours be?

arduino experimentation kit Arduino Experimenter s Kit SketchBoard Edition

Application Note AN 157: Arduino UART Interface to TelAire T6613 CO2 Sensor

Experimenter s Guide for Arduino

Electronic Prototyping

INTRODUCTION to MICRO-CONTROLLERS

Sidekick Basic Kit for Arduino V2 Introduction

INA169 Breakout Board Hookup Guide

Lab 06: Ohm s Law and Servo Motor Control

Experiment 1 Identification of Components and Breadboard Realization

6Circuit Worksheets SIK BINDER //93

Programming 2 Servos. Learn to connect and write code to control two servos.

Application Note AN 102: Arduino I2C Interface to K 30 Sensor

Setup Download the Arduino library (link) for Processing and the Lab 12 sketches (link).

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

INTRODUCTION to MICRO-CONTROLLERS

.:Getting Started:..:(Blinking LED):.

THE INPUTS ON THE ARDUINO READ VOLTAGE. ALL INPUTS NEED TO BE THOUGHT OF IN TERMS OF VOLTAGE DIFFERENTIALS.

Robotic Arm Assembly Instructions

Robotycs - YLab Robotics Group Toy Hacking Workshop Part 2 November 11, 2015

EE 314 Spring 2003 Microprocessor Systems

02 Digital Input and Output

INTRODUCTION to MICRO-CONTROLLERS

Pulse Width Modulation and

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs Introduction to Arduino

Date Issued: 12/13/2016 iarmc.06: Draft 6. TEAM 1 - iarm CONTROLLER FUNCTIONAL REQUIREMENTS

PWM CONTROL USING ARDUINO. Learn to Control DC Motor Speed and LED Brightness

CONSTRUCTION GUIDE Robotic Arm. Robobox. Level II

Arduino Application: Speed control of small DC Motors

keyestudio keyestudio Mini Tank Robot

Sten-Bot Robot Kit Stensat Group LLC, Copyright 2013

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

Notes on Firmata Communication Protocol

CONSTRUCTION GUIDE IR Alarm. Robobox. Level I

CONSTRUCTION GUIDE Capacitor, Transistor & Motorbike. Robobox. Level VII

About Arduino: About keyestudio:

µchameleon 2 User s Manual

The µbotino Microcontroller Board

Drawbot DC Motor Servo Motor Creative Design 03 Interactive Digital Prototyping Junior Software Academy. 10 Drowbot 121 MIC

NAMASKAR ROBOT-WHICH PROVIDES SERVICE

BEYOND TOYS. Wireless sensor extension pack. Tom Frissen s

Veyron Servo Driver (24 Channel) (SKU:DRI0029)

CPSC 226 Lab Four Spring 2018

ENGN/PHYS 207 Fall 2018 Assignment #5 Final Report Due Date: 5pm Wed Oct 31, 2018

INTRODUCTION TO THE ARDUINO MICROCONTROLLER

RESET SIK GUIDE SCL SCA AREF GND ~11 ~10 13 RX TX ~9 8 7 ~6 ~5 4 ~3 DIGITAL (PWM~) 7-15V ON

Lesson4 Obstacle avoidance car

Intelligent Systems Design in a Non Engineering Curriculum. Embedded Systems Without Major Hardware Engineering

4WD Mobile Platform SKU:ROB0022

Transcription:

Arduino Digital Out_QUICK RECAP

BLINK File> Examples>Digital>Blink int ledpin = 13; // LED connected to digital pin 13 // The setup() method runs once, when the sketch starts void setup() // initialize the digital pin as an output: pinmode(ledpin, OUTPUT); // the loop() method runs over and over again, // as long as the Arduino has power void loop() digitalwrite(ledpin, HIGH); // set the LED on delay(1000); // wait for a second or 1000 milliseconds digitalwrite(ledpin, LOW); // set the LED off delay(1000); // wait for a second or 1000 milliseconds

Arduino Digital In and Out

Pull Up Resistor A pull-up resistor weakly pulls the voltage of the wire it is connected to towards its voltage source level when the other components on the line are inactive. When all other connections on the line are inactive, they are highimpedance and act like they are disconnected Arduino will read HIGH until circuit is activated and it will switch to LOW. Pull Down Resistor A pull-down resistor is connected to ground, and holds the logic signal near zero volts when no other active device is connected. Arduino will read LOW until circuit is activated and it will switch to HIGH.

FILE> Examples>Digital>Button DIGITAL IN_BUTTON int buttonpin = 2; // the number of the pushbutton pin int ledpin = 13; // the number of the LED pin int buttonstate = 0; // variable for reading the pushbutton status void setup() // initialize the LED pin as an output: pinmode(ledpin, OUTPUT); // initialize the pushbutton pin as an input: pinmode(buttonpin, INPUT); void loop() // read the state of the pushbutton value: buttonstate = digitalread(buttonpin); // check if the pushbutton is pressed. // if it is, the buttonstate is HIGH: if (buttonstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW);

ARDUINO_Internal Pull Up Resistor int buttonpin = 2; // the number of the pushbutton pin int ledpin = 13; // the number of the LED pin int buttonstate = 0; // variable for reading the pushbutton status void setup() // initialize the LED pin as an output: pinmode(ledpin, OUTPUT); // initialize the pushbutton pin as an input: pinmode(buttonpin, INPUT); //turns on the pullup resistor on buttonpin digitalwrite(buttonpin, HIGH); arduino 1.0.1: void setup() // initialize the LED pin as an output: pinmode(ledpin, OUTPUT); // initialize the pushbutton pin as an input: pinmode(buttonpin, INPUT_PULLUP ); void loop() // read the state of the pushbutton value: buttonstate = digitalread(buttonpin); // check if the pushbutton is pressed. // if it is, the buttonstate is HIGH: if (buttonstate == HIGH) // turn LED on: digitalwrite(ledpin, HIGH); else // turn LED off: digitalwrite(ledpin, LOW);

Arduino Analog In and Out

DIGITAL AND ANALOG I/O ON THE BOARD A OUT A OUT DIGITAL I/O A O U T ANALOG IN

ANALOG DIGITAL CONVERTERS (ADCs) _ADC is an electronic device that converts an input analog voltage (or current) to a digital number proportional to the magnitude of the voltage or curren _Arduino has a built in 10-bit ADC which keeps checking the value of the voltage input and returns back the values. It takes (0.0001 s) per reading. 10,000 readings / sec.

Pulse Width Modulation(PWM) _Digital way of getting an analog current supply. _ a PWM variable-power scheme switches the power quickly between fully on and fully off _Pulse: sudden increase and decrease in current flow. _ The term duty cycle describes the proportion of on time to the regular interval or period of time; a low duty cycle corresponds to low power, because the power is off for most of the time _Low (0-255) High

DIGITAL I/O pinmode(pin#, INPUT/OUTPUT); //assigns pin as input or output digitalwrite(pin#, STATE: HIGH/LOW); //OUTPUT digitalread(pin#); //INPUT ANALOG I/O analogwrite(pin#, the duty cycle: 0 (always off)-255 (always on)); //OUTPUT analogread(pin#); //INPUT

ANALOG OUT_PWM int analogpin = 9; void setup() Serial.begin(9600); void loop() analogwrite(analogpin, 0); //0% delay(1000); analogwrite(analogpin, 64); //25% delay(1000); analogwrite(analogpin, 127); //50% delay(1000); analogwrite(analogpin, 191); //75% delay(1000); analogwrite(analogpin, 255); //100% delay(1000);

Voltage Divider How is it used with Arduino? point between the fixed pulldown or pullup resistor and the variable resistor is connected to the analog input of a microcontroller Why do you need it? fixed resistor scales the values of variable resistor by referencing two voltages: 5V and 0V. fixed resistor Values are LOW to HIGH 0-255 variable resistor

ANALOG IN_variable resistor FILE> Examples> Analog> AnalogInput int sensorpin = 0; // select the input pin for the potentiometer int ledpin = 9; // select the PWM pin for the LED int sensorvalue = 0; // variable to store the value coming from the sensor void setup() Serial.begin(9600); void loop() // read the value from the sensor sensorvalue = analogread(sensorpin); //prints sensor value to program notification area using Serial.print or Serial.println Serial.println(sensorValue); delay(500); // turn the ledpin on according to potentiometer s modulation analogwrite(ledpin, sensorvalue);

int sensorpin = 0; int ledpin = 9; Scaling Values_Software // select the input pin for the potentiometer // select the PWM pin for the LED int sensorvalue = 0; // variable to store the value coming from the sensor int outputdata = 0; // Assigning integer value to the variable outputdata void setup() Serial.begin(9600); void loop() // read the value from the sensor sensorvalue = analogread(sensorpin); // map it to the range of the analog out outputdata = map(sensorvalue, 0, 1023, 0, 255); // turn the ledpin on according to potentiometer s modulation analogwrite(ledpin, sensorvalue);

SERVOS

SERVO TYPES Regular Servo: _Can only rotate from 0-180 _position can be tracked by rotation angle _direction can be controlled by incrementing or descreasing rotation angle. Continous Rotation: _lose position tracking _gain 0-360 rotation, speed, and direction

FILE> Examples>Servo> Sweep SERVOS_SWEEP #include <Servo.h> Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position void setup() myservo.attach(9); // attaches the servo on pin 9 to the servo object void loop() for(pos = 0; pos < 180; pos ++) //goes from 0 degrees to 180 degrees in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable pos delay(15); // waits 15ms for the servo to reach the position for(pos = 180; pos>=1; pos--) // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable pos delay(15); // waits 15ms for the servo to reach the position

SERVOS_using variable resistor http://www.arduino.cc/playground/componentlib/servo #include <Servo.h> Servo myservo; //create servo object to control a servo int potpin = 0; // analog pin used to connect the potentiometer int val = 0; // variable to read the value from the analog pin void setup() myservo.attach(2); // attaches the servo on pin 2 to the servo object void loop() val = analogread(potpin); // reads the value of the potentiometer (value between 0 and 1023) val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there

SERIAL COMMUNICATION Bits, Bytes, Data Rates and Protocols ASCI interpretation Using terminal to view serial Data Serial Out from Arduino Serial In to Processing, PD, Max/MSP, Flash

SERIAL COMMUNICATION _creates a data stream by sending one bit at a time _occurs sequentially H...E...L...L...O The first to be recieved is H then E and so on.

SERIAL COMMUNICATION_ARDUINO RX Receiving Data TX Transmitting Data

Time to Talk with Arduino board! _Program to let Arduino say Hello World! _Baud Rate is the rate at which data is sent and recieve, must be synced between the two devices that are communicating _Bit per second (baud rate) _Note that this communication baud rate is independent of the upload process, which is fixed at 19200 bps.

Sending Serial Data Serial.println( something ); print and println is writing data to the serial port. println writes a \n(newline) at the end of each statement equivalant to a serial.write(); in other programming langauages

int val = 0; void setup() Serial.begin(9600); void loop() val = analogread(0); Serial.print(val); Serial.println(); Sending Serial Data to Processing IDE PROCESSING CODE: import processing.serial.*; Serial myport; String instring; float val; int lf = 10; void setup() size(200, 200); String portname = Serial.list()[0]; myport = new Serial(this, portname, 9600); myport.clear(); void draw() // Create object from Serial class // Data received from the serial port // ascii code for linefeed background(255); // Set background to white val = map(val, 0, 1023, 0, 255); fill(int(val)); //typecast float to int rect(50, 50, 100, 100); /*built in function within processing called when data is available which can be set with buffer() to only trigger after a certain number of data elements are read and can be set with bufferuntil() to only trigger after a specific character is read to be used with one of the Read() functions*/ void serialevent(serial p) myport.bufferuntil(lf); instring = p.readstring(); print( received: +instring); val = float(instring); println( val); //buffer until linefeed (println) //typecast string type to float

Arduino_receiving data via Serial.Available int incomingbyte = 0; // for incoming serial data void setup() Serial.begin(9600); // opens serial port, sets data rate to 9600 bps void loop() // send data only when you receive data: if (Serial.available() > 0) // read the incoming byte: incomingbyte = Serial.read(); // say what you got: Serial.print( I received: ); Serial.println(incomingByte); else Serial.println( Nothing );

SERIAL READ_switch case Code: http://arduino.cc/en/tutorial/switchcase2

EXAMPLES > CONTROL> SWITCHCASE2 void setup() // initialize serial communication: Serial.begin(9600); // initialize the LED pins: for (int thispin = 2; thispin < 7; thispin++) pinmode(thispin, OUTPUT); SERIAL READ_switch case void loop() // read the sensor: if (Serial.available() > 0) int inbyte = Serial.read(); /*do something different depending on the character received. The switch statement expects single number values for each case; in this exmaple, though, you re using single quotes to tell the controller to get the ASCII value for the character. For example a = 97, b = 98, and so forth:*/ switch (inbyte) case a : digitalwrite(2, HIGH); break; case b : digitalwrite(3, HIGH); break; case c : digitalwrite(4, HIGH); break; case d : digitalwrite(5, HIGH); break; case e : digitalwrite(6, HIGH); break; default: // turn all the LEDs off: for (int thispin = 2; thispin < 7; thispin++) digitalwrite(thispin, LOW);

SERIAL FLUSH Flushes the buffer of serial port, when sending or recieving any call to Serial method will return only data received after all the most recent call to Serial.flush(): Serial.println( Hello! ); Serial.flush(); will pass Hello! \n to Serial buffer before doing anything else to the Serial buffer.