Our first task was to create a button with a transistor that turned on and off when we pressed the button. I wanted to figure out the latching button but was unable to. I did not use any code, given that the motor was run off of the power of the computer and did not need code. The button opens the gate of the transistor, and this turns the motor on. If I had to think about latching, it would require code, likely changing the output when the button is pressed and keeping it there.

Secondly, we made a servo respond to a light sensor. This involved some research for figuring out code, but overall the most difficult part was map, and that ended up working fine once I understood it further. The Servo attaches to pin 9, and then there is a circuit using the light sensor that reads in to the servo and maps, and then writes the value (val) to the servo, converting from 0 to 1023 to 0 to 180.

#include <Servo.h>
Servo servo1;
void setup() {
servo1.attach(9);
}
void loop() {
int val = analogRead(A0);
val = map(val, 0, 1023, 0, 180);
servo1.write(val);
}
Posted in

Leave a comment