Categories
PhysicalComputing

final project – working light sensor and motor

working the code out on our own was pretty darn satisfying today. h-bridge. analog. yes. we’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
int motor1Pin = 3; // H-bridge leg 1
int motor2Pin = 4; // H-bridge leg 2
int speedPin = 9; // H-bridge enable pin

void setup() {
// set the PWM as an input:
pinMode(sensorPin, INPUT);
Serial.begin(9600);
// set other pins as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(speedPin, OUTPUT);
}

void loop() {
potValue = analogRead(sensorPin); // read the pot value
analogWrite(speedPin, potValue); // PWM the sensor value with the pot value
Serial.println(potValue); // print pot value back to the debugger pane

if (potValue >= 800) {
analogWrite(motor2Pin, potValue*4); // set leg 2 of the H-bridge “high”
}
else if (potValue >= 400 && potValue

Leave a Reply

Your email address will not be published. Required fields are marked *