This week we learned to read input from switches, variable resistors, or sensors connected to the digital and analog inputs on arduino and how to send digital signal out to control actuators.
The first thing I did was build a circuit with a button and a pull down resistor to read digital (on/off) input from the button, depending on whether it was pushed down to complete the circuit. By connecting it to a digital pin, I could read this information and use it in my program. The next piece was to build two additional circuits with a resistor and LED, and connect each of those to their own digital pin. Then, with some conditional logic, I made one LED light up when the button wasn’t pressed, the other light up when it was pressed.
Next I tried reading analog values from a potentiometer and a force sensor to control the brightness of an LED. By connecting the LED to pin 9 on the arduino, which is a PWM (pulse width modulation) pin, you can simulate analog output which allows for this apparent dimming of the LED. Reading values from a potentiometer and any other variable resistor really aren’t so different.
Realizing that I had already played with analog output with the dimming LED, I wanted to go back to my reflective flower from last week and control it with a variable resistor instead. Since it’s a flower, it made sense that it would react to light, so I used a photoresistor. I had to skip ahead in the labs a little bit, since the motor needs a 9V power supply, and I wasn’t sure how to control the motor with the power supply and the arduino. The answer is: with a transistor! I used a PN2222 transistor (thank you, internet) to connect the analog out from the arduino to the circuit that controlled that power for the motor. My flower responds to light!
Some other issues are that the base isn’t so sturdy, so it works kind of like a spinning top. Also the motor takes a while to slow down, so playing with it you don’t sense an immediate change by lessening the amount of light available. I think it would be cool to hide the photoresistor within the flower somewhere, so that you can control the flower by interacting with it directly.