Sinyal Sistem w6 en Projects
Sinyal Sistem w6 en Projects
Aytaç DURMAZ
Sensor Connection
Output Programming
Audio-Visual Demo
Course Overview
Getting started:
Electric:
-----------------------------
Programming:
Virtual Prototyping:
Schematics and PCB Layout in Fritzing
Arduino Board
Processor
• Coding is accessible and transferable (C++, Processing, java)
Arduino…
http://spectrum.ieee.org/geek-life/hands-on/the-making-of-arduino
Getting Started
• SW Installation: Arduino (v.1.0+)
•Fritzing
•SIK Guide Code
•Drivers (FTDI)
• Materials:
• SIK Guide
• Analog I/O, Digital I/O, Serial,
& Fritzing handouts
• Arduino CheatSheet
PWR IN USB
(to Computer)
RESET
SCL\SDA
(I2C Bus)
POWER
5V / 3.3V / GND
Digital I\O
PWM(3, 5, 6, 9, 10, 11)
Analog
INPUTS
PWR IN USB
(to Computer)
RESET
SCL\SDA
(I2C Bus)
POWER
5V / 3.3V / GND
Digital I\O
PWM(3, 5, 6, 9, 10, 11)
Analog
INPUTS
Go ahead and get the board up
and running
Arduino Shields
•What happens
when you break the
circuit?
•What if you
wanted to add more
than one LED?
Adding controls – let's use
Arduino
and start programming!!
Concepts: INPUT & OUTPUT
Almost all systems that use physical computing will have some form of output
What are some examples of Output?
Concepts: IN and OUT
5 5
V V
0 0
V V
Turn on Arduino
•Hints:
•For PC Users
1.Let the installer copy and
move the files to the
appropriate locations, or
2.Create a folder under C:\ For Mac Users
Program Files (x86) called 1. Move the Arduino
Arduino. Move the entire executable to the dock
Arduino program folder here. for ease of access.
2. Resist the temptation to
run these from your
desktop.
Arduino Integrated Development
Environment (IDE)
Two required functions /
methods / routines:
void setup()
{
// runs once
}
void loop()
{
error & status messages // repeats
}
Settings: Tools Serial Port
Your computer communicates
with the Arduino
microcontroller through a serial
port through a USB-to-Serial
adapter.
•Check to make sure the drivers
are installed correctly.
Ayarlar: Araçlar Panosu
analogWrite()
digitalRead()
analogRead()
Serial communication
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License .
Let's talk about coding...
Project #1 – Blink
The "Hello World" of Physical Computing
•Psuedo code – how should this work?
Loop Döngüsü
Structure of Arduino code
pinMode(var1, var2) The pinMode functions set the mode of the given pin.
Var1 is the pin number and var2 is the mode (IN,
INPUT_PULLUP, OUTPUT)
digitalWrite(var1, var2) digitalWrite changes the state of the pin. Var1 is the pin
number and var2 is the status (LOW, HIGH).
IMPORTANT TO NOTICE:
Depending on whether the pin is set to OUTPUT or INPUT, the actual effect of
•
digitalWrite() is different
map(var1,var2,var3,var4,var5) It maps the value var1 to the interval var2, var3 linearly
to the interval var4, var5. It also works with negative
numbers.
Arduino C – Basic functions
Basic blinking
LED
int ledPin = 13; //Variable to store the pin number
void setup()
{
pinMode(ledPin, OUTPUT); //set ledPin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); //LED ON
delay(1000); //Wait 1000ms (=0,1s)
digitalWrite(ledPin, LOW); //LED OFF
delay(1000); //Wait 1000ms (=1s)
}
Installation of the program
1. Click Verify
The program
is checked 2.
1.
2. Click Upload
The program
is uploaded to
the Arduino
mCu board
Breadboard
Resistor LED
Capacitor Transistor
Inductor
Example 1 – Push Button
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); //set ledPin off as default
pinMode(buttonPin, INPUT); //set buttonPin as input
digitalWrite(buttonPin, HIGH); //set the default state of the pin to HIGH (+5V)
}
void loop()
{
if(digitalRead(buttonPin) == LOW)
{
digitalWrite(ledPin, HIGH); //LED ON
}
else
{
digitalWrite(ledPin, LOW); //LED OFF
}
}
Example 1 - Interrupt
void switchLED()
{
ledState = !ledState;
digitalWrite(ledPin, ledState);
}
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); //set ledPin off as default
pinMode(buttonPin, INPUT_PULLUP); //turn on the internal pullup
attachInterrupt(digitalPinToInterrupt(buttonPin), switchLED, CHANGE); //creates
the interrupt
}
void loop()
{
//waiting for interrupt
}
Caution!
• Basic terms
• 100 %
• 75 %
• 25 %
• 0%
PWM Applications
Longer pin
Example 2 - Analog I/O
Potentiometer controlled PWM LED
int ledPin = 3; //Variable to store the pin number
int potPin = A0; //Variable to store the pin number
void setup()
{
pinMode(ledPin, OUTPUT); //set ledPin as output
pinMode(potPin, INPUT); //set potPin as input
}
void loop()
{
int potValue = analogRead(potPin); //Read the value of the potentiometer
int ledValue = map(potValue, 0, 1023, 0, 255); //map to correct range
analogWrite(ledPin, ledValue); //Read the value of the potentiometer
delay(10); //To run the loop ~100 times a second
}
Comments
• digitalWrite(pin, HIGH/LOW);
• ex: digitalWrite(13, HIGH);
• delay(time_ms);
• ex: delay(2500); // delay of 2.5
sec.
•
Programming Concepts: Variables
Variable Scope
•Global
•---
•Function-level
Concepts: Analog and Digital
•analogWrite(pin, val);
•
•pin – ÇIKIŞ pinini
ifade eder (3, 5, 6, 9,
10, 11 pinleriyle
sınırlıdır.) – ~ sembolü
ile gösterilir
Color Mixing
Tri-color LED
• int redPin = 5;
• int greenPin = 6;
• int bluePin = 9;
• void setup()
• {
• pinMode(redPin, OUTPUT);
• pinMode(greenPin, OUTPUT);
• pinMode(bluePin, OUTPUT);
• }
RGB LED Color Mixing
• void loop()
• {
• analogWrite(redPin, 255);
• analogWrite (greenPin, 255);
• analogWrite (bluePin, 255);
• }
Project: Mood Lamp / Light
Sculpture
Driving Motors or Other High
Current Loads
to Digital
Pin 9
(Input)
to Digital Pin 2
Digital Sensors (a.k.a. Switches)
Add an indicator LED to pin 13
<Boolean> Description
( ) == ( ) is equal?
( ) != ( ) is not equal?
( ) > ( ) greater than
( ) >= ( ) greater than or equal
( ) < ( ) less than
( ) <= ( ) less than or equal
Trimpot (Potentiometer)
Variable Resistor
fixed
end
wiper
fixed
end
Analog Sensors
3 Pin Potentiometer = var. resistor (circuit)
a.k.a. Voltage Divider Circuit
wiper
fixed
ends
1.0 V 1.0 V
Ohms Law… (just the basics)
Actually, this is the “voltage
divider”
•
analogRead()
Opens up a Serial
Terminal Window
Analog Sensors
2 Pin Analog Sensors = var.
resistor
•Get two sensors - Use the
Series Monitor and find the
range of input values you get
for each sensor.
•MaxAnalogRead = _________
•MinAnalogRead = _________
Analog Sensors
Examples:
Sensors Variables
Mic soundVolume
Photoresistor lightLevel
Potentiometer dialPosition
Temp Sensor temperature
Flex Sensor bend
Accelerometer tilt/acceleration
Additional Serial Communication
Sending Messages
void loop ( )
{
Serial.print(“Hands on “) ;
Serial.print(“Learning ”) ;
• Serial.println(“is Fun!!!”) ;
}
Serial Communication:
Serial Debugging
void loop()
{
int xVar = 10;
Serial.print ( “Variable xVar is “ ) ;
Serial.println ( xVar ) ;
}
Serial Communication:
Serial Troubleshooting
void loop ( )
{
Serial.print (“Digital pin 9: “);
Serial.println (digitalRead(9));
}
Projects!
Report Title
Name – Surname Number (Max teams of 3)
Purpose of the Project
Theoretical Explanation
Bill of Materials Used
Wiring Diagram
Working Procedure
Discussion and comments
Appendix -1 Codes
Appendix -2 Demo
• Appendix -3 Project Presentation
tomatic pot watering
nnect Components: Connect the humidity sensor, water pump, and relay to the Raspberry Pi.
st the Moisture Sensor: Write a Python script that will read the data from the sensor and
ure the moisture level of the soil.
mp Control: Write a Python script to control the pump via relay. Start the pump when the
dity is low.
4. Automation: Set the script to run at specific intervals or configure it to check the
humidity level in a continuous cycle.
https://www.youtube.com/watch?v=s_Ecar_yMBM
https://www.instructables.com/
Arduino-Plant-Watering-System/
https://docs.arduino.cc/hardware/
plant-watering-kit/
2) Alarm Clock
1. Bileşenleri Bağla: Buzzer, butonları ve ekranı Raspberry Pi'ye bağla.
2. Saat Fonksiyonu: Şu anki zamanı ve alarm zamanını gösterecek bir Python
scripti yaz.
3. Alarm Kurma: Kullanıcının alarm zamanını ayarlamasını sağlayacak butonlar
için script yaz.
4. Alarmı Tetikle: Ayarlanan zaman geldiğinde buzzer'ı çalıştıracak ve kullanıcı
alarmı durdurana kadar çalmaya devam edecek bir sistem kur.
https://projecthub.arduino.cc/
tittiamo68/alarm-clock-057133
https://www.instructables.com/
Arduino-Alarm-Clock-3/
art Mirror
nnect Components: Connect the touchscreen and camera to the Raspberry Pi.
er Interface: Create an interface where users can choose clothes.
oto Capture: Write a function that will take a photo of the user using the camera.
4. Outfit Selection and Display: Set up a system to overlay the selected outfit on the user's photo.
https://projecthub.arduino.cc/
mohammadsohail0008/smart-mirror-
5cec0a
hgate
nnect Components: Connect the servo motor, PIR sensor, and buttons to the Raspberry Pi.
tion Detection: Write a script that will read the data from the PIR sensor and open the door.
or Control: Develop a system to open and close the door using the servo motor.
4. Manual Control: Set up a control system for the buttons to open and close the door
manually.
eractive LED Display
nnect Components: Connect the LED strips and microphone module to the Raspberry Pi.
ce Detection: Write a Python script that will collect audio data from the microphone.
D Control: Set up a system that will change the way the LEDs light up and color based on the
d data.
4. PWM Control: Enhance the visual impact by adding a function to adjust the brightness
of the LEDs.
FID Door Lock
onnect Components: Connect the RFID reader, electronic lock mechanism (servo or
noid) to the Raspberry Pi.
ID Reading: Write a Python script that will recognize authorized RFID tags.
ck Control: Develop a system that activates the lock mechanism when an authorized tag is
cted.
4. Security: Add a layer of security to log unauthorized access attempts and alert
when necessary.
7) Traffic Light Control
1. Connect Components: Connect the red, yellow, green LEDs and buttons to the
Raspberry Pi.
2. Traffic Light Logic: Write a Python script with timing and transition logic for each light.
3. Manual Control: Add a feature that allows you to manually switch between lights at the
push of a button.
4. Safety Features: Design a safety mechanism that will make all the lights red for
emergencies.
8) Burglar Alarm
1. Connect Components: Connect the PIR sensor and buzzer to the Raspberry Pi.
2. Motion Detection: Write a Python script that will be activated when motion is detected from
the PIR sensor.
3. Alarm Trigger: Set up a system that will activate the buzzer when motion is detected and
keep it ringing for a certain period of time.
4. Mute: Add a button to mute the alarm, giving the user control.
Zero W Security Camera
onnect Components: Connect the camera module to the Raspberry Pi Zero W.
ve Streaming: Write a Python script that will stream live video.
otion Detection (Optional): Add motion detection to notify the user when motion is
cted.
4. Data Retention: Use local memory or network space to store detected motion or
continuous video streaming.
Environmental Monitoring Station
onnect Components: Environmental sensors (air quality, temperature, humidity, etc.) Connect it
our Raspberry Pi.
Data Collection: Write a Python script that will collect and process data from sensors.
isualization: Develop a user interface to visualize the collected data in real-time.
4. Trend Analysis: Set up a system that can analyze long-term environmental changes by
recording data.
Time-lapse Camera
Connect Components: Connect the camera module to the Raspberry Pi.
Photo Shoot: Write a Python script that will automatically take photos at regular intervals.
Video Creation: Develop a system to create a time-lapse video by combining captured photos.
4. Auto-Save: Set up a mechanism to automatically save and store the generated videos.
https://www.instructables.com/
Arduino-Time-Lapse-Photography/
) Digital Photo Frame
Connect Components: Connect the LCD screen to the Raspberry Pi.
Photo Display: Write a Python script that will automatically load and display photos from local
orage or network sources.
User Control: Design a simple user interface that allows you to switch between photos.
4. Customization: Add options to customize features such as display time, transition effects,
etc.
https://www.tomshardware.com/how-to/raspberry-pi-photo-frame
Voice-Activated Light
onnect Components: Connect the microphone module and relay/LED strips to the Raspberry Pi.
oice Detection and Processing: Write a Python script that will detect and process voice
mmands.
ght Control: Develop a control mechanism that will turn the lights on and off according to voice
mmands.
4. User Interface: Provide an interface that can customize system settings.
https://projects.raspberrypi.org/en/projects/google-voice-
aiy
https://www.instructables.com/Raspberry-Pi-Voice-
Controlled-Home-Automation/
Speaker & Bluetooth
onnect Components: Connect the Bluetooth module and speaker to the Raspberry Pi.
luetooth Connection: Set up to connect the devices to the Raspberry Pi via Bluetooth.
Music Playback: Write a Python script that will stream music from the connected
ice.
4. User Control: Add basic control features such as music playback, stop and
skip.
https://www.instructables.com/DIY-Google-Home-With-
Bluetooth-Speaker-on-Raspberr/
https://www.instructables.com/Raspberry-Pi-Bluetooth-
Speaker/
Voice Changer
onnect Components: Connect the microphone and speaker to the
pberry Pi.
udio Capture: Write a Python script that will capture the sound from the
rophone in real-time.
udio Processing: Set up a processing system that will make changes to
captured audio (pitch, speed, equalizer settings, etc.).
4. Output: Develop a mechanism to extract the processed sound
from the speaker.
16) Arduino Gas Leak Detector with Alert System
Objective:
To develop an Arduino-based system capable of detecting the presence of hazardous
gases, such as propane or methane, and alerting the user both visually and audibly to
ensure safety in environments prone to gas leaks.
Hardware Requirements:
1. Arduino Uno Board: Serves as the central processing unit for controlling other
components.
2. MQ-2 Gas Sensor: Detects various gases including methane, butane, LPG, and smoke.
3. Buzzer: Emits an audible alert when gas concentrations exceed safe levels.
4. LEDs (Red and Green): Red LED indicates a hazard (gas detected), while green LED
shows system status (operational).
5. Resistors: For LED connection to limit current and prevent damage.
6. Jumper Wires: For connections between the Arduino and other components.
7. Breadboard: For prototyping the circuit without soldering.
8. Power Supply: Either via USB or an external 9V battery.
Software Requirements:
1. Arduino IDE: To write and upload code to the Arduino board.
2. Libraries: Specific libraries for the MQ-2 sensor to facilitate interfacing and data
reading.
Development Steps:
1. Assemble the Circuit:
- Connect the MQ-2 sensor to the Arduino using jumper wires according to the sensor's
pin layout.
- Attach the buzzer and LEDs to the Arduino, ensuring correct resistance values are
used for the LEDs.
- Arrange all components on the breadboard and ensure secure connections.