{"id":30,"date":"2006-01-28T23:57:00","date_gmt":"2006-01-29T04:57:00","guid":{"rendered":"http:\/\/www.tigoe.com\/pcomp\/code2\/category\/uncategorized\/30"},"modified":"2007-08-06T23:38:36","modified_gmt":"2007-08-07T04:38:36","slug":"digital-input-controlling-digital-output","status":"publish","type":"post","link":"https:\/\/www.tigoe.com\/pcomp\/code\/arduinowiring\/30\/","title":{"rendered":"Digital Input controlling Digital output"},"content":{"rendered":"<p>This example was written to control a motor from a touch sensor.  More generically, it turns on a digital output based on the state of a digital input.<\/p>\n<p><!--more--><\/p>\n<pre>\n\/*\n  Digital Input controlling DC Motor\n by Tom Igoe \n \n This example controls a DC motor on pin 13. If a digital input on pin 3\n is HIGH, the motor turns on.  Otherwise it turns off.  In the original \n example, the digital input was connected to a QT113 capacitive touch sensor.\n \n Created 28 Jan. 2006 \n *\/\n\n\nint motorPin = 13;        \/\/ this is the digital output pin for the motor\nint touchSensorPin = 3;   \/\/ this is the digital input pin for the touch sensor\nint touchSensor = 0;      \/\/ this is a variable to hold the state of the touch sensor\n\n\nvoid setup() {\n  pinMode(motorPin, OUTPUT);       \/\/ set the motor pin as a digital output\n  pinMode(touchSensorPin, INPUT);  \/\/ set the touch sensor pin as a digital input\n  blink(3);                        \/\/ blink the LED pin 3 times to know that Arduino is alive\n}\n\nvoid loop() {\n  touchSensor = digitalRead(touchSensorPin);  \/\/ read the touch sensor\n  if (touchSensor == HIGH) {                  \/\/ if the touch sensor is sending 5 volts\n    digitalWrite(motorPin, HIGH);             \/\/ turn on the motor\n  } \n  else {\n    digitalWrite(motorPin, LOW);             \/\/ turn off the motor\n  }\n}\n\n\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>More generically, it turns on a digital output based on the state of a digital input&#8230;.  If a digital input on pin 3 is HIGH, the motor turns on. Otherwise it turns off.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-30","post","type-post","status-publish","format-standard","hentry","category-arduinowiring"],"_links":{"self":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":0,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/30\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/categories?post=30"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/tags?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}