Download presentation
Presentation is loading. Please wait.
Published byAndrea Orosz Modified over 6 years ago
1
Topics: Analog/Digital Read Relay control 7 segment control Buzzer
Arduino Part 2 Topics: Analog/Digital Read Relay control 7 segment control Buzzer
2
Workshop Overview Hands-on Project 4: Reading analog signal
Hands-on Project 5: Reading digital signal Hands-on Project 6: melody with buzzer Hands-on Project 7: LED Dimmer Hands-on Project 8: Relay control Hands-on Project 9: 7-segment control
3
Hands-on Project 4: Reading analog signal
1 2 hardware setup: Write the code/sketch: void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A0); Serial.println(sensorValue); delay(1000); Trimmer potentiometer
4
Hands-on Project 4: Reading analog signal
3 4 Load the program into arduino Open serial monitor, turn the potentiomenter and observe the output Press verify button to check for errors Press upload button to load the program into the arduino Serial monitor Try to use other sensors/input that produce analog signal and observe the output
5
Hands-on Project 5: Reading digital signal
2 1 Write the code/sketch: hardware setup: int pushButton = 2; void setup() { Serial.begin(9600); pinMode(pushButton, INPUT); } void loop() { int buttonState = digitalRead(pushButton); Serial.println(buttonState); delay(1); 10kOhm
6
Hands-on Project 5: Reading digital signal
3 4 Load the program into arduino Open serial monitor, press the button and observe the output Press verify button to check for errors Press upload button to load the program into the arduino Serial monitor Try to use other sensors/input that produce digital signal and observe the output
7
Hands-on Project 6: melody with buzzer
1 2 The code/sketch: hardware setup:
8
Hands-on Project 6: melody with buzzer
3 4 Once uploaded, you should be able to hear the melody Load the program into arduino Press verify button to check for errors Press upload button to load the program into the arduino Try to change the tone variable and observe the output
9
Hands-on Project 7: LED Dimmer
1 2 The code/sketch: hardware setup: 220 Ohm
10
Hands-on Project 7: LED Dimmer
3 4 Once uploaded, you should be able to see the brightness of your LED changes Load the program into arduino Press verify button to check for errors Press upload button to load the program into the arduino
11
Hands-on Project 8: relay control
1 hardware setup (use relay module from SIRIM robokit): relay2 relay1 relay4 relay3 GND 5v
12
Hands-on Project 8: relay control
2 The Code: void setup() { Serial.begin(9600); pinMode(12, OUTPUT); } void loop() { if (Serial.available() > 0) { int inByte = Serial.read(); switch (inByte) { case 'a': digitalWrite(12, HIGH); break; case 'b': digitalWrite(12, LOW); Copy from previous example (project3) use pin/port number 12 3 Verify and upload the program 4 Press ‘a’ or ‘b’ to activate the relay
13
Hands-on Project 9: 7-segment control
1 hardware setup (use 7segment module from SIRIM robokit): 5v GND Bit 1 Bit 0 Bit 3 Bit 2 display4 display3 display2 display1
14
Hands-on Project 9: 7-segment control
2 The Code: bit3 bit2 bit1 bit0 display 1 2 3 4 5 6 7 8 9 we will use display number 4 only the number will be displayed based on the following table: 5v GND Bit 1 Bit 0 Bit 3 Bit 2
15
Hands-on Project 9: 7-segment control
2 The Code(cont.): int b0 = 2; int b1 = 3; int b2 = 4; int b3 = 5; int b4 = 6; void setup() { pinMode(b0, OUTPUT); pinMode(b1, OUTPUT); pinMode(b2, OUTPUT); pinMode(b3, OUTPUT); pinMode(b4, OUTPUT); } void loop() { digitalWrite(b0, HIGH); digitalWrite(b1, LOW); digitalWrite(b2, LOW); digitalWrite(b3, LOW); digitalWrite(b4, HIGH); } 5v GND Bit 1 Bit 0 Bit 3 Bit 2 This code will always display number 1. Try to change the number by changing the logic level of b0,b1,b2 and b3 according to the previous table
16
Hands-on Project 9: 7-segment control
3 The results: void loop() { digitalWrite(b0, HIGH); digitalWrite(b1, LOW); digitalWrite(b2, LOW); digitalWrite(b3, LOW); digitalWrite(b4, HIGH); } void loop() { digitalWrite(b0, LOW); digitalWrite(b1, HIGH); digitalWrite(b2, LOW); digitalWrite(b3, LOW); digitalWrite(b4, HIGH); } void loop() { digitalWrite(b0, HIGH); digitalWrite(b1, HIGH); digitalWrite(b2, LOW); digitalWrite(b3, LOW); digitalWrite(b4, HIGH); }
17
References www.arduino.cc www.ladyada.net/learn/arduino
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.