Hi Everyone,
I'm needing to run a 6 amp x 12v fan motor over a time ( 1hr on and 1 hr off) during the day only.
Can someone point me in the right direction for code to turn off the sketch loop with an LDR with low light say <300.
So that the motor fan runs during the day only with the solar panel connected to the battery system.
I have the VMH5019 Pololo motor shield and Uno mounted and wired with test fan to check works for now and will connect to 6amp fan once this works well.
Now that I have this working correctly with 1hr on and 1 hour off ( see current sketch below), Im keen to get the LDR working to only turn the VMH5019 on when there is more than <300 on the LDR,
So if below <300 then turn off the Void Loop() and holds the sketch untill the light comes back ( ie daylight)
Come someone advise me which function I need to control the sketch on and off with LDR.
Best regards
Jason
My current sketch as of today:
include "DualVNH5019MotorShield.h"
const long oneSecond = 1000; // a second is a thousand milliseconds
const long oneMinute = oneSecond * 60;
const long oneHour = oneMinute * 60;
const long oneDay = oneHour * 24;DualVNH5019MotorShield md;
int sensorPin = A0; // select the input pin for ldr, JON Need to find pin to turn off M1 motor Vcc?? //
int sensorValue = 0; // variable to store the value coming from the sensorvoid setup()
{
Serial.begin(115200);
Serial.println("Dual VNH5019 Motor Shield");
md.init();
pinMode(2, OUTPUT); //pin connected to the VNH5019//
}void loop()
{
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.print("LDR light reading of ");
Serial.println(sensorValue); //prints the values coming from the sensor on the screenif(sensorValue < 300) //setting a threshold value
digitalWrite(2,HIGH); //turn VNH5019 ON//else digitalWrite(2,LOW); //turn VNH5019 OFF//
delay(2);//motor startup//
Serial.println("M1 Speed 50% Forward");// 400 is 100%//
md.setM1Speed(200);
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());Serial.print("Delay: ");
Serial.println("delay for 1 hour");
delay(oneHour);// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.print("LDR light reading of ");
Serial.println(sensorValue); //prints the values coming from the sensor on the screenif(sensorValue < 300) //setting a threshold value
digitalWrite(2,HIGH); //turn VNH5019 ON//else digitalWrite(2,LOW); //turn VNH5019 OFF//
delay(2);//motor shutdown//
Serial.println("M1 Speed 0% stopped");
md.setM1Speed(0);
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());Serial.print("Delay: ");
Serial.println("delay for 1 hour");
delay(oneHour);
}
Image of the arduino and shield