Programming Arduino with Scratch (S4A)

Programming Arduino with Scratch (S4A)

STEM by ART: Teaching Science, Technology, Engineering, Math by ART Programming Arduino with Scratch (S4A) Fotios Gioulekas, Panagiotis Katsaros School of Informatics Aristotle University of Thessaloniki Greece http://stem.lupacovka.cz Computer programming & computer program . Computer programming: Calorie Calculator . act of writing computer programs to solve a problem . Computer program . structured collection of a sequence of instructions written using a Computer Programming Language to tell the computer to do a specific task Robotic arm playing https://www.calculator.net/calorie-calculator.html chess Image taken from: https://www.flickr.com/photos/steve_hoge/5143590110/ 1 Microcontrollers . A microcontroller is a computer system on a single chip that does a job (MCU, μC) . control electronic equipment . exists in electrical device, cars, washing machines, microwave ovens, telephones . includes central processing unit (CPU), memory (a small amount of RAM, program memory, or both), and programmable input/output peripherals, which are used to interact with various units Images taken from: http://d1gsvnjtkwr6dd.cloudfront.net/large/IC-ATMEGA168A-PU_LRG.jpg http://i.stack.imgur.com/whWVa.jpg http://slideplayer.com/slide/5881540/19/images/26/Fixed+Function+Integrated+Circuits+I+(Cont.).jpg 2 Arduino . Arduino is an open-source electronics prototyping platform that contains both hardware and software founded by Massimo Banzi and David Cuartielles in 2005 . open-source: Original design files are freely distributes enabling people to study them, make changes and share those changes with others . Electronics: Science sector dealing with the study of flow and control of electrons (electricity) and the study of their behavior and effects in devices using such electrons . Prototyping: An original model, form or an instance that serves as a basis for other things . Platform: A combination of a hardware system with software environment that can be programmed and execute other software Refs: https://www.arduino.cc/en/Guide/Introduction 3 Arduino Uno platform – I . One of the many flavors of Arduino platforms . It is able to read inputs (e.g. light on a sensor, a finger on a button, or a Twitter message) - and turn it into an output (e.g. activating a motor, turning on LEDs, publishing something online) . It can sense and react with the environment . The μC on the Arduino board is programmed using the Arduino programming language (Wiring Language which is based on C++) and the Arduino Integrated Development Environment (IDE) . The software consists of a standard programming language compiler and a boot loader that executes on the microcontroller Refs: https://www.arduino.cc/en/Guide/Introduction 4 Arduino Uno platform – II . Input voltage: 7-12 V (USB, DC plug, or Vin) . Max output current per pin: 40 mA Power Indicator 16MHz Clock Voltage regulator Image taken from: http://www.studentcompanion.co.za/wp-content/uploads/2015/12/Arduino-Uno-R3-pins.jpg 5 Arduino Uno Kit Shift Register Temperature sensor LDR 6 Putting parts together . How can I connect various sensors to Arduino? . How can I connect actuators to Arduino? . How can I tell or program an Arduino to do a job? 7 Programming Environment . It is an computer software framework that includes: . A text editor to create computer programs . A compiler to compile the created programs using the text editor into binary format or . An interpreter to execute the programs created directly 8 Scratch . Scratch is an open source visual programming language for teaching programming to children . One can create interactive stories, games, and animations – and share the creations with others on the we . Developed by the Lifelong Kindergarten group at the MIT Media Lab, USA . Programming resembles to putting parts together assembling a puzzle Source: https://scratch.mit.edu/ 9 Scratch for Arduino S4A - I . S4A, developed in 2010 by the Citilab Smalltalk Team, is a Scratch modification that allows for simple programming of the Arduino open source hardware platform . It provides a high level interface to Arduino programmers so as to manage sensors and actuators . An Arduino sketch (S4AFirmware16.ino) has to be loaded to the board to communicate with S4A through USB Source: http://s4a.cat/ 10 Scratch for Arduino S4A - II . Comparison of a simple program that blinks a LED connected to LED BUILTIN PIN # 13 on Arduino and in S4A LED # 13 Arduino Code S4A Program 11 Breadboards . A breadboard is used to create circuits and connect different sensors and actuators to the Arduino board through jumper wires, and electronic components . Horizontal hole groups are linked power and ground columns are connected vertically 12 Ohm's Law (Basic Electronics Law) . A physics law which states that current passing through a conductor is proportional to the input voltage . Voltage (V): is the measure of electrical potential . unit of measurement = Volts (V) . Current (I): is the amount of flow through a conductive material . unit of measurement = Amperes or Amps (A) . Resistance (R): is the material's opposition to the flow of electric current . unit of measurement = Ohms (Ω) Source: http://ohmlaw.com/ohms-law-for-kids/ 13 How a LED works . It is a light-emitting diode that emits light when activated based on the Electroluminescence (EL) . An optical phenomenon and electrical phenomenon in which a material emits light in response to the passage of an electric current . Electricity flows from a higher voltage to a lower voltage Long Short leg leg Source: https://en.wikipedia.org/wiki/Light-emitting_diode 14 S4A installation . Install S4A into your PC . Download the program from http://vps34736.ovh.net/S4A/S4A16.zip . Unzip it to a folder named S4A . Installing the Firmware into your Arduino . Download Arduino IDE from https://www.arduino.cc/download_handler.php and run the file arduino-1.8.5-windows.exe to setup it . Download S4A firmware from http://vps34736.ovh.net/S4A/S4AFirmware16.ino . Connect your Arduino board to a USB port in your computer . Open the firmware file (S4AFirmware16.ino) from the Arduino environment . In the Tools menu, select the board version and the serial port where the board is connected . Load the firmware into your board through File > Upload 15 Physical computing . Design interactive physical systems by the use of software and hardware that can sense and respond to the real world . smart automotive . traffic control systems . factory automation processes . Smart buildings . Robots Source: https://en.wikipedia.org/wiki/Physical_computing 16 Lab 1 – Control a LED from S4A (I) . Connect a LED and a 220Ω Resistor on the breadboard and with Arduino according to the schematic below _ Digital port #10 + GND 17 Lab 1 – Control a LED from S4A (II) . In S4A select . Digital off and on I/O . Drag and drop them to scripts area . Change them to Press here to switch on or off the LED #10 18 Lab 1 – Control a LED from S4A (III) . From control place wait 1 sec block in between the on of motion blocks . LED switches on and off every 1 sec if you click on the block of commands 19 Lab 1 – Control a LED from S4A (IV) . How to make Loops in the program? 20 Lab 1 – Control a LED from S4A (V) . When button is pushed, turn ON the LED for 10 seconds and then switch it OFF . 10KΩ pull down resistor is required to avoid inducing a dead short circuit when the button is pushed down Common pins Common pins Images sources: https://create.arduino.cc/projecthub/mjrobot/physical-computing-scratch-for-arduino-72661a , http://tymkrs.tumblr.com/post/19734219441/the-four-pin-switch-hooking-it-up 21 Lab 1 – Control a LED from S4A (VI) . Connect a LED and a 220Ω Resistor on the breadboard and with Arduino according to the schematic below _ Digital port OUT #10 220Ω 10KΩ 5V + GND GND Digital port IN #2 22 Lab 1 – Control a LED from S4A (VI) . S4A program 23 Lab 2 – Turn on a LED when LDR sensor is covered Automatic Night Light (I) .CdS - LDR (Cadmium Sulfide - Light Dependent Resistor) or photocell sensor .Its resistance is inversely dependent on the amount of light falling on it 5V Light Pin A0 0-5V 10KΩ 10kΩ resistor 220Ω resistor 24 Lab 2 – Turn on a LED when LDR sensor is covered Automatic Night Light (II) . Write down the Voltage values at Analog pin A0 CONDITION A0 VOLTAGE (mV) Lab’s light are switched ON Lab’s light are switched ON & Hand on the LDR Lab’s light are switched OFF Lab’s light are switched OFF & Hand on the LDR . What is the threshold value that differentiates darkness from lightness? 25 Lab 2 – Turn on a LED when LDR sensor is covered Automatic Night Light (II) . Program S4A . Sense the threshold voltage value of the sensor in an if loop . Depending on the value of the sensor . Switch on and off the LED 26 Lab 3 - Temperature Alarm – (I) . Program Arduino buzzer to buzz when temperature goes higher than a value +5V Temperature LM35 LM35 analog temperature sensor Voltage Supply: 4V – 20V Output Voltage Pin A3 10mv per Degree Ground Celsius 0-5V 27 Lab 3 - Temperature Alarm – (II) . Schematic Topology + GND 5V Digital Pin #11 GND Analog Pin A3 28 Lab 3 - Temperature Alarm – (III) . Read the voltage value in pin A1 . Does it correspond to real room temperature? . How to calculate the temperature value in oC since voltage values are read in A1 from the LM35 sensor? . Formula according to LM35 datasheet . Find what percentage of the range (1024 = 10bits representation of ADC) value in A1 is, multiplying that by the range itself (5000 mV), and divide it by 10 mV per oC . Temperature in oC = (A1 value * 500)/1023 Source: http://www.ti.com/lit/ds/symlink/lm35.pdf 29 Lab 3 - Temperature Alarm – (IV) .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    33 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us