Using Arduino Workshop
Using Arduino Workshop
Using Arduino Workshop
ET 111 - iCREAT I
Workshop
Electronic Components 1:
Breadboard, Batteries, Resistors, Ohm’s law, LEDs
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
Breadboard and Jumper Wires
Jumper Wires
Battery
Batteries have three parts, an anode
(-), a cathode (+), and the
electrolyte. The cathode and anode
(the positive and negative sides at
either end of a traditional battery)
are hooked up to an electrical
circuit. The chemical reactions in
the battery causes a buildup of
electrons at the anode. Based on materials from NCWIT.org/etextiles
LED
A light-emitting diode (LED) is a
two-lead semiconductor light source. It
is a p–n junction diode, which emits light
when activated. When a suitable voltage
is applied to the leads, electrons are able
to recombine with electron holes within
the device, releasing energy in the form
of photons. You can read more here
20 mA is a good MAXIMUM current rating
Ohm’s law
R = V/I
V = 9V
I = 20mA (.02)
Max
R=9V / 20mA
R=450 Max
What is a Resistor?
Ω
MassBay Community College
ET 111 - iCREAT I
TinkerCAD
Simulate Your Circuit First
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
Starting TinkerCAD
Go to https://www.tinkercad.com/
Create an account and sign up
When you are ready select Circuits
Create new circuit
How Tinkercad Works
Practice Lab 1
Do Part 2 only
1. Simulate in TinkerCAD
2. Implement Physical Design
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
MassBay Community College
ET 111 - iCREAT I
Arduino
Arduino, Arduino IDE
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
What is the Arduino?
An Arduino is a
microcontroller that can be
programmed to do many
kinds of things! You can learn
more here.
Programming the Arduino
Blocks and text code will be synchronized. STOP using blocks once
you are familiar with the commands
Connect your Arduino to your computer
Practice Lab 2
Do Part 1 only
1. Simulate in TinkerCAD
2. Implement Physical Design
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
MassBay Community College
ET 111 - iCREAT I
Buzzer
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
Buzzer
A buzzer or beeper is an audio
signalling device, which may be
mechanical, electromechanical, or
piezoelectric. Typical uses of
buzzers and beepers include
alarm devices, timers, and
confirmation of user input such as
a mouse click or keystroke.
Based on materials from NCWIT.org/etextiles
Understanding Sound
For more info watch: Using the Arduino tone() function with a piezo speaker
Based on materials from NCWIT.org/etextiles
Notes and Frequencies
28
Based on materials from NCWIT.org/etextiles
MassBay Community College
ET 111 - iCREAT I
Practice Lab 3
Do Part 3 only
1. Simulate in TinkerCAD
2. Implement Physical Design
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
MassBay Community College
ET 111 - iCREAT I
Electronic Components 2:
Breadboard, Batteries, Resistors, Ohm’s law, LEDs
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
LDR-light dependent resistor
A photoresistor (or light-dependent
resistor, LDR, or photocell) is a
light-controlled variable resistor.
The resistance of a photoresistor
decreases with increasing incident
light intensity; in other words, it
exhibits photoconductivity. You can
read more here
Based on materials from NCWIT.org/etextiles
Analog Input: Reading Sensors
Analog Input will only work with the analog pins on the Arduino. Use
an If/Else block to test the data received.
Displaying the Data Read
void loop() {
int LEDright = 9; // Right LED Serial.println(analogRead(LDR));
int LEDleft = 11; // Left LED if (analogRead(LDR) <= 15) { // if input value from LDR <= 15
int LDR = A0; // LDR sensor digitalWrite(LEDleft,HIGH); // set left LED to HIGH (on)
digitalWrite(LEDright,LOW);// set right LED to LOW (off)
void setup() { delay(1000);
pinMode(LDR,INPUT); // declare LDR as input digitalWrite(LEDleft,LOW); // set left LED to LOW (off)
pinMode(LEDright,OUTPUT); // declare LEDright as output digitalWrite(LEDright,HIGH); // set right LED to HIGH (on)
pinMode(LEDleft,OUTPUT);// declare LEDleft as output delay(1000);
Serial.begin(9600); } else {
} digitalWrite(LEDright,LOW);
}
}
PIR-Passive Infrared Sensor
Motion Sensor
A passive infrared sensor (PIR
sensor) is an electronic sensor that
measures infrared (IR) light
radiating from objects in its field of
view. They are most often used in
PIR-based motion detectors.
You can read more here.
Based on materials from NCWIT.org/etextiles
House Sample Code void loop(){
sensorValue = digitalRead(input); // read input value
if (sensorValue == HIGH) { // check if the input is high
beep(500); //sound function
//Variables
if (currentState == LOW) {
int input = 2; // input pin for PIR sensor
Serial.println("Motion detected!");
int currentState = LOW; //assuming no motion detected
currentState = HIGH;
int sensorValue = 0; //reading PIR value (status)
}
int buzzer = 10; //PIN for Buzzer
}
else{ // If sensor input is low (no motion),
void setup() {
if (currentState == HIGH){ // and there was motion before,
pinMode(input, INPUT); // declare sensor as input
Serial.println("No motion detected!"); // print "No motion."
pinMode(buzzer, OUTPUT); // declare buzzer as output
currentState = LOW; // Set currentStatus to LOW (no motion).
Serial.begin(9200);
}
}
//give PIR sensor 30-60 seconds to stabilize.
}
Serial.print("Stabilizing sensor ");
for(int i = 0; i < 40; i++){
void beep(int delayms){ //Beep (sound) function
Serial.print(".");
tone(buzzer, 3000); // try different frequency!
delay(1000);
delay(delayms);
}
noTone(buzzer); // Stops any tone for pin 10
Serial.println("\ndone..."); // '\n' just to start a new line
delay(delayms);
}
}
Servo Motor SG90: DATA SHEET
The Ultrasonic Sensor
This sensor has 4 pins but we’ll use it as a 3 pin sensor. Ultrasonic Distance Sensor
● The echo pin - listens for the returned pulse
● The trig pin - gets triggered to start the detection
● 5v
● ground
5v
Trig Ground
Echo
Boat with Flag Sample Code
#include <Servo.h> void loop() {
Servo myservo; // variables for duration of the ping, and result in inches and cm
int pos = 0; long duration, inches, cm;
int dif = 0;
// The PING))) is triggered by a HIGH pulse of 2 or more msec.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
// pin number for the sensor's output:
pinMode(pingPin, OUTPUT);
const int pingPin = 7;
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
void setup() {
digitalWrite(pingPin, HIGH);
myservo.attach(9);
delayMicroseconds(5);
Serial.begin(9600); // initialize serial communication:
digitalWrite(pingPin, LOW);
}
long microsecondsToInches(long microseconds) {
// The same pin is used to read the signal from the PING))): a HIGH pulse
return microseconds / 74 / 2; // whose duration is the time (in msecs) from the sending of the ping
} // to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
long microsecondsToCentimeters(long microseconds) { duration = pulseIn(pingPin, HIGH);
return microseconds / 29 / 2;
}
Boat with Flag Sample Code - continuation
inches = microsecondsToInches(duration);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
int val = map(cm,0,50,0,180);
Serial.print(cm);
val = val % 180;
Serial.print("cm");
if(abs(dif - cm) > 3){
Serial.println();
Serial.print("Rotating ");
delay(500);
Serial.print(val);
dif = cm;
Serial.println(" degrees");
}
for(pos = 0; pos <= val; pos++){
myservo.write(pos);
delay(15);
}
for(pos = val;pos >= 0;pos--){
myservo.write(pos);
delay(15);
}
}
MassBay Community College
ET 111 - iCREAT I
Project
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd, Gauri Agrawal
This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
Any questions?
You can find me at:
[email protected]
[email protected]
[email protected]
Marina Bograd
Susanne Steiger-Escobar
Giuseppe Sena (Tony)
Credits