Photocell to control DC motors: Please Help!

Hey everyone!

So I've been working on this arduino project where I take a photocell, get a value, convert from 0-1023 scale to 0-255 scale and operate one of two motors.

I wrote a code and I feel like my thinking is write but I cant seem to get the motors to run. Can anyone check to see whats wrong/missing? Thanks a bunch!

int LightSensorPin = 0;
int Read; // initializing a "Read" value
int val; // receive value that will drive the motor
int motorPin1 = 3;
int motorPin2 = 6;

void setup(void) {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
Serial.begin(9600); //Communication of sensor and computer
}

void loop(void) {

Read = analogRead(LightSensorPin);

Serial.print(" Reading = "); //print phrase
Serial.println(Read); //print analog reading of the light sensor
val = map(Read, 0, 1023, 0, 255); //map photocell values (0-1023) to analog values(0-255) for motor

if (val>150)
{
analogWrite(motorPin1, HIGH);
analogWrite(motorPin2, LOW);
}
if (val<101)
{
analogWrite(motorPin2, HIGH);
analogWrite(motorPin1, LOW);
}

delay(4000);
}

Hi
Can you please post a copy of your sketch, using code tags?
Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

What are your motors and how are you connecting them to the arduino?
What model arduino is it.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Tom.... :slight_smile:

Does the LDR have a pullup or pulldown resistor.
What value is it.

Do you get the "Read" value on the serial monitor, and what are the numbers you see.

Are you using a motor driver.
Leo.