{"id":2642,"date":"2015-09-04T10:08:23","date_gmt":"2015-09-04T14:08:23","guid":{"rendered":"https:\/\/itp.nyu.edu\/physcomp\/?page_id=2642"},"modified":"2024-09-16T14:30:54","modified_gmt":"2024-09-16T18:30:54","slug":"lab-sensor-change-detection","status":"publish","type":"page","link":"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/lab-sensor-change-detection\/","title":{"rendered":"Lab: Sensor Change Detection"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Microcontrollers can sense what&#8217;s going on in the physical world using digital and analog sensors, but a single sensor reading doesn&#8217;t tell you much. In order to tell when something significant happens, you need to know when that reading changes. For example, when a digital input changes from LOW to HIGH or the reverse, you can tell that a person closed or opened &nbsp;a switch. When a force-sensing resistor reaches a peak reading, you know that something has hit the sensor. In this lab, you&#8217;ll learn how to program your microcontroller to look for three common changes in sensor readings that give you information about events in the physical world: state change detection on digital sensors, and threshold crossing and peak detection on analog sensors. You&#8217;ll use these three techniques all the time when you&#8217;re designing to read users&#8217; actions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Youll_Need_to_Know\"><\/span>What You\u2019ll Need to Know<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To get the most out of this lab, you should be familiar with the following concepts. You can check how to do so in the links below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a class=\"wikilink\" style=\"color: #37aad1;\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/\">Digital Input with Arduino<\/a><\/li>\n\n\n\n<li><a class=\"wikilink\" style=\"color: #37aad1;\" href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/analog-in-with-an-arduino\/\">Analog Input with Arduino<\/a><\/li>\n\n\n\n<li>Basic <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/programming-terms-and-programming-environments\/\" data-type=\"page\" data-id=\"2006\">microcontroller programming concepts<\/a>, including <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/variables\/\" data-type=\"page\" data-id=\"640\">variables<\/a> and conditional statements.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Things_Youll_Need\"><\/span>Things You\u2019ll Need<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-3 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2224\" height=\"1668\" data-id=\"5921\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot.jpg\" alt=\"Photo of an Arduino Nano 33 IoT module. The USB connector is at the top of the image, and the physical pins are numbered in a U-shape from top left to bottom left, then from bottom right to top right.\" class=\"wp-image-5921\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot.jpg 2224w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-arduino-nano-33-iot-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Arduino Nano 33 IoT<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"4217\" height=\"3163\" data-id=\"5908\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires.jpg\" alt=\"Photo of flexible jumper wires\" class=\"wp-image-5908\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires.jpg 4217w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-jumper-wires-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Flexible jumper wires. These wires are quick for breadboard prototyping, but can get messy when you have lots of them on a board.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"3836\" height=\"2877\" data-id=\"5909\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg\" alt=\"Photo of a solderless breadboard\" class=\"wp-image-5909\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard.jpg 3836w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-breadboard-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">A solderless breadboard with two rows of holes along each side. The . board is turned sideways so that the side rows are on top and bottom in this view. There are no components mounted on the board. <\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2194\" height=\"1646\" data-id=\"5918\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons.jpg\" alt=\"Photo of four breadboard-mounted pushbuttons\" class=\"wp-image-5918\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons.jpg 2194w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-pushbuttons-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Pushbuttons<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-force-sensing-resistor.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2032\" height=\"1524\" data-id=\"5920\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-force-sensing-resistor.jpg\" alt=\"Photo of a Force Sensing Resistor (FSR)\" class=\"wp-image-5920\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-force-sensing-resistor.jpg 2032w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-force-sensing-resistor-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-force-sensing-resistor-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Force Sensing Resistor (FSR)<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"2356\" height=\"1767\" data-id=\"5915\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor.jpg\" alt=\"Photo of a handful of 10-kilohm resistors\" class=\"wp-image-5915\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor.jpg 2356w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor-768x576.jpg 768w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/pcomp-kit-f2019-10k-resistor-1280x960.jpg 1280w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">10-kilohm resistors. These ones are 5-band resistors<\/figcaption><\/figure>\n<figcaption class=\"blocks-gallery-caption wp-element-caption\">Figures 1-6. The parts you&#8217;ll need for this exercise. Click on any image for a larger view.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Understanding_How_Your_Sensor_Changes\"><\/span>Understanding How Your Sensor Changes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before you start trying to detect specific sensor change events, you should know what your sensor&#8217;s changes look like over time. You might want to start by viewing the change on an oscilloscope, or by using the Serial Plotter in the Arduino IDE Tools menu (command-shift-L), or a graphing program like the one shown in the <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-serial-communication\/lab-webserial-input-to-p5-js\/\" data-type=\"page\" data-id=\"9566\">WebSerial input to p5.js Lab<\/a> or <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/serial-output-from-an-arduino\/\" data-type=\"page\" data-id=\"1200\">Serial Output From Arduino to Processing lab<\/a> to understand how your sensors change. Figure 7 shows a typical sensor change graph.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/processing_graph_screenshot.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"242\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/processing_graph_screenshot-300x242.png\" alt=\"Graphing a sensor in Processing. The drawing shows a graph in which the line is alternately rising and falling on a relatively smooth curve.\" class=\"wp-image-1228\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/processing_graph_screenshot-300x242.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/processing_graph_screenshot.png 847w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 7. Graphing a sensor in Processing<\/figcaption><\/figure><\/div>\n\n\n<p>Sensor changes are described in terms of the change in the sensor&#8217;s property, often a voltage output, over time. The most important&nbsp;cases to consider for sensor change are the <strong>rising<\/strong> and <strong>falling edges<\/strong> of a digital or binary sensor, and the <strong>rising<\/strong> and <strong>falling edges<\/strong> and the <strong>peak<\/strong> of an analog sensor. The graphs in Figures 8 and 9 of sensor voltage over time illustrate these conditions:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/state_change_explained.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"183\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/state_change_explained-300x183.png\" alt=\"Graph of a digital sensor's rising and falling edge. The graph shows a flat line near zero, followed by a vertical rise to the top of the vertical axis. This change is labeled &quot;Rising&quot;. Then there is another flat line for a short distance, then a vertical drop back to near zero. This change is labeled &quot;Falling&quot;.\" class=\"wp-image-2774\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/state_change_explained-300x183.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/state_change_explained.png 405w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 8. Digital sensors change from high voltage to low and vice versa. The change from low voltage to high is called the rising edge, and the change from high voltage to low is called the falling edge<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/peak_explained.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"183\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/peak_explained-300x183.png\" alt=\"Graph of an analog sensor. Graph depicts the sensor rising, peaking, and falling over time. It also depicts a threshold value below the rising, peak, and falling points.\" class=\"wp-image-2773\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/peak_explained-300x183.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/peak_explained.png 406w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 9. The three general states of an analog sensor are when it&#8217;s rising (current state &gt; previous state), when it&#8217;s falling (current state &lt; previous state), and when it&#8217;s at a peak.<\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prepare_the_breadboard\"><\/span>Prepare the breadboard<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Connect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V or 3.3V (depending on your model) and any of the ground connections, as shown in Figures 10 and 11.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplate_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"195\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplate_bb-300x195.png\" alt=\"An Arduino Uno on the left connected to a solderless breadboard, right. The Uno's 5V output hole is connected to the red column of holes on the far left side of the breadboard. The Uno's ground hole is connected to the blue column on the left of the board. The red and blue columns on the left of the breadboard are connected to the red and blue columns on the right side of the breadboard with red and black wires, respectively. These columns on the side of a breadboard are commonly called the buses. The red line is the voltage bus, and the black or blue line is the ground bus. \" class=\"wp-image-2159\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplate_bb-300x195.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplate_bb.png 559w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 10. Breadboard view of an Arduino Uno on the left connected to a solderless breadboard, right.<\/figcaption><\/figure><\/div>\n\n\n<p>Figure 10 shows an Arduino Uno on the left connected to a solderless breadboard, right. The Uno&#8217;s 5V output hole is connected to the red column of holes on the far left side of the breadboard. The Uno&#8217;s ground hole is connected to the blue column on the left of the board. The red and blue columns on the left of the breadboard are connected to the red and blue columns on the right side of the breadboard with red and black wires, respectively. These columns on the side of a breadboard are commonly called the buses. The red line is the voltage bus, and the black or blue line is the ground bus.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplateNanoShort_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"717\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabTemplateNanoShort_bb.png\" alt=\"Arduino Nano on a breadboard.\" class=\"wp-image-5903\" style=\"width:228px;height:359px\"\/><\/a><figcaption class=\"wp-element-caption\">Figure 11. Breadboard view of Arduino Nano mounted on a breadboard.<\/figcaption><\/figure><\/div>\n\n\n<p>Figure 11 shows an Arduino Nano mounted on a solderless breadboard. The Nano is mounted at the top of the breadboard, straddling the center divide, with its USB connector facing up. The top pins of the Nano are in row 1 of the breadboard.<\/p>\n\n\n\n<p>The Nano, like all Dual-Inline Package (DIP) modules, has its physical pins numbered in a U shape, from top left to bottom left, to bottom right to top right. The Nano&#8217;s 3.3V pin (physical pin 2) is connected to the left side red column of the breadboard. The Nano&#8217;s GND pin (physical pin 14) is connected to the left side black column. These columns on the side of a breadboard are commonly called the buses. The red line is the voltage bus, and the black or blue line is the ground bus. The blue columns (ground buses) are connected together at the bottom of the breadboard with a black wire. The red columns (voltage buses) are connected together at the bottom of the breadboard with a red wire.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><em style=\"font-size: 16px;\">Images made with <a href=\"http:\/\/fritzing.org\/home\/\">Fritzing<\/a><\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Add_a_pushbutton\"><\/span>Add a pushbutton<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Connect a pushbutton to digital input 2 on the Arduino. Figures 12 and 13 show the schematic and breadboard views of this for an Arduino Uno, and Figure 14 shows the breadboard view for an Arduino 33 IoT.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_switch_schem1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"264\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_switch_schem1-300x264.png\" alt=\"Schematic view of an Arduino connected to a pushbutton. One side of the pushbutton is connected to digital pin 2 of the Arduino. A 10-kilohm resistor is connected from digital pin 2 to ground as well. The other side of the pushbutton is attached to +5V. \" class=\"wp-image-2166\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_switch_schem1-300x264.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_switch_schem1.png 576w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 12. Schematic view of an Arduino connected to a pushbutton.<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_switch_bb1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"195\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_switch_bb1-300x195.png\" alt=\"Breadboard view of an Arduino connected to a pushbutton. The +5 volts and ground pins of the Arduino are connected by red and black wires, respectively, to the left side rows of the breadboard. +5 volts is connected to the left outer side row (the voltage bus) and ground is connected to the left inner side row (the ground bus). The side rows on the left are connected to the side rows on the right using red and black wires, respectively, creating a voltage bus and a ground bus on both sides of the board. The pushbutton is mounted across the middle divide of the solderless breadboard. A 10-kilohm resistor connects from the same row as pushbutton's bottom left pin to the ground bus on the breadboard. There is a wire connecting to digital pin 2 from the same row that connects the resistor and the pushbutton. The top left pin of the pushbutton is connected to +5V.\" class=\"wp-image-2160\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_switch_bb1-300x195.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_switch_bb1.png 559w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 13. Breadboard view of an Arduino connected to a pushbutton.<\/figcaption><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<div class=\"wp-block-image wp-image-5906\">\n<figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"455\" height=\"718\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/arduino_nano_switch_bb1.png\" alt=\"Breadboard view of an Arduino Nano connected to a pushbutton. The +5 volts and ground pins of the Arduino are connected by red and black wires, respectively, to the left side rows of the breadboard. +5 volts is connected to the left outer side row (the voltage bus) and ground is connected to the left inner side row (the ground bus). The side rows on the left are connected to the side rows on the right using red and black wires, respectively, creating a voltage bus and a ground bus on both sides of the board. The pushbutton is mounted across the middle divide of the solderless breadboard. A 10-kilohm resistor connects from the same row as pushbutton's bottom left pin to the ground bus on the breadboard. There is a wire connecting to digital pin 2 from the same row that connects the resistor and the pushbutton. The top left pin of the pushbutton is connected to +3.3V.\" class=\"wp-image-5906\" style=\"width:228px;height:359px\"\/><figcaption class=\"wp-element-caption\">Figure 14. Breadboard view of an Arduino Nano connected to a pushbutton<\/figcaption><\/figure><\/div>\n\n\n<p>The +3.3 volts and ground pins of the Arduino are connected by red and black wires, respectively, to the left side rows of the breadboard. +3.3 volts is connected to the left outer side row (the voltage bus) and ground is connected to the left inner side row (the ground bus). The side rows on the left are connected to the side rows on the right using red and black wires, respectively, creating a voltage bus and a ground bus on both sides of the board. The pushbutton is mounted across the middle divide of the solderless breadboard. A 10-kilohm resistor connects from the same row as pushbutton&#8217;s bottom left pin to the ground bus on the breadboard. There is a wire connecting to digital pin 2 from the same row that connects the resistor and the pushbutton. The top left pin of the pushbutton is connected to +3.3V.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Program_the_Microcontroller_to_Read_the_Pushbuttons_State_Change\"><\/span>Program the Microcontroller&nbsp;to Read the Pushbutton&#8217;s State Change<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In the <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-arduino-digital-and-analog\/digital-input-and-output-with-an-arduino\/\">Digital Lab<\/a> you learned how to read a pushbutton using the <code>digitalRead()<\/code> command. To tell when a pushbutton is pushed, you need to determine when the button&#8217;s state changes from off to on. With the button wired as you have it here, the button&#8217;s state will change from 0 to 1. In order to know that, you need to know not only what the current state of the button is, but you also need to remember the state of the button the previous time you read it. This is called <strong>state change detection<\/strong>. To do this, set up a global variable to store the button&#8217;s previous state. Initialize the button in your program&#8217;s <code>setup()<\/code> function using the <code>pinMode()<\/code> command. Then, in the <code>loop()<\/code> function, write a block of code that reads the button and compares its state to the previous state variable. To do this, you need to read the button, check the current button state against the last state, then save the current state of the button in a variable for the next time through the loop like so:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nint lastButtonState = LOW;    \/\/ state of the button last time you checked\n\nvoid setup() {\n  \/\/ make pin 2 an input:\n  pinMode(2, INPUT);\n}\n\nvoid loop() {\n  \/\/ read the pushbutton:\n  int buttonState = digitalRead(2);\n\n  \/\/ check if the current button state is different than the last state:\n  if (buttonState != lastButtonState) {\n     \/\/ do stuff if it is different here\n  }\n\n  \/\/ save button state for next comparison:\n  lastButtonState = buttonState;\n}\n<\/pre><\/div>\n\n\n<p>If <code>buttonState<\/code> is not equal to <code>lastButtonState<\/code>, then the button has changed. Then you want to check if the current state is HIGH. If it is, then you know the button has changed from LOW to HIGH. That means your user pressed it. Print out a message to that effect.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nint lastButtonState = LOW;   \/\/ state of the button last time you checked\n\nvoid setup() {\n  \/\/ initialize serial communication:\n  Serial.begin(9600);\n  \/\/ make pin 2 an input:\n  pinMode(2, INPUT);\n}\n\nvoid loop() {\n  \/\/ read the pushbutton:\n  int buttonState = digitalRead(2);\n\n  \/\/ if it's changed and it's high, toggle the mouse state:\n  if (buttonState != lastButtonState) {\n    if (buttonState == HIGH) {\n      Serial.println(\"Button was just pressed.\");\n    }\n  }\n  \/\/ save button state for next comparison:\n  lastButtonState = buttonState;\n}\n<\/pre><\/div>\n\n\n<p>Your code should only print out a message when the button changes state. For every button press, you should get one line of code. You can use this technique any time you need to tell when a digital input changes state.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Count_Button_Presses\"><\/span>Count Button Presses<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>One of the many things you can do with&nbsp;state change detection is to count the number of button presses. Each time the button changes from off to on, you know it&#8217;s been pressed once. By adding another global variable and incrementing it when you detect the button press, you can count the number of button presses. &nbsp;Add a global variable at the top of your program like so:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nint lastButtonState = LOW;   \/\/ state of the button last time you checked\nint buttonPresses = 0;       \/\/ count of button presses\n<\/pre><\/div>\n\n\n<p>Then in the if statement that detects the button press, add one to the button press:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\n if (buttonState == HIGH) {\n      buttonPresses++;\n      Serial.print(\"Button has been pressed \");\n      Serial.print(buttonPresses);\n      Serial.println(\" times.\");\n    }\n<\/pre><\/div>\n\n\n<p>The key to detecting state change is the&nbsp;use of a variable to save the current state for comparison the next time through the loop. This is a pattern you&#8217;ll see below as well:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nint lastSensorState = LOW;   \/\/ sensor's previous state\n\/\/ other globals and the setup go here\n\nvoid loop() {\n  \/\/ read the sensor:\n  int sensorState = digitalRead(2);\n\n  \/\/ if it's changed:\n  if (sensorState != lastSensorState) {\n    \/\/ take action or run a more detailed check\n  }\n  \/\/ save sensor state for next comparison:\n  lastSensorState = sensorState;\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Long_Press_Short_Press\"><\/span>Long Press, Short Press<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes you want to take a different action on a short button press than you do on a long button press.  To do this, you need to know now only when the button changes, but also how long it stays in a pressed state after it changes. Here&#8217;s how you might do that.<\/p>\n\n\n\n<p>Start with some global variables for the button pin number, and the length of a long press or a short press, in milliseconds. You also need a variable to track how long the button has been pressed, and as in the code above, you need a variable to track the last button state. Add another variable called <code>pressTime<\/code>, which will keep track of the last time the button went from LOW to HIGH:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\n\/\/ the input pin:\nint buttonPin = 2;\n\n\/\/ the length of the presses in ms:\nint longPress = 750;\nint shortPress = 250;\n\/\/ variable for how long the user actually presses:\nlong pressTime = 0;\n\n\/\/ previous state of the button:\nint lastButtonState = LOW;\n\n<\/pre><\/div>\n\n\n<p>In the <code>setup()<\/code>,  set the button pin mode and initialize serial as you did before:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nvoid setup() {\n  \/\/ initialize serial and I\/O pin:\n  Serial.begin(9600);\n  pinMode(buttonPin, INPUT);\n}\n<\/pre><\/div>\n\n\n<p>In the loop, look for the button to change state, and when it does, note the press time in the <code>pressTime<\/code> variable. When the button is released (goes from HIGH to LOW), calculate how ling it was pressed, and print it:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nvoid loop() {\n  \/\/ read the button:\n  int buttonState = digitalRead(buttonPin);\n\n  \/\/ if the button has changed:\n  if (buttonState != lastButtonState) {\n    \/\/ if the button is pressed, start a timer:\n    if (buttonState == HIGH) {\n      pressTime = millis();\n    }\n    \/\/ if it&#039;s released, stop the timer:\n    if (buttonState == LOW) {\n      long holdTime = millis() - pressTime;\n      \/\/ take action for long press, short press, or tap:\n      if (holdTime &gt; longPress) {\n        Serial.println(&quot;long press&quot;);\n      } else if (holdTime &gt; shortPress) {\n        Serial.println(&quot;short press&quot;);\n      } else {\n        Serial.println(&quot;Tap&quot;);\n      }\n    }\n  }\n  \/\/ save button state for next time:\n  lastButtonState = buttonState;\n}\n<\/pre><\/div>\n\n\n<p>You can see from this that you&#8217;ve actually got three states now, long press (&gt; 750ms), short press (250-750ms), and tap (&gt;250ms). With this, you can make one button do three things.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Analog_Sensor_Threshold_Detection\"><\/span>Analog Sensor Threshold Detection<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When you&#8217;re using analog sensors, binary&nbsp;state change detection like you saw above is not usually&nbsp;effective, because your sensors can have multiple states. Remember, an analog sensor on an Arduino can have up to 1024 possible states. The simplest form of analog state change detection is to look for the sensor to rise above a given threshold in order to take action. However, if you want the action be triggered only once when your sensor passes the threshold, you need to keep track of both its current state and previous state.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Change_the_Breadboard\"><\/span>Change the Breadboard<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To build this example, you&#8217;ll need an analog sensor attached to your microcontroller, as shown in the Analog Input lab. Figures 15-17 show how to connect it.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_schem.png\"><img loading=\"lazy\" decoding=\"async\" width=\"227\" height=\"300\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_schem-227x300.png\" alt=\"Schematic of Arduino connected to an FSR on pin 2. One leg of the FSR connects to +5V. The other leg simultaneously connects to the Arduino's digital pin 2 and one end of a 10-kilohm resistor. The other end of the resistor connects to ground.\" class=\"wp-image-2776\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_schem-227x300.png 227w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_schem.png 440w\" sizes=\"(max-width: 227px) 85vw, 227px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 15. Schematic of Arduino connected to an FSR on pin 2<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_bb.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"164\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_bb-300x164.png\" alt=\"Breadboard view of Arduino connected to an FSR on pin 2. One leg of the FSR connects to +5V. The other leg simultaneously connects to the Arduino's digital pin 2 and one end of a 10-kilohm resistor. The other end of the resistor connects to ground.\" class=\"wp-image-2775\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_bb-300x164.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_bb.png 579w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 16. Breadboard view of Arduino connected to an FSR on pin 2. The FSR is connected to two rows in the left center section of the breadboard. One of its pins is wired to voltage. The other is connected to ground through a 10-kilohm resistor. The row connecting the two resistors is wired to analog input 0.<\/figcaption><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"922\" height=\"995\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_bb-2.png\" alt=\"Breadboard view of Arduino Nano connected to an FSR on pin 2.\" class=\"wp-image-10853\" style=\"width:406px;height:438px\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_bb-2.png 922w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/LabSensorAnalog_bb-2-768x829.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption class=\"wp-element-caption\">Figure 17. Breadboard view of Arduino Nano connected to an FSR on pin 2. The FSR is connected to two rows in the left center section of the breadboard, below the Nano. One of its pins is wired to voltage. The other is connected to ground through a 10-kilohm resistor. The row connecting the two resistors is wired to analog input 0.<\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Program_the_Microcontroller_to_Read_a_Sensor_Threshold_Crossing\"><\/span>Program the Microcontroller to Read a Sensor Threshold Crossing<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This example is very&nbsp;similar to&nbsp;the one above:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nint lastSensorState = LOW;   \/\/ sensor&#039;s previous state\nint threshold = 512;   \/\/ an arbitrary threshold value\n\nvoid setup() {\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/ read the sensor:\n  int sensorState = analogRead(A0);\n\n  \/\/ if it&#039;s above the threshold:\n  if (sensorState &gt;= threshold) {\n    \/\/ check that the previous value was below the threshold:\n     if (lastSensorState &lt; threshold) {\n        \/\/ the sensor just crossed the threshold\n        Serial.println(&quot;Sensor crossed the threshold&quot;);\n     }\n  }\n  \/\/ save button state for next comparison:\n  lastSensorState = sensorState;\n}\n<\/pre><\/div>\n\n\n<p>This program will give you an alert only when the sensor value crosses the threshold when it&#8217;s rising. You won&#8217;t get any reading when it crosses the threshold when it&#8217;s falling, and you&#8217;ll only get one message when it crosses the threshold. It is possible to sense a threshold crossing when the sensor is falling, by reversing the greater than and less than signs in the example above. The threshold you set depends on your application.&nbsp;For example, if you&#8217;re using a light sensor to detect when it&#8217;s dark enough to turn on artificial lighting, you&#8217;d use the example above, and turn on the light when the threshold crossing happens. But you might also need to check for the falling threshold crossing to turn off the light.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Detecting_a_Peak\"><\/span>Detecting a Peak<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>There are times when you&nbsp;need to know when an analog sensor reaches its highest value in a given time period. This is called a <strong>peak<\/strong>. To detect a peak, you first set an initial peak value at zero. &nbsp;Pick a threshold below which you don&#8217;t care about peak values. Any time the sensor value rises above the peak value, you set the peak value equal to the sensor value. When the sensor value starts to fall, the peak will remain with the highest value:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nint peakValue = 0;\nint threshold = 50;   \/\/set your own value based on your sensors\n\nvoid setup() {\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/read sensor on pin A0:\n  int sensorValue = analogRead(A0);\n  \/\/ check if it&#039;s higher than the current peak:\n  if (sensorValue &gt; peakValue) {\n    peakValue = sensorValue;\n  }\n}\n<\/pre><\/div>\n\n\n<p>You only really know you have a peak when you&#8217;ve passed it, however. When the current sensor value is less than the last reading you saved as the peak value, you know that last value was a peak. When the sensor value falls past below&nbsp;threshold after you have a peak, but your peak value is above the threshold, then you know you&#8217;ve got a significant peak value. after you use&nbsp;that peak value, you need to reset the variable to 0 to detect other peaks&nbsp;:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nint peakValue = 0;\nint threshold = 50;   \/\/set your own value based on your sensors\n\nvoid setup() {\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/read sensor on pin A0:\n  int sensorValue = analogRead(A0);\n  \/\/ check if it&#039;s higher than the current peak:\n  if (sensorValue &gt; peakValue) {\n    peakValue = sensorValue;\n  }\n  if (sensorValue &lt;= threshold) {\n    if (peakValue &gt; threshold) {\n      \/\/ you have a peak value:\n      Serial.println(peakValue);\n      \/\/ reset the peak variable:\n      peakValue = 0;\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Dealing_with_Noise\"><\/span>Dealing with Noise<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Quite often, you get noise from sensor readings that can interfere with peak readings. Instead of a simple curve, you get a jagged rising edge filled with many local peaks, as shown in Figure 18:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/local_peaks.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"180\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/local_peaks-300x180.png\" alt=\"Graph of a sensor rising above a constant threshold, peaking, falling below that peak but still above the threshold, then rising to its highest point and falling below the threshold\" class=\"wp-image-2778\" srcset=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/local_peaks-300x180.png 300w, https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/local_peaks.png 579w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 18. Graph of local peaks<\/figcaption><\/figure><\/div>\n\n\n<p>You can smooth out the noise and ignore some of these local peaks by adding in a noise variable and checking to see if the sensor&#8217;s change is different than the previous reading and the noise combined, like so:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: arduino; title: ; notranslate\" title=\"\">\nint peakValue = 0;\nint threshold = 50;   \/\/set your own value based on your sensors\nint noise = 5;        \/\/set a noise value based on your particular sensor\n\nvoid setup() {\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/read sensor on pin A0:\n  int sensorValue = analogRead(A0);\n  \/\/ check if it&#039;s higher than the current peak:\n  if (sensorValue &gt; peakValue) {\n    peakValue = sensorValue;\n  }\n  if (sensorValue &lt;= threshold - noise ) {\n    if (peakValue &gt; threshold + noise) {\n      \/\/ you have a peak value:\n      Serial.println(peakValue);\n      \/\/ reset the peak value:\n      peakValue = 0;\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<p>Most sensor change cases can be described using a combination of state change detection, threshold crossing, and peak detection.&nbsp;When you start to write sensor change detection routines, make sure you understand these three basic techniques, and make sure you have a good idea what your sensor&#8217;s readings look like over time. With that combination, you should be able to detect most simple sensor change events.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this lab you&#8217;ll learn some methods for determining when a sensor&#8217;s reading changes significantly. <\/p>\n","protected":false},"author":2,"featured_media":0,"parent":1622,"menu_order":105,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[46,11,15,26,7],"tags":[],"class_list":["post-2642","page","type-page","status-publish","hentry","category-arduino-fundamentals","category-code","category-lab","category-programming","category-sensors"],"_links":{"self":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/2642"}],"collection":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/comments?post=2642"}],"version-history":[{"count":38,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/2642\/revisions"}],"predecessor-version":[{"id":12150,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/2642\/revisions\/12150"}],"up":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/1622"}],"wp:attachment":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/media?parent=2642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/categories?post=2642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/tags?post=2642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}