Thursday, March 3, 2016

Arduino Day 2

Photocell:

We used a photocell - light sensor - to sense the brightness of the room.  Depending on what value was sensed, different color lights would turn on and off.  This is seen in the if/else if statements.  Each LED has its own line of code: digitalWritie() set as HIGH or LOW for each LED.  For this exercise we used the brown-black-red-gold resistor.

  • 0 - 199: no lights - dark (hand covering photocell)
  • 200 - 399: blue - dim (hand hovering over photocell)
  • 400 - 599: red - light (lighting of the room)
  • 600 - 799: green - bright (light shining on photocell)
  • 800 +: all - very bright (light shining directly on photocell)





Switch:

Using a switch (button), turn on and off a LED light.  Code the Arduino to sense the switch.  Here, a pull-up resistor is used and the switch is set to INPUT.  Depending on whether the switch is open or closed, the LED, set as an OUTPUT, will turn on and off.  When the switch is on and pressed, it connects the circuit between the Arduino and LED.












Sweep and Knob:

We downloaded the sweep and knob codes from Arduino and modified knob to ensure the servo only rotates between 60-120 degrees when the potentiometer - our knob - is turned.



Sweep: 


  • the servo position is initially set to 0 and is connected to pin 9
  • in loop: servo moves from 0 - 180 degrees in 1 degree steps and back from 180 - 0 degrees in -1 degree steps





Knob:


  • connect knob to pin A0
  • potentiometer reads in values from 0 - 1023
  • potentiometer uses the read values to adjust to the servo turning between 60 - 120 degrees







Reflection:

Coding when done correctly, can be satisfying, however, with just one small mistake such as a bracket in the wrong place, can be extremely frustrating.

We found the photocell task to be challenging, and had a hard time coding the lights to light up and turn off.  Initially, instead of using digitalWrite() to code the LEDs to turn on and off, we wrote led_Value and set that to HIGH or LOW to turn it on or off.

On the other hand, I really enjoyed the switch task as it gave me an insight to how lights that we use everyday work with the flick of a switch.

2 comments:

  1. I agree that coding can be frustrating at times! And digitalWrite() is really convenient :-)

    ReplyDelete
  2. I like how you organized your blog post! Very readable and fun!

    ReplyDelete