Uno Solar Tracker with DC Motors

Hello World!!
I am trying to prototype a solar tracker for a solar food dehydrator, and before I go any farther let me mention that I am still VERY new, this is my very first arduino project. I aware that it would be a lot easier for me to use a servo or h-bridge to run a single motor/servo in both directions but due to lack of funds and resources I’m limited to a couple small dc motors and components from a boombox. I have been able to test all parts of the circuit, and everything checks out. But when I run the program to pan neither of my motors turn!?
What am I doing wrong?

pan.txt (1.21 KB)

int motorL = 10;
int motorR = 11;
int luxL = A0;
int luxR= A1;

float rawRange = 1024; // 3.3v
float logRange = 5.0; // 3.3v = 10^5 lux

void setup() {
pinMode(motorL, OUTPUT); // dont know if I need this
pinMode(motorR, OUTPUT);
pinMode(luxL, INPUT);
pinMode(luxR, INPUT);
analogReference(EXTERNAL);
Serial.begin(9600);
while (! Serial){
Serial.println("Analog Light Sensor");
}}

void loop() {
// read the raw value from the sensor:
int rawLValue = analogRead(luxL);
int rawRValue = analogRead(luxR);
int i = (rawLValue - rawRValue);
int range = map(i, -120, 120, 1,3);
switch (range){
case '1':
analogWrite(motorR, 255);
break;
case '3':
analogWrite(motorL, 255);
break;
default:
analogWrite(motorL, 0);
delay(1);

Serial.print("Left -");
Serial.print(" Raw = ");
Serial.print(rawLValue);
Serial.print(" Right -");
Serial.print(" Raw = ");
Serial.print(rawRValue);
Serial.print(" Difference of - ");
Serial.print(i);
Serial.print(" Range = ");
Serial.println(range);
delay(100);

}}
float RawToLux(int raw)
{
float logLux = raw * logRange / rawRange;
return pow(10, logLux);
}

Hi,

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

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 is your level of electronics, programming, arduino, hardware experience?

What are you sensing with?

Tom..Hope to help..... :slight_smile:

Welcome to forum.use code tag line to post your code.
Are you building single axis tracker??

Can you post your schematic

Write a short program structured like this to make the motor go Left make the motor Stop and go Right and Stop. Start with just the motorLeft and motorStop.

Then take the motorLeft, motorRight and motorStop functions into your solar program.

void setup() {
   // othe setup stuff
   motorLeft();
   delay(5000);
   motorStop();
   delay(5000);
   motorRight();
   delay(5000);
   motorStop();
}
void loop() {
}
void motorLeft() {
   // code to make motor go Counter Clockwise
}
void motorStop() {
  // code to make motor stop
}
// etc

…R
planning and implementing a program

take a picture of your wiring
make a drawing or a hand sketch or use PAINT or some such (wish there was a unbunto equalivent) and show us what you are trying to do.

you should have a power to teh motor.
then from the motor to a transistor,
then the transistor to ground.
you ONLY control the transistor.

you should NOT try to power the motor from the Arduino. you will burn out your arduino.

I’m using two Adafruit GA1A1S202WP Analog Light Sensors.
I tried my best to put together a schematic its very messy, please forgive me. I made it on 123D Circuits if anyone is familiar with the site. And I had to substitute my light sensors for pots but same basic idea applies.

123D Solar Tracker

int motorL = 10;
int motorR = 11;
int luxL = A0;
int luxR= A1;

float rawRange = 1024; // 3.3v
float logRange = 5.0; // 3.3v = 10^5 lux
 

void setup() {
  pinMode(motorL, OUTPUT);         
  pinMode(motorR, OUTPUT);
  pinMode(luxL, INPUT);
  pinMode(luxR, INPUT);
  analogReference(EXTERNAL);
  Serial.begin(9600);
  while (! Serial){
    Serial.println("Analog Light Sensor");
}}

void loop() {
    // read the raw value from the sensor:
  int rawLValue = analogRead(luxL);    
  int rawRValue = analogRead(luxR);
  int i = (rawLValue - rawRValue);
  int range = map(i, -120, 120, 1,3);
 switch (range){
   case '1':
   analogWrite(motorR, 255);
   break;
   case '3':
   analogWrite(motorL, 255);
   break;
   default:
   analogWrite(motorL, 0);
   delay(1);
  
   Serial.print("Left -");
   Serial.print(" Raw = ");
   Serial.print(rawLValue);
   Serial.print(" Right -");
   Serial.print(" Raw = ");
   Serial.print(rawRValue);
   Serial.print(" Difference of - ");
   Serial.print(i);
   Serial.print(" Range = ");
   Serial.println(range);
   delay(100);

}}
float RawToLux(int raw)
{
  float logLux = raw * logRange / rawRange;
  return pow(10, logLux);
}
int rawLValue = analogRead(luxL);   
int rawRValue = analogRead(luxR);


IF (rawL - rawR ) > 20{   // left sensor is higher than right
analogWrite(motorL, 255);  // move motor to rotate left
}
ELSE             // if rawL is not greater than rawR by more than 20, then motor is off
{
analogWrite(motorL, 0);
}
IF (rawR - rawL ) > 20{
analogWrite(motorR, 255);
}
ELSE
{
analogWrite(motorR,0);
}

there will be a dead band when the values are between the +20 and -20 .
all the motors should do is to nudge the unit so the unit follows the sun

in reality, you only need to move the unit one direction. a second motor is not absolutely required.

you could put a home switch on and once the unit pass a point, it would then spin around to the starting point.
a tracker should never hunt backwards. just wait and the planets rotation will catch up soon enough.

Hi,
Greenspace519, a nice simple circuit, no its not messy.
May I suggest a simple sketch that just turns on one motor then the other to prove that the drive is OK.
You don't need to convert to lux, just use the raw analog values to analyse the sun direction info.
Unless you want to display the light level on a display.
You said that the motors did not operate, what was the monitor displaying.
What are the base resistors and transistors?

Tom.... :slight_smile:

If you want a PC base schematic editor, ExpressPCB, it is free, comes no junk program, apps, browser extensions, and its freee, its freee.