Application of Programming: Scratch & Arduino

Slides:



Advertisements
Similar presentations
Lab7: Introduction to Arduino
Advertisements

Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
How to use Arduino By: Andrew Hoffmaster.
Embedded Sumo 1T4 – 1T5 UTRA.
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.
1 Ultrasonic Distance Sensor. 2 How it Works The distance sensor emits short bursts of sound and listens for this sound to echo off of nearby objects.
Embedded Programming and Robotics
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Arduino Part 2 Topics: Serial Communication Programming Constructs: functions, loops and conditionals Digital Input.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
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.
1 - Remove LED from 13 and GND - Bring out your breadboard from HW#4 Arduino Overview:
Arduino The Internet of Things: Using the Arduino to Teach Coding.
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.
Introduction to Arduino A very basic intro to Arduino, the IDE and the Servos class.
Istituto Tecnico Industriale A.Monaco EURLAB Object Detection Object Detection by Ultrasonic How to install and program a ultra sonic sensor with Arduino.
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw.
1 Microcontrollers. 2 Programmers work in the virtual world Machinery works in the physical world Microcontrollers connect the virtual and physical world.
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.
Prototyping with Microcontrollers and Sensors. Overview Objective Background Information Problem Statement Materials Procedure Assignment Closing.
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
The Internet of Things: Using the Arduino to Teach Coding
Having fun with code, using Arduino in a middle school CS classroom
Arduino.
By Rick Darby Sponsors: Geekspace Gwinnett The WorkSpot
Controlling Servos with the Arduino
Assist. Prof. Rassim Suliyev - SDU 2017
Prototyping with Microcontrollers and Sensors
Microcontroller basics
If you want to swing an robot arm or …
Microcontroller basics
Manual for Arduino Kit v1.0
Microprocessors Tutorial 1: Arduino Basics
Arduino & its hardware interfacing
UTA010 : Engineering Design – II
Sensors with Arduino A Microcontroller.
Welcome to Arduino A Microcontroller.
Get Your Project Started with Arduino
Arduino Development for Beginners
UCD ElecSoc Robotics Club 2017/2018
Arduino Part 1 Topics: Microcontrollers Programming Basics
INC 161 , CPE 100 Computer Programming
Arduino - Introduction
Arduino Uno and sensors
Introduction to Arduino Microcontrollers
Introduction to Arduino Microcontrollers
How to avoid catching things on fire.
Roller Coaster Design Project
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.
What is an Arduino ? Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Schedule 8:00-11:00 Workshop: Arduino Fundamentals
What is Arduino? By James Tedder.
Arduino 101 Credit(s):
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Welcome to Digital Electronics using the Arduino Board
Chapter 1 Introduction of Arduino
Arduino : Introduction & Programming
Programming 2: The Arduino IDE & First Sketches
Arduino Practice: Photoresistors, PWM, Potentiometers, Motors
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Aeroponic Engineering and Vertical Farming
Lab #1: Getting Started.
Arduino Uno circuit basics
Introduction to Arduinos
Introduction to arduino
Presentation transcript:

Application of Programming: Scratch & Arduino Dr. Hong Sun Hag Professor Seoil University

Open Source Platform?

An assortment of common input & output components

Common components like helping us build functional electronic circuits

A sampling of wires & accessories for power and circuitry

BASICS OF ELECTRICITY AND CIRCUITS As the name suggests, an electronic circuit is circular. Electrons flow from the positive end of the power source (for example, a battery) around the circuit to the negative end of the same power source. The easiest way to understand the physics of what is happening inside an electric circuit is to compare it to a water tank system. Water in a pipe flows just like electrons in a wire. These electrons are what form the electric current that powers the components of the circuit.

Ex.1 LED Blink You will need: 1 × Arduino UNO 1 × solderless breadboard 1 × standard LED 1 × 220 Ohm resistor 2 × jumper cables

To start the circuit, connect a jumper wire from pin 10 on the Arduino To start the circuit, connect a jumper wire from pin 10 on the Arduino. This is the point at which the Arduino starts talking to the circuit. You can use any numbered pin from the right side of the Arduino — just make sure your code refers to the correct one. To make sure the ideal amount of current flows through the LED, the resistor is needed. Unlike the LED, it doesn’t matter which way it is inserted into the circuit. Whether pin 10 is allowing current through or not (controlled by your code) will determine whether the LED is on or off. Another jumper wire then connects to the negative side of the LED and returns to ground to complete the circuit. Simple! Once completed, your circuit should look something like the image below. Plug this into your computer via USB. The next task is to set up the Arduino to work with software coding.

LED_Blink.ino /* Blink - Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care of use the correct LED pin whatever is the board used. If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at https://www.arduino.cc/en/Main/Products This example code is in the public domain. modified 8 May 2014 by Scott Fitzgerald modified 2 Sep 2016 by Arturo Guadalupi */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(10, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(10, LOW); // turn the LED off by making the voltage LOW

Tools -> Board Tools -> Serial Port Sketch -> Verify/Compile

Bluetooth Paring Test We need 4 wires to connect Vcc (+5V) GND TX Rx

// Arduino code for basic Bluetooth test. << BT_test // Arduino code for basic Bluetooth test. << BT_test.ino >> #include <SoftwareSerial.h> SoftwareSerial BTSerial(2, 3); //Connect HC-06. Use your (TX, RX) settings void setup() { Serial.begin(9600); Serial.println("Hello!"); BTSerial.begin(9600); // set the data rate for the BT port } void loop() // BT –> Data –> Serial if (BTSerial.available()) { Serial.println(BTSerial.read()); // Serial –> Data –> BT if (Serial.available()) { BTSerial.write(Serial.read());

At Google Play, Install app -> BlueTerm When finished the installation of BlueTerm, Android phone may connect with HC-06 of Arduino by pairing Pin number : 1234 Device number : *****(e.g. smu001 .. )

Pairing When pairing completes, You may click the serial monitor window like below figure.

Ex.2 LED Control You will need: 1 × Arduino UNO 1 * Bluetooth HC-06 1 × solderless breadboard 1 × standard LED 1 × 220 Ohm resistor 2 × jumper cables

<< LED_BT.ino >> #include <SoftwareSerial.h> SoftwareSerial BTSerial(2,3); byte a=0; int LED=8; void setup(){ Serial.begin(9600); Serial.println("Hello!"); BTSerial.begin(9600); pinMode(LED,OUTPUT); } void loop(){ if(BTSerial.available()){ a = BTSerial.read(); BTSerial.write(a); if(a==49){ BTSerial.write("led on "); digitalWrite(LED,HIGH); if(a==48){ BTSerial.write("led off "); digitalWrite(LED,LOW); << LED_BT.ino >>

Ex.3 Digital Switch You will need: 1 × Arduino UNO 1 × solderless breadboard 1 × standard switch 1 × 10K Ohm resistor 2 × jumper cables

<< Switch_BT.ino >> #include <SoftwareSerial.h> SoftwareSerial BTSerial(2,3); int button = 13; // Pin setup void setup(){ Serial.begin(9600); Serial.println("Hello!"); BTSerial.begin(9600); pinMode(button,INPUT); } void loop(){ if(digitalRead(button) == LOW) { BTSerial.write("0"); if(digitalRead(button) == HIGH) BTSerial.write("1"); << Switch_BT.ino >>

Ex.4-1 LDR Serial Monitoring

// These constants won't change. << LDR_Serial.ino >> const int analogInPin = A1; // Analog input pin that the potentiometer is attached to const int analogOutPin = 9; // Analog output pin that the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(analogOutPin, outputValue); // print the results to the serial monitor: Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); // wait 2 milliseconds before the next loop, for the analog-to-digital converter to settle // after the last reading: delay(20);

Ex.4-2 LDR B/T Monitoring You will need: 1 × Arduino UNO 1 * Bluetooth HC-06 1 × breadboard 1 × LDR 1 × 4.7K Ohm resistor 2 × jumper cables

// << LDR_BT.ino >> #include <SoftwareSerial.h> SoftwareSerial BTSerial(2, 3); //Connect HC-06. (TX, RX) settings void setup() { Serial.begin(9600); Serial.println("Hello!"); BTSerial.begin(9600); // set the data rate for the BT port } void loop() int light = analogRead(A5); BTSerial.println(light); delay(200);

Ex.5 Ultra Sonic Monitoring

// << Sonic_Serial.ino >> #define ECHOPIN 2 // echo pulse receive pin #define TRIGPIN 3 // trigger signal sending pin void setup(){ Serial.begin(9600); pinMode(ECHOPIN, INPUT); pinMode(TRIGPIN, OUTPUT); } void loop(){ digitalWrite(TRIGPIN, LOW); // trigger pin 2[uS] “LOW” delayMicroseconds(2); digitalWrite(TRIGPIN, HIGH); // “ranging” triggering 10[uS] “HIGH” delayMicroseconds(10); digitalWrite(TRIGPIN, LOW); // trigger pin “LOW” int distance = pulseIn(ECHOPIN, HIGH); // pulse time reading distance= distance/58; // calculate distance via pulse time Serial.println(distance); delay(50); // waiting 50[mS] for next action

Ex.6 Motor B/T Controlling

#include <SoftwareSerial.h> // << Motor_BT.ino >> SoftwareSerial BTSerial(8, 9); const int motorPins = 3; // motor connect D3 void setup() { BTSerial.begin(9600); } void loop() { if (BTSerial.available()) { char ch = BTSerial.read(); if(ch >= '0' && ch <= '9') // “ch”is number 0 ~9 int speed = map(ch, '0', '9', 0, 255); // Convert 0~9 to 0~255 analogWrite(3, speed); BTSerial.println(" "); BTSerial.println(speed); else { BTSerial.print("Unexpected character "); BTSerial.println(ch); } }

Q/A & Have a Good Time!!

Dr. Hong Sun Hag Professor at Seoil Univesity hongsh@seoil.ac.kr