CS4101 Introduction to Embedded Systems Lab 8: Arduino DAC and PWM

Slides:



Advertisements
Similar presentations
EMS1EP Lecture 8 Pulse Width Modulation (PWM)
Advertisements

ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
Chung-Ta King National Tsing Hua University
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.
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 PROGRAMMING Working with the Arduino microcontroller.
DataInputFrom Digital PinsUsing an On/OFF button to control an LEDFrom Analog Pins Reading light intensity using a photocell and turning an LED on and.
Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.
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,
Arduino Training New Mexico Mathematics, Engineering, and Science Achievement (NM MESA) Getting Started.
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.
Final Term Project Hi-Tek Smoke Detektor By: Rohan Sharma.
RGB LED 燈條實驗.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
LAB1 TYWU. Devices Dip Switch (4 Switches) Triple Output LED (RGB) –Common Cathode.
Introduction to Arduino A very basic intro to Arduino, the IDE and the Servos class.
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
ECE Group Members Samantha Starr BME Arduino Arianna Weinshel BME Sensors, Circuits Eden Woldemichael CE AM Radio Taylor Brooke EE Instrumentation,
INTERNET OF EVERYTHING SDU 2016 Week 8. Visual Output  Lets the Arduino show off  Arduino supports a broad range of LED devices  Use digital and analog.
Microcontroller basics Embedded systems for mortals.
1 Transistor. 2 Transistors are used to turn components on and off They come in all different shapes and sizes.
physical computing .2 – Day 3
Lab 7 Basic 1: Game of Memory
Introduction In this lab , we will learn
Outline Introduction to digital-to-analog converter (DAC)
Assist. Prof. Rassim Suliyev - SDU 2017
CS4101 嵌入式系統概論 General Purpose IO
Microcontroller basics
More on LED’s with Arduino
If you want to swing an robot arm or …
Microcontroller basics
CS4101 Introduction to Embedded Systems Lab 10: Tasks and Scheduling
Manual for Arduino Kit v1.0
Exploring lighting effects with LED’s and Arduino
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
Wireless Cue Light Project
Arduino Programming Part II
Microcontroller basics
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Prof. Chung-Ta King Department of Computer Science
Exploring more with LED’s and Arduino
European Robotic LABoratory
Lab 1: Arduino Basics Topics: Arduino Fundamentals, First Circuit
CS4101 嵌入式系統概論 General Purpose IO
INC 161 , CPE 100 Computer Programming
Arduino.
Arduino - Introduction
Control the color and brightness of an RGB LED with a Potentiometer
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 6: Serial Communication Prof. Chung-Ta King Department of Computer Science National.
How to avoid catching things on fire.
Analog Input through POT
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.
IoT Programming the Particle Photon.
Arduino Week 2 Lab ECE 1020 Prof. Ahmadi.
Servos and Stepper Motors
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Chapter 1 Introduction of Arduino
Arduino : Introduction & Programming
Arduino Practice: Photoresistors, PWM, Potentiometers, Motors
Sensors and actuators Sensors Resistive sensors
CTY SAR FCPS Shawn Lupoli, Elliot Tan
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
Arduino Uno circuit basics
Introduction to Arduinos
Interrupts.
Presentation transcript:

CS4101 Introduction to Embedded Systems Lab 8: Arduino DAC and PWM Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan

RGB LED Module Connect to PWM pins (pins with a ‘~’ notation)  Since the RGB mini board already contains built-in resistors, you can connect to Arduino Uno directly. 

Sample Code for RGB LED Duty cycle: 0~255 int redPin = 11, greenPin = 10, bluePin = 9; void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); } void loop() { analogWrite(redPin, 50); analogWrite(greenPin, 100); analogWrite(bluePin, 150); delay(1000); analogWrite(redPin, 0); analogWrite(greenPin, 0); analogWrite(bluePin, 0); Duty cycle: 0~255

Analog Joystick

Sample Code for Analog Joystick int button = 2; int xAxis = A0, yAxis = A1; void setup() { Serial.begin(9600); pinMode(button, INPUT_PULLUP); // LOW when pressed } void loop() { int xVal = analogRead(xAxis); int yVal = analogRead(yAxis); int isPress = digitalRead(button); Serial.print("X="); Serial.print(xVal); Serial.print("Y="); Serial.print(yVal); if( isPress == 0) Serial.print("Button is pressed."); else Serial.print("Button is not pressed."); delay(200); INPUT_PULLUP: use internal pull-up resistors (resistors that connect to power internally)  When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. Because the internal pull-up on pin 2 is active and connected to 5V, we read HIGH when the button is open. When the button is closed, the Arduino reads LOW because a connection to ground is completed.

Stepper Motor: 28BYJ-48 Number of phases: 4 Step angle: 8-step sequence: 5.625° (64 steps per revolution) 4-step sequence: 11.25° (32 steps per revolution) Gear reduction ratio: 1/64 32*64 = 2048 steps per revolution in 4-step sequence NOTE: Arduino "Stepper Library" runs in 4-step mode

Stepper Motor Driver  5V GND Choose 4 pins as input

Sample Code for Stepper Motor #include <Stepper.h> #define STEPS 2048 // for 28BYJ-48 // create an instance of the stepper class Stepper stepper(STEPS, 8, 9, 10, 11); int previous = 0; // previous reading from analog IN void setup() { stepper.setSpeed(5); // set the speed to 5 RPMs } void loop() { int val = analogRead(A0); // get the sensor value // move # of steps equal to change in sensor reading stepper.step(val - previous); // remember the previous value of the sensor previous = val;

Basic 1 Use the analog joystick to control the RGB LED through PWM. Turn the analog joystick and change the light intensity of red and blue LEDs as follows: When the joystick moves down, red LED will be the brightest. When the joystick is up, turn off red LED. When the joystick moves left, blue LED will be the brightest. When the joystick is at the right end, turn off the blue LED. While the joystick is pressed, send 0 V to green pin. Otherwise, send 3 V to green pin.

Basic 2 Glue an arrow shaped paper on a stick and put them on the axis of the stepper motor. Move the arrow corresponding to the input from the analog joystick. If you can only control 4 directions, you will get 70% of the score.