<-

Photoresistor to Motor

This was a quick and fun experiment playing with input-output relationships with analog and digital signals by convertin light-input through a photoresistor to a physical motion output using a DC motor.

Code

int motor_pin = 26; int photo_pin = 32; int speed = 255; void setup() { // put your setup code here, to run once: pinMode(motor_pin, OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: float read = analogRead(photo_pin); float photo_read = (float)(read - 3200.0) * (255.0/800.0); analogWrite(motor_pin, min((float)255,photo_read)); }