workshops:arduino_for_the_curious:stage_2
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
workshops:arduino_for_the_curious:stage_2 [2017-04-05 12:52] – external edit 127.0.0.1 | workshops:arduino_for_the_curious:stage_2 [2017-04-10 11:22] (current) – Simon | ||
---|---|---|---|
Line 4: | Line 4: | ||
This stage involves the following new components. | This stage involves the following new components. | ||
- | * | + | * [[pushbutton|Push Button]] |
- | * Potentiometer (Rotation Sensor) | + | * |
Line 15: | Line 15: | ||
{{workshops: | {{workshops: | ||
- | | {{workshops: | + | | {{workshops: |
Line 22: | Line 22: | ||
- | We're now going to use the pushbutton | + | We're now going to use the push button |
Note: the buttons in your kit have bent legs. It's worth using a pair of pliers to straighten them out. | Note: the buttons in your kit have bent legs. It's worth using a pair of pliers to straighten them out. | ||
Line 30: | Line 30: | ||
{{workshops: | {{workshops: | ||
- | Below is the code for controlling LEDs with the pushbutton. It stops the LEDs when the button is pressed. | + | Below is the code for controlling LEDs with the push button. It stops the LEDs when the button is pressed. |
+ | < | ||
// Button is on pin 7 | // Button is on pin 7 | ||
int button = 7; | int button = 7; | ||
Line 70: | Line 70: | ||
} | } | ||
} | } | ||
+ | </ | ||
- | + | | {{workshops: | |
- | | {{workshops: | + | |
Line 84: | Line 84: | ||
The Arduino' | The Arduino' | ||
+ | < | ||
// The reading will be a number between 0 and 1023, where 0 is 0V, 1023 is 5V, and all the numbers in between are the voltages inbetween | // The reading will be a number between 0 and 1023, where 0 is 0V, 1023 is 5V, and all the numbers in between are the voltages inbetween | ||
// For example a reading of 512 (which is right in the middle of the range) would be a voltage of 2.5V. | // For example a reading of 512 (which is right in the middle of the range) would be a voltage of 2.5V. | ||
int reading = analogRead(0); | int reading = analogRead(0); | ||
+ | </ | ||
Place the rotation sensor on the breadboard and wire it up to the Arduino as follows: | Place the rotation sensor on the breadboard and wire it up to the Arduino as follows: | ||
Line 94: | Line 94: | ||
{{workshops: | {{workshops: | ||
- | Remember using the serial communication in Lesson 1 to allow the Arduino to send data back to your laptop? We can use that to see how the value output by our rotation sensor varies as we rotate it. | + | Remember using the serial communication in [[stage_1|Lesson 1]] to allow the Arduino to send data back to your laptop? We can use that to see how the value output by our rotation sensor varies as we rotate it. |
+ | < | ||
void setup() { | void setup() { | ||
// initialize serial communication at a speed of 9600 bits per second: | // initialize serial communication at a speed of 9600 bits per second: | ||
Line 108: | Line 108: | ||
delay(500); | delay(500); | ||
} | } | ||
+ | </ | ||
- | + | | {{workshops: | |
- | | {{workshops: | + | |
workshops/arduino_for_the_curious/stage_2.1491396766.txt.gz · Last modified: 2017-04-05 12:52 by 127.0.0.1