{"id":47,"date":"2007-04-20T18:16:38","date_gmt":"2007-04-21T01:16:38","guid":{"rendered":"http:\/\/itp.nyu.edu\/blogs\/bmy1\/2007\/04\/20\/final-project-working-light-sensor-and-motor\/"},"modified":"2009-01-11T13:58:09","modified_gmt":"2009-01-11T20:58:09","slug":"final-project-working-light-sensor-and-motor","status":"publish","type":"post","link":"https:\/\/yeeality.com\/blog\/2007\/04\/20\/final-project-working-light-sensor-and-motor\/","title":{"rendered":"final project &#8211; working light sensor and motor"},"content":{"rendered":"<p>working the code out on our own was pretty darn satisfying today. h-bridge. analog. yes. we&#8217;ll need to tweak the speeds\/values once we get the actual fan and bird setup, but this is functional. <a href=\"http:\/\/itp.nyu.edu\/~bmy1\/video\/fan.mov\">see the lil video here.<\/a><br \/>\n<br \/>\n<img decoding=\"async\" src=\"http:\/\/itp.nyu.edu\/~bmy1\/images\/fanguts.jpg\" width=\"300\"><br \/>\n<img><\/p>\n<p>int sensorPin = 0;    \/\/ analog input photocell<br \/>\nint potValue = 0;     \/\/value read from photocell<br \/>\nint motor1Pin = 3;    \/\/ H-bridge leg 1<br \/>\nint motor2Pin = 4;    \/\/ H-bridge leg 2<br \/>\nint speedPin = 9;     \/\/ H-bridge enable pin<\/p>\n<p>void setup() {<br \/>\n  \/\/ set the PWM as an input:<br \/>\n  pinMode(sensorPin, INPUT);<br \/>\n  Serial.begin(9600);<br \/>\n  \/\/ set other pins as outputs:<br \/>\n  pinMode(motor1Pin, OUTPUT);<br \/>\n  pinMode(motor2Pin, OUTPUT);<br \/>\n  pinMode(speedPin, OUTPUT);<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n  potValue = analogRead(sensorPin); \/\/ read the pot value<br \/>\n  analogWrite(speedPin, potValue);  \/\/ PWM the sensor value with the pot value<br \/>\n  Serial.println(potValue);      \/\/ print pot value back to the debugger pane<\/p>\n<p>  if (potValue &gt;= 800) {<br \/>\n    analogWrite(motor2Pin, potValue*4);  \/\/ set leg 2 of the H-bridge &#8220;high&#8221;<br \/>\n  }<br \/>\n  else if (potValue &gt;= 400 &amp;&amp; potValue<\/p>\n","protected":false},"excerpt":{"rendered":"<p>working the code out on our own was pretty darn satisfying today. h-bridge. analog. yes. we&#8217;ll need to tweak the speeds\/values once we get the actual fan and bird setup, but this is functional. see the lil video here. int sensorPin = 0; \/\/ analog input photocell int potValue = 0; \/\/value read from photocell [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[20],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-pcomp","tag-lightflight"],"_links":{"self":[{"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":1,"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":664,"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/posts\/47\/revisions\/664"}],"wp:attachment":[{"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yeeality.com\/blog\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}