massbay community college breadboard, batteries, resistors
TRANSCRIPT
Workshop
MassBay Community CollegeET 111 - iCREAT I
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina Bograd This material is based upon work supported by the National Science Foundation under grant no. DUE-1501451
Electronic Components 1:Breadboard, Batteries, Resistors, Ohm’s law, LEDs
MassBay Community CollegeET 111 - iCREAT I
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
a board for making an experimental model of an electric circuit. You can read more here
Jumper Wires
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.
Battery
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
You can calculate the current using Ohm's Law: I = V / R where
I is the current, in AMPSV is the voltage in voltsR is the resistor value, in ohms.
To learn more about the specification, go here
Based on materials from NCWIT.org/etextiles
LED Circuit
R = V/IV = 9VI = 20mA (.02) Max
R=9V / 20mA
R=450 Max
What is a Resistor?
a device having a designed resistance to the passage of an electric current You can learn more here.
Ω Ω
Ω
TinkerCADSimulate Your Circuit First
MassBay Community CollegeET 111 - iCREAT I
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 CircuitsCreate new circuit
How Tinkercad Works
● A name will be provided to your circuit automatically
● Select the components for your circuit:
○ Arduino Uno○ Breadboard○ LED○ resistor , etc.
● Drag them to the work area one by one
● Rotate and move them if necessary
● Connect them
Practice Lab 1 Do Part 2 only
1. Simulate in TinkerCAD2. Implement Physical Design
MassBay Community CollegeET 111 - iCREAT I
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
ArduinoArduino, Arduino IDE
MassBay Community CollegeET 111 - iCREAT I
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
To program the Arduino board we will use the Arduino Integrated Development Environment (IDE)We will also use the TinkerCAD blocks simulation tool to help us code initially To start the IDE look for the this icon on your desktop
Example of coding and simulating with Tinkercad
Use the code editor blocks to start coding
Start the simulation and upload and run your code.
Copy the code into the Arduino IDE once all works well.
Blocks and text code will be synchronized. STOP using blocks once you are familiar with the commands
Drag blocks
Connect your Arduino to your computer
Use the USB cable to connect your computer to the Arduino board.
Important Pins in the Arduino MicrocontrollerInternal LED on Pin 13. Use it to test components! Use these digital pins for your LEDs and push button. You can send or read
a HIGH or LOW value only. DIGITAL!
Use these analog pins for your LDR or temperature sensors, potentiometer. You will read values between 0 and 1023. ANALOG!Make sure your circuits are closed! Do not
forget to connect components to GROUND!
Starting the Arduino IDE
There may be a lot of boards listed, and multiple Arduinos. Make sure to choose the correct board.
If you have trouble figuring out what the serial port is for your board, unplug the board, then go back to Tools > Port: and check the list to see what disappears/reappears when you plug in the board.
Terminology
For more on terminology check out the programming cheat sheet
Making an LED Blink (Review)
Turn pin 13 ON.Stop program for 1 second.Turn pin 13 OFF.Stop program for 1 second.
Practice Lab 2Do Part 1 only
1. Simulate in TinkerCAD2. Implement Physical Design
MassBay Community CollegeET 111 - iCREAT I
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
MassBay Community CollegeET 111 - iCREAT I
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
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.
Buzzer
Based on materials from NCWIT.org/etextiles
Understanding Sound
Based on materials from NCWIT.org/etextiles
The Tone Procedure
Based on materials from NCWIT.org/etextilesFor more info watch: Using the Arduino tone() function with a piezo speaker
Notes and Frequencies
28 Based on materials from NCWIT.org/etextiles
Practice Lab 3Do Part 3 only
1. Simulate in TinkerCAD2. Implement Physical Design
MassBay Community CollegeET 111 - iCREAT I
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
Electronic Components 2:Breadboard, Batteries, Resistors, Ohm’s law, LEDs
MassBay Community CollegeET 111 - iCREAT I
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
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
LDR-light dependent resistor
Based on materials from NCWIT.org/etextiles
Analog Input: Reading Sensors
Connect a light sensor to an Analog Pin and check the data being received! They will send a value between 0 and 1023.
Display or test the Analog pin!
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
We know the sensor is sending data through the pin. It would be nice to see the data. Right?Let’s ask the Arduino to print it on the screen so we can see it.
Print to the Serial Monitor
Ask a question. This is the test statement
If the answer is TRUE, then run code here
If the answer is FALSE, then run code here
Using an IF/ELSE block to make decisions
Use Comparison Operator blocks to test values in
the question
MassBay - Susanne Steiger-EscobarBased on materials from Sparkfun – Angela Sheehan
Less thanLess or equalEqualNot equalGreater thanGreater or equal
Open Serial Monitor and Check the data
Open Serial Monitor
Airplane Sample Code
int LEDright = 9; // Right LED
int LEDleft = 11; // Left LED
int LDR = A0; // LDR sensor
void setup() {
pinMode(LDR,INPUT); // declare LDR as input
pinMode(LEDright,OUTPUT); // declare LEDright as output
pinMode(LEDleft,OUTPUT);// declare LEDleft as output
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(LDR));
if (analogRead(LDR) <= 15) { // if input value from LDR <= 15
digitalWrite(LEDleft,HIGH); // set left LED to HIGH (on)
digitalWrite(LEDright,LOW);// set right LED to LOW (off)
delay(1000);
digitalWrite(LEDleft,LOW); // set left LED to LOW (off)
digitalWrite(LEDright,HIGH); // set right LED to HIGH (on)
delay(1000);
} else {
digitalWrite(LEDright,LOW);
}
}
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.
PIR-Passive Infrared SensorMotion Sensor
Based on materials from NCWIT.org/etextiles
House Sample Code
//Variables
int input = 2; // input pin for PIR sensor
int currentState = LOW; //assuming no motion detected
int sensorValue = 0; //reading PIR value (status)
int buzzer = 10; //PIN for Buzzer
void setup() {
pinMode(input, INPUT); // declare sensor as input
pinMode(buzzer, OUTPUT); // declare buzzer as output
Serial.begin(9200);
//give PIR sensor 30-60 seconds to stabilize.
Serial.print("Stabilizing sensor ");
for(int i = 0; i < 40; i++){
Serial.print(".");
delay(1000);
}
Serial.println("\ndone..."); // '\n' just to start a new line
}
void loop(){
sensorValue = digitalRead(input); // read input value
if (sensorValue == HIGH) { // check if the input is high
beep(500); //sound function
if (currentState == LOW) {
Serial.println("Motion detected!");
currentState = HIGH;
}
}
else{ // If sensor input is low (no motion),
if (currentState == HIGH){ // and there was motion before,
Serial.println("No motion detected!"); // print "No motion."
currentState = LOW; // Set currentStatus to LOW (no motion).
}
}
}
void beep(int delayms){ //Beep (sound) function
tone(buzzer, 3000); // try different frequency!
delay(delayms);
noTone(buzzer); // Stops any tone for pin 10
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.
● The echo pin - listens for the returned pulse
● The trig pin - gets triggered to start the detection
● 5 v
● ground
Ultrasonic Distance Sensor
Trig
Echo
Ground5v
Boat with Flag Sample Code
#include <Servo.h>
Servo myservo;
int pos = 0;
int dif = 0;
// pin number for the sensor's output:
const int pingPin = 7;
void setup() {
myservo.attach(9);
Serial.begin(9600); // initialize serial communication:
}
long microsecondsToInches(long microseconds) {
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}
void loop() {
// variables for duration of the ping, and result in inches and cm
long duration, inches, cm;
// 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:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH pulse
// 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);
duration = pulseIn(pingPin, HIGH);
Boat with Flag Sample Code - continuation
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
int val = map(cm,0,50,0,180);
val = val % 180;
if(abs(dif - cm) > 3){
Serial.print("Rotating ");
Serial.print(val);
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);
}
}
// convert the time into a distance
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(500);
dif = cm;
}
Project
MassBay Community CollegeET 111 - iCREAT I
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]@massbay.edu
Marina BogradSusanne Steiger-EscobarGiuseppe Sena (Tony)
Credits
2016-2018 -- Shamsi Moussavi, Giuseppe Sena, Susanne Steiger-Escobar, Marina BogradThis material is based upon work supported by the National Science Foundation under grant no. DUE-1501451