Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 1
Activity Title: Blink [LED]
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
Line by Line Comments:
int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
Challenge:
Try varying delay.
Try interface 4 LED with different color. What code do you add? _________________________
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 2
Activity Title: Fade [LED]
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
Line by Line Comments:
int led = 9;
int brightness = 0;
int fadeAmount = 5;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
delay(30);
}
Challenge:
Try varying constant [Numbers].
What code defines the fade delay? _________________________________________________
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 3
Activity Title: Piezo [Sensor]
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
Line by Line Comments:
const int ledPin = 13;
const int knockSensor = A0;
const int threshold = 100;
int sensorReading = 0;
int ledState = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
[Link](9600);
}
void loop() {
sensorReading =
analogRead(knockSensor);
if (sensorReading >= threshold) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
[Link]("Knock!");
}
delay(100);
}
Challenge:
What is the purpose of anologRead? _______________________________________________
In your opinion how does Piezo recognize your knock? _________________________________
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 4
Activity Title: Servo [Motor]
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
Line by Line Comments:
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup()
{
[Link](9);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1)
{
[Link](pos);
delay(15);
}
for(pos = 180; pos>=1; pos-=1)
{
[Link](pos);
delay(15);
}
}
Challenge:
Try re-write the code and instead 180 degrees, use 90.
What is the use of For loop?
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 5
Activity Title: Keypad
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {8, 7, 6};
Keypad keypad = Keypad(
makeKeymap(keys), rowPins, colPins,
ROWS, COLS );
byte ledPin = 13;
boolean blink = false;
boolean ledPin_state;
void setup(){
[Link](9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
ledPin_state = digitalRead(ledPin);
[Link](keypadEvent);
}
void loop(){
char key = [Link]();
if (key) {
[Link](key);
}
if (blink){
digitalWrite(ledPin,!digitalRead(ledPin));
delay(100);
}
}
void keypadEvent(KeypadEvent key){
switch ([Link]()){
case PRESSED:
if (key == '#') {
digitalWrite(ledPin,!digitalRead(ledPin));
ledPin_state = digitalRead(ledPin);
}
break;
case RELEASED:
if (key == '*') {
digitalWrite(ledPin,ledPin_state);
blink = false;
}
break;
case HOLD:
if (key == '*') {
blink = true;
}
break;
}
}
Line by Line Comments:
Challenge:
Try adding a servo, and interface it in keypad using 1 key, and if pressed write it 0, hold write it
45, lastly when released write it 90. [Note: Do not remove the LED function]
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 6
Activity Title: LCD [Display]
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
Line by Line Comments:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
[Link](16, 2);
[Link]("hello, world!");
}
void loop() {
[Link](0, 1);
[Link](millis()/1000);
}
Challenge:
Try to draw a saw-tooth wave form, by modifying the code above.
What is the use of potentiometer in the circuit? _______________________________________
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 7
Activity Title: LCD + Keypad [Display]
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd (11,10,6,7,8,9);
const byte rows = 4;
const byte cols = 3;
const char keys [rows][cols] =
{
{'#','0','*'},
{'9','8','7'},
{'6','5','4'},
{'3','2','1'}
};
byte rowPins[rows] = {6,7,8,9};
byte colPins[cols] = {2,3,4};
Keypad keypad = Keypad(
makeKeymap(keys), rowPins, colPins,
rows, cols );
void setup(){
[Link](9600);
[Link](16,2);
[Link]();
[Link]();
[Link](0,1);
delay(2000);
[Link](20);
}
void initLCDKeys()
{
for (int i = 0; i < sizeof(rowPins); i++)
pinMode(rowPins[i],OUTPUT);
for (int i = 0; i < sizeof(colPins); i++)
{
pinMode(colPins[i],INPUT);
digitalWrite(colPins[i],LOW);
}
}
void loop(){
char key = [Link]();
initLCDKeys();
delay(50);
if (key != NO_KEY){
[Link](key);
[Link](key);
}
Line by Line Comments:
Challenge:
Try using Digital pin 0 and 1 as one of your pin.
What happened? _______________________________________________________________
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 8
Activity Title: Push Button Mouse [Input]
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
const int upButton = 2;
const int downButton = 3;
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton = 6;
int range = 5;
int responseDelay = 10;
void setup() {
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton, INPUT);
[Link]();
}
void loop() {
int upState = digitalRead(upButton);
int downState =
digitalRead(downButton);
int rightState = digitalRead(rightButton);
int leftState = digitalRead(leftButton);
int clickState =
digitalRead(mouseButton);
int xDistance = (leftState rightState)*range;
int yDistance = (upState downState)*range;
if ((xDistance != 0) || (yDistance != 0)) {
[Link](xDistance, yDistance, 0);
}
if (clickState == HIGH) {
if () {
[Link](MOUSE_LEFT);
}
}
else {
// if the mouse is pressed, release it:
if ([Link](MOUSE_LEFT)) {
[Link](MOUSE_LEFT);
}
}
delay(responseDelay);
}
Line by Line Comments:
Challenge:
Try draw your name using this circuit and by using paint then upload it to Facebook, with a
caption This name will soon be written in newspaper because, I will become Engineer.
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 9
Activity Title: Master & Slave [Input & Output]
Material/Components Used:
______________________________________________________________________________
______________________________________________________________________________
Code:
FOR MASTER
#include <Wire.h>
void setup()
{
[Link]();
[Link](9600);
}
void loop()
{
[Link](2, 6);
while([Link]())
{
char c = [Link]();
[Link](c);
}
delay(500);
}
FOR SLAVE
#include <Wire.h>
void setup()
{
[Link](2);
[Link](requestEvent); }
void loop()
{
delay(100);
}
void requestEvent()
{
[Link]("hello ");
}
Line by Line Comments:
Challenge:
Try putting 1 LED to Slave unit and try to remote control it by Master unit.
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Conclusion:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Name: _________________________
Course/Year/Block: _______________
Instructor: _____________________
Date: _________________________
Activity # 10
Activity Title: Arduino Master
Code:
Line by Line Comments:
Challenge:
Make a code and try integrating 3 previous device that you use. Except LED.
Draw the Schematic Diagram Below.
Schematics: