0% found this document useful (0 votes)
37 views

Suggested Activity Microprocessor

This document contains details of 7 activities involving basic circuits and coding with Arduino. Each activity explores a different component: 1) Blinking an LED, 2) Fading an LED, 3) Using a piezo sensor, 4) Controlling a servo motor, 5) Using a keypad, 6) Interfacing with an LCD display, and 7) Combining a keypad and LCD display. For each activity the materials, code, and challenges are documented. The student is asked to comment on the code, try variations, and note their observations and conclusions.

Uploaded by

holysavior
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Suggested Activity Microprocessor

This document contains details of 7 activities involving basic circuits and coding with Arduino. Each activity explores a different component: 1) Blinking an LED, 2) Fading an LED, 3) Using a piezo sensor, 4) Controlling a servo motor, 5) Using a keypad, 6) Interfacing with an LCD display, and 7) Combining a keypad and LCD display. For each activity the materials, code, and challenges are documented. The student is asked to comment on the code, try variations, and note their observations and conclusions.

Uploaded by

holysavior
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

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);
Serial.begin(9600);
}
void loop() {
sensorReading =
analogRead(knockSensor);
if (sensorReading >= threshold) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
Serial.println("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()
{
myservo.attach(9);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 180; pos>=1; pos-=1)
{
myservo.write(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(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
ledPin_state = digitalRead(ledPin);
keypad.addEventListener(keypadEvent);
}
void loop(){
char key = keypad.getKey();
if (key) {
Serial.println(key);
}
if (blink){
digitalWrite(ledPin,!digitalRead(ledPin));
delay(100);
}
}
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
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() {
lcd.begin(16, 2);
lcd.print("hello, world!");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(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(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.noAutoscroll();
lcd.clear();
lcd.setCursor(0,1);
delay(2000);
keypad.setDebounceTime(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 = keypad.getKey();
initLCDKeys();
delay(50);
if (key != NO_KEY){
Serial.println(key);
lcd.print(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);
Mouse.begin();
}
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)) {
Mouse.move(xDistance, yDistance, 0);
}
if (clickState == HIGH) {
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(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()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Wire.requestFrom(2, 6);
while(Wire.available())
{
char c = Wire.read();
Serial.print(c);
}
delay(500);
}

FOR SLAVE
#include <Wire.h>
void setup()
{
Wire.begin(2);
Wire.onRequest(requestEvent); }
void loop()
{
delay(100);
}
void requestEvent()
{
Wire.write("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:

You might also like