massbay community college breadboard, batteries, resistors

45
Workshop MassBay Community College ET 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

Upload: others

Post on 04-Dec-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MassBay Community College Breadboard, Batteries, Resistors

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

Page 2: MassBay Community College Breadboard, Batteries, Resistors

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

Page 3: MassBay Community College Breadboard, Batteries, Resistors

Breadboard and Jumper Wires

a board for making an experimental model of an electric circuit. You can read more here

Jumper Wires

Page 4: MassBay Community College Breadboard, Batteries, Resistors

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

Page 5: MassBay Community College Breadboard, Batteries, Resistors

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

Page 6: MassBay Community College Breadboard, Batteries, Resistors

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

Page 7: MassBay Community College Breadboard, Batteries, Resistors

LED Circuit

R = V/IV = 9VI = 20mA (.02) Max

R=9V / 20mA

R=450 Max

Page 8: MassBay Community College Breadboard, Batteries, Resistors

What is a Resistor?

a device having a designed resistance to the passage of an electric current You can learn more here.

Page 9: MassBay Community College Breadboard, Batteries, Resistors

Ω Ω

Ω

Page 10: MassBay Community College Breadboard, Batteries, Resistors

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

Page 11: MassBay Community College Breadboard, Batteries, Resistors

Starting TinkerCAD

Go to https://www.tinkercad.com/Create an account and sign up When you are ready select CircuitsCreate new circuit

Page 12: MassBay Community College Breadboard, Batteries, Resistors

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

Page 13: MassBay Community College Breadboard, Batteries, Resistors

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

Page 14: MassBay Community College Breadboard, Batteries, Resistors

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

Page 15: MassBay Community College Breadboard, Batteries, Resistors

What is the Arduino?

An Arduino is a microcontroller that can be programmed to do many kinds of things! You can learn more here.

Page 16: MassBay Community College Breadboard, Batteries, Resistors

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

Page 17: MassBay Community College Breadboard, Batteries, Resistors

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

Page 18: MassBay Community College Breadboard, Batteries, Resistors

Connect your Arduino to your computer

Use the USB cable to connect your computer to the Arduino board.

Page 19: MassBay Community College Breadboard, Batteries, Resistors

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!

Page 20: MassBay Community College Breadboard, Batteries, Resistors

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.

Page 21: MassBay Community College Breadboard, Batteries, Resistors

Terminology

For more on terminology check out the programming cheat sheet

Page 22: MassBay Community College Breadboard, Batteries, Resistors

Making an LED Blink (Review)

Turn pin 13 ON.Stop program for 1 second.Turn pin 13 OFF.Stop program for 1 second.

Page 23: MassBay Community College Breadboard, Batteries, Resistors

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

Page 24: MassBay Community College Breadboard, Batteries, Resistors

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

Page 25: MassBay Community College Breadboard, Batteries, Resistors

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

Page 26: MassBay Community College Breadboard, Batteries, Resistors

Understanding Sound

Based on materials from NCWIT.org/etextiles

Page 27: MassBay Community College Breadboard, Batteries, Resistors

The Tone Procedure

Based on materials from NCWIT.org/etextilesFor more info watch: Using the Arduino tone() function with a piezo speaker

Page 28: MassBay Community College Breadboard, Batteries, Resistors

Notes and Frequencies

28 Based on materials from NCWIT.org/etextiles

Page 29: MassBay Community College Breadboard, Batteries, Resistors

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

Page 30: MassBay Community College Breadboard, Batteries, Resistors

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

Page 31: MassBay Community College Breadboard, Batteries, Resistors

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

Page 32: MassBay Community College Breadboard, Batteries, Resistors

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.

Page 33: MassBay Community College Breadboard, Batteries, Resistors

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

Page 34: MassBay Community College Breadboard, Batteries, Resistors

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

Page 35: MassBay Community College Breadboard, Batteries, Resistors

Open Serial Monitor and Check the data

Open Serial Monitor

Page 36: MassBay Community College Breadboard, Batteries, Resistors

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);

}

}

Page 37: MassBay Community College Breadboard, Batteries, Resistors

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

Page 38: MassBay Community College Breadboard, Batteries, Resistors

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);

}

Page 40: MassBay Community College Breadboard, Batteries, Resistors

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

Page 41: MassBay Community College Breadboard, Batteries, Resistors

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);

Page 42: MassBay Community College Breadboard, Batteries, Resistors

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;

}

Page 43: MassBay Community College Breadboard, Batteries, Resistors

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