Download presentation
Presentation is loading. Please wait.
Published byBrenda Bailey Modified over 8 years ago
1
Embedded systems and sensors 1 Part 2 Interaction technology Lennart Herlaar
2
Contents Coding and sketches Circuits Pull-up resistors Voltage dividers Concepts Delay, timing, scheduling Interrupts Debouncing Beyond Arduino
3
Coding and sketches
4
My First Circuit Controlling a LED 4
5
Declaration of variables Initialization (only once) Main loop (ad infinitum) Hello World! (Blink)
6
Arduino programming language C (or C++) variant "Sketches" instead of programs "Small" language Complex features are hidden from view But are available if needed Usual control structures if, if-else, for, while, do-while, switch Usual functions Parameterization return
7
Arduino programming language Usual operators ==, !=, <, =<, &&, ||, !, ++, +=, *=, <<, etc. Usual datatypes boolean, char, byte, (unsigned) int, long, float, double, string, array, String (object) Usual standard functions min(), abs(), sqrt(), cos(), tan(), random(), etc. Boring language... !? Simple... !? Lots of syntactic sugar
8
Arduino programming language Digital I/O pinMode(pin, INPUT/OUTPUT) digitalWrite(pin, HIGH/LOW) digitalRead(pin) LOW = 3 Volt Analog I/O analogRead(pin) 0.. 5 Volt, ranging 0.. 1023 (10 bit resolution A/D converter) analogWrite(pin, 0.. 255) Pulse Width Modulation (PWM), 500 Hz
9
PWM
10
Arduino programming language Time millis() micros() delay() delayMicroseconds() Structure setup() loop() Our Hello World application has a problem! More on that later…
11
Circuits
12
Connecting an RGB led Three leds in one package… …sharing a common lead Common anode versus common cathode
13
Connecting a button Unconnected input pins are floating A pull-up or pull-down resistor is needed Pull-up resistors are generally preferred
14
Connecting a light sensor Light Dependent Resistor (LDR) A microcontroller can't sense resistance directly …but can sense voltage levels Convert resistance to voltage …using a voltage divider
15
Motion and distance sensors Connecting these is pretty straightforward You may need to solder on some wires and configure
16
Connecting a temperature sensor Your temperature sensor is quite advanced DS18B20 compatible one-wire device One-wire protocol Actually a communication bus Needs a pull-up
17
Connecting an LCD Lots of wires! Backlight with series resistor Voltage divider for contrast Easy coding! Library
18
Connecting the missing piece Using a mosfet as an electronic switch Separate circuits! Needs a pull-down resistor Flyback diode for protection
19
Resistor ladder Multiple buttons on one pin Resistor are 10k What will be the readings?
20
Go with the flow… Multiple leds on one pin How to control the individual leds?
21
Concepts
22
Back to Blink Our Hello World application has a problem! delay() is a blocking function call We need to become clock-watchers Blink without delay
23
Interrupts Sometimes delays are hard to prevent… …or things need to be really real-time Interrupts could help you out! attachInterrupt(interrupt, function, mode) interrupt 0 on pin 2, interrupt 1 on pin 3 LOW, CHANGE, RISING, FALLING detachInterrupt(interrupt) interrupts() noInterrupts()
24
Interrupts Short routines, volatile vars, no delays, no Serial Setting a variable and handling it elsewhere Postponing interrupts versus clearing interrupts Interrupts on all pins are possible PinChangeInt, but code needs to figure it out Timer interrupts besides external interrupts Timers / interrupts are a scarce resource Using a timer interrupt may break certain libraries Timers / interrupts are an advanced topic
25
For now… Your Stickuino + IDE should already be working Unless you don't have it yet Go through all the circuits on the hooking things up page This should take you approximately 4 - 8 hours Preferably before the end of this weekend Read up on the topics you find fun / difficult A little less than 3 weeks left for the assignment But 20 hours a week, per person, > 3 weeks; 25% Complexity comes from combining things!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.