No, Much earlier I posted a full code sample to do that using Hysteresis. That code sample will need modified since I wrongly assumed the motor driver board had an enable pin. This can likely be done with an IF statement so IF the battery voltage drops below a preset level the PWM out to the motor board goes to 0. Post #90 had complete code including monitoring the battery. I explained how that code sample works and there are remarks in the code.Question Im not sure yet but in the code is it setup to turn the pump motor on and off depending on the battery voltage
The thread is open to anyone to read and reply to. Unfortunately with a thread like this, having so many post, most people do not read through all of the post so do not have a full handle on what is going on. Another problem is with a project like this there are several ways to go about it with the hardware and even several ways to write the code.Quick question can all members read these thread posts the reason why is because im getting help by many people but it seams to me like they ether dont look at other posts or they can't see them
So we knew it was a motor but weren't aware it would only need to run in a single direction. The use of an H-Bridge is common when we have a bi-directional motor. In your case later it was known it was just a uni-directional pump and then the fan figured into things. This is why it is good to know as much as possible before getting into helping someone with a project. This forum has no shortage of very knowledgeable people and the more that is known the better a project can be addressed.Any help would be appreciated what I want to build may be simple for some one out the there that's been using the Arduino for a wile now. I've never used one before but was told I could get help here .I haven't bought any parts yet because I want sure what to get .Heres what I'm wanting to make is a automatic switch from a 12v dc car battery to a 12v dc 80 watt motor . I want the Arduino to do is start the 12v dc 80 watt motor when the voltage is at 12v dc turn on the motor then when it reaches 11v dc or maybe lower turn off the motor I'm not sure how low you can get a car battery before it mess's it up. Maybe using a relay of some kind with an external power supply to power the motor.The project is not going to run all the time just when I'm using it Theres a solar controller with 2 100 watt solar panels charging the battery or battery's later on so i just want it to automatically stop when it get to 11v dc. I'll be using a step down converter from 12v to 5 volts off the same battery to power the Arduino so there would be a load from the step down converter and the motor itself...
So if anyone could tell me what parts I would need to buy and how to wire it all up and maybe a script for all of it I would appreciate it greatly...
I'm sorry about any grammar problems I had to rewrite this many times already
#define analogInPin A0
#define PWM1 3#define analogInPin A0
#define PWM1 3
#define DIR1 5
#define BATTERY A1
uint16_t sensorValue,outputValue,percentValue;
uint32_t batteryVoltage; //32 bit to prevent overflow
uint32_t tick=0;
void setup() {
Serial.begin(115200);
Serial.println("\n\n\n\nHello");
pinMode(PWM1,OUTPUT); //set the PWM pin to output
pinMode(analogInPin,INPUT); //set the potentiometer pin to input
pinMode(BATTERY,INPUT); //set the battery pin to input
pinMode(DIR1,OUTPUT); //set the dir pin to output
digitalWrite(DIR1,HIGH); //set it high - change HIGH to LOW if motor goes wrong way
}
void loop(){
// Read the PWM value of the input potentiometer.
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// map pump speed percent of full scale
percentValue = map (outputValue, 0, 255, 0, 100);
// change the analog out value:
analogWrite(PWM1, outputValue);
batteryVoltage=analogRead(BATTERY);
if((millis()-tick)>100){ //display 10 times per second
tick=millis();
Serial.print("Potentiometer Value = ");
Serial.println(sensorValue,DEC);
//convert battery reading to voltage (in milliVolts)
batteryVoltage*=15000; //*5000*3
batteryVoltage/=1024;
Serial.print("Battery Voltage = ");
Serial.println(batteryVoltage,DEC);
}
}
// InputHysteresis.ino Turn a motor On and Off based on Battery Voltage.
// We want the motor to run only when the battery voltage exceeds a preset level.
// We also want a potentiometer to be able to set the motor speed when the motor is enabled.
// Define the baud rate for the serial port.
#define BAUD_RATE 9600
// This assumes A0 for Battery Voltage input and A1 for Motor Speed input.
// Battery Voltage allows a digital out for the motor to run or not run.
// Motor Speed controls a PWM output siganl to the motor.
#define INPUT1_PIN A0
#define INPUT2_PIN A1
// PWM Constants
const int analogInPin = A1; // Analog input pin that the potentiometer is attached to
const int pwmOutPin = 5; // Analog output pin that the LED is attached to
// The Arduino Uno built in LED is used for test purposes pin 13.
// The Arduino Uno pin 12 is used to enable or disable the motor.
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
/****************************************************************/
// Global variables.
// The state of the motor enable output pin can be captured with only two values, High or Low Battery Voltage.
// Battery Voltage is represented by a single bit.
// The following statement defines two symbolic values, one for each possible state.
enum state_t { IS_LOW, IS_HIGH };
// Declare the state variable as a symbolic value.
enum state_t state = IS_LOW;
// The hysteretic response is defined by using two thresholds.
const int high_threshold = 881;
const int low_threshold = 819;
// The PWM Functions
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
int percentValue = 0; // pump speed percent full scale
// Standard Arduino initialization function to configure the system.
void setup()
{
// initialize the Serial port
Serial.begin( BAUD_RATE );
// configure our trivial I/O
pinMode( LED_BUILTIN, OUTPUT );
pinMode( 12, OUTPUT);
// the LED and pin 12 start out High to match the initial state.
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(12, HIGH);
}
/****************************************************************/
// Standard Arduino polling function.
void loop()
{
// Read the PWM value of the input potentiometer.
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// map pump speed percent of full scale
percentValue = map (outputValue, 0, 255, 0, 100);
// change the analog out value:
analogWrite(pwmOutPin, outputValue);
// print the results to the Serial Monitor:
Serial.print("\t Speed Input = ");
Serial.print(sensorValue);
Serial.print("\t Speed Output = ");
Serial.print(outputValue);
Serial.print("\t Motor Speed Percentage = ");
Serial.println(percentValue);
// wait 500 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(500); // Allow 0.5 Second and continue
// Read the Battery Voltage level.
int input1 = analogRead(INPUT1_PIN);
float battVolt = (input1 * 5.0) / 1023 * 3;
Serial.print ("\t Battery Voltage is ");
Serial.print (battVolt);
Serial.println (" Volts");
delay(1000);
if (state == IS_HIGH) {
if (input1 < low_threshold) {
Serial.print("Low observed at input level ");
Serial.println(input1);
Serial.println("Transitioning to the IS_LOW state.");
state = IS_LOW;
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(12, LOW);
}
} else { // state must be IS_LOW
if (input1 > high_threshold) {
Serial.print("High observed at input level ");
Serial.println(input1);
Serial.println("Transitioning to the IS_HIGH state.");
state = IS_HIGH;
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(12, HIGH);
}
}
}
/****************************************************************/
#define DIR1 5
#define BATTERY A1
uint16_t sensorValue,outputValue,percentValue;
uint32_t batteryVoltage; //32 bit to prevent overflow
uint32_t tick=0;
void setup() {
Serial.begin(115200);
Serial.println("\n\n\n\nHello");
pinMode(PWM1,OUTPUT); //set the PWM pin to output
pinMode(analogInPin,INPUT); //set the potentiometer pin to input
pinMode(BATTERY,INPUT); //set the battery pin to input
pinMode(DIR1,OUTPUT); //set the dir pin to output
digitalWrite(DIR1,HIGH); //set it high - change HIGH to LOW if motor goes wrong way
}
void loop(){
// Read the PWM value of the input potentiometer.
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// map pump speed percent of full scale
percentValue = map (outputValue, 0, 255, 0, 100);
// change the analog out value:
analogWrite(PWM1, outputValue);
batteryVoltage=analogRead(BATTERY);
if((millis()-tick)>100){ //display 10 times per second
tick=millis();
Serial.print("Potentiometer Value = ");
Serial.println(sensorValue,DEC);
//convert battery reading to voltage (in milliVolts)
batteryVoltage*=15000; //*5000*3
batteryVoltage/=1024;
Serial.print("Battery Voltage = ");
Serial.println(batteryVoltage,DEC);
}
}
// InputHysteresis.ino Turn a motor On and Off based on Battery Voltage.
// We want the motor to run only when the battery voltage exceeds a preset level.
// We also want a potentiometer to be able to set the motor speed when the motor is enabled.
// Define the baud rate for the serial port.
#define BAUD_RATE 9600
// This assumes A0 for Battery Voltage input and A1 for Motor Speed input.
// Battery Voltage allows a digital out for the motor to run or not run.
// Motor Speed controls a PWM output siganl to the motor.
#define INPUT1_PIN A0
#define INPUT2_PIN A1
// PWM Constants
const int analogInPin = A1; // Analog input pin that the potentiometer is attached to
const int pwmOutPin = 5; // Analog output pin that the LED is attached to
// The Arduino Uno built in LED is used for test purposes pin 13.
// The Arduino Uno pin 12 is used to enable or disable the motor.
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
/****************************************************************/
// Global variables.
// The state of the motor enable output pin can be captured with only two values, High or Low Battery Voltage.
// Battery Voltage is represented by a single bit.
// The following statement defines two symbolic values, one for each possible state.
enum state_t { IS_LOW, IS_HIGH };
// Declare the state variable as a symbolic value.
enum state_t state = IS_LOW;
// The hysteretic response is defined by using two thresholds.
const int high_threshold = 881;
const int low_threshold = 819;
// The PWM Functions
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
int percentValue = 0; // pump speed percent full scale
// Standard Arduino initialization function to configure the system.
void setup()
{
// initialize the Serial port
Serial.begin( BAUD_RATE );
// configure our trivial I/O
pinMode( LED_BUILTIN, OUTPUT );
pinMode( 12, OUTPUT);
// the LED and pin 12 start out High to match the initial state.
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(12, HIGH);
}
/****************************************************************/
// Standard Arduino polling function.
void loop()
{
// Read the PWM value of the input potentiometer.
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// map pump speed percent of full scale
percentValue = map (outputValue, 0, 255, 0, 100);
// change the analog out value:
analogWrite(pwmOutPin, outputValue);
// print the results to the Serial Monitor:
Serial.print("\t Speed Input = ");
Serial.print(sensorValue);
Serial.print("\t Speed Output = ");
Serial.print(outputValue);
Serial.print("\t Motor Speed Percentage = ");
Serial.println(percentValue);
// wait 500 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(500); // Allow 0.5 Second and continue
// Read the Battery Voltage level.
int input1 = analogRead(INPUT1_PIN);
float battVolt = (input1 * 5.0) / 1023 * 3;
Serial.print ("\t Battery Voltage is ");
Serial.print (battVolt);
Serial.println (" Volts");
delay(1000);
if (state == IS_HIGH) {
if (input1 < low_threshold) {
Serial.print("Low observed at input level ");
Serial.println(input1);
Serial.println("Transitioning to the IS_LOW state.");
state = IS_LOW;
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(12, LOW);
}
} else { // state must be IS_LOW
if (input1 > high_threshold) {
Serial.print("High observed at input level ");
Serial.println(input1);
Serial.println("Transitioning to the IS_HIGH state.");
state = IS_HIGH;
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(12, HIGH);
}
}
}
/****************************************************************/
#define analogInPin A0
#define PWM1 3
#define DIR1 5
#define BATTERY A1
uint16_t sensorValue,outputValue,percentValue;
uint32_t batteryVoltage; //32 bit to prevent overflow
uint32_t tick=0;
void setup() {
Serial.begin(115200);
Serial.println("\n\n\n\nHello");
pinMode(PWM1,OUTPUT); //set the PWM pin to output
pinMode(analogInPin,INPUT); //set the potentiometer pin to input
pinMode(BATTERY,INPUT); //set the battery pin to input
pinMode(DIR1,OUTPUT); //set the dir pin to output
digitalWrite(DIR1,HIGH); //set it high - change HIGH to LOW if motor goes wrong way
}
void loop(){
sensorValue = analogRead(analogInPin); // Read the PWM value of the input potentiometer.
outputValue = map(sensorValue, 0, 1023, 0, 255); // map it to the range of the analog out:
percentValue = map (outputValue, 0, 255, 0, 100); // map pump speed percent of full scale
analogWrite(PWM1, outputValue); // change the analog out value:
batteryVoltage=analogRead(BATTERY);
if((millis()-tick)>100){ //display 10 times per second
tick=millis();
Serial.print("Potentiometer Value = ");
Serial.println(sensorValue,DEC);
//convert battery reading to voltage
batteryVoltage*=15000; //*5000*3
batteryVoltage/=1024;
Serial.print("Battery Voltage = ");
Serial.println(batteryVoltage,DEC);
}
}
#define analogInPin A0
#define PWM1 3
#define DIR1 5
#define BATTERY A1
uint16_t sensorValue,outputValue;
uint32_t batteryVoltage; //32 bit to prevent overflow
uint32_t tick=0;
boolean motorRun;
void setup() {
Serial.begin(115200);
Serial.println("\n\n\n\nHello");
pinMode(PWM1,OUTPUT); //set the PWM pin to output
pinMode(analogInPin,INPUT); //set the potentiometer pin to input
pinMode(BATTERY,INPUT); //set the battery pin to input
pinMode(DIR1,OUTPUT); //set the dir pin to output
digitalWrite(DIR1,HIGH); //set it high - change HIGH to LOW if motor goes wrong way
motorRun=false;
}
void loop(){
batteryVoltage=analogRead(BATTERY); //convert battery reading to voltage
batteryVoltage*=15000; //*5000*3
batteryVoltage/=1024;
sensorValue = analogRead(analogInPin); // Read the PWM value of the input potentiometer. 0 to 1023
outputValue = sensorValue/4; // convert 0-1023 to 0-255
if(motorRun==true){
if(batteryVoltage<=11900) //this is the cutoff voltage in mV
motorRun=false;
}else{
if(batteryVoltage>12250) //this is the restart voltage in mV
motorRun=true;
}
if(motorRun==true)
analogWrite(PWM1, outputValue); // change the analog out value:
else
analogWrite(PWM1,0);
if((millis()-tick)>100){ //display 10 times per second
tick=millis();
Serial.print("Potentiometer Value = ");
Serial.println(sensorValue,DEC);
Serial.print("Battery Voltage = ");
Serial.println(batteryVoltage,DEC);
if(motorRun)
Serial.println("The motor is running.");
else
Serial.println("The motor is stopped.");
}
}
Well you gave it a nice flow making it easy to follow with good remarks explaining what is going on. That's important since the OP is merely doing a copy and paste. Pretty cool!As the OP is a complete beginner I tried to make the code as simple as possible. Hopefully, they'll be able to start to follow what it does.
Mike.
I think many posters post questions about their solution rather than the original problem.This is not an overt attack, just an observation of this thread as compared to numerous others, which eventually seem to play out the same way.....
There appears to be an excessively-large amount of secrecy when an initial thread is started. Why that is, I have no idea, but details often tend to be pretty scant and helpers almost have to pry information from the close-to-death clutches of those seeking help, lest they take the relevant information to the grave.
It is only when a satisfactory solution is achieved, that the full extent of the initial proposal/requirements become apparent.
If there had been FULL disclosure at the outset, many threads would likely not have to stretch to multiple pages.
My 2c
Good deal and glad the project is doing what was desired of it.Thanks for all the help it works great now my daughters pool pump is completely off grid its been cutting on and off all day and now i don't have to worry so much about it damaging the batteries.. the solar panels charge the batteries then it cuts on and when the battery gets low it cuts off so it can be recharged for the next time
I think what happens here a new to this or similar forum person is directed by a friend or family member to come here. Possibly by someone who also received help. The new member is in unfamiliar territory and not pursuing a career goal in electronics but just needs a project to accomplish a certain task. They know "about" what they expect or want their project to do but often lack the technical background to express in text what they want. Initially those wanting to help just ask more questions to better refine a solution. Eventually enough information is dragged out and things begin to come together.This is not an overt attack, just an observation of this thread as compared to numerous others, which eventually seem to play out the same way.....
There appears to be an excessively-large amount of secrecy when an initial thread is started. Why that is, I have no idea, but details often tend to be pretty scant and helpers almost have to pry information from the close-to-death clutches of those seeking help, lest they take the relevant information to the grave.
It is only when a satisfactory solution is achieved, that the full extent of the initial proposal/requirements become apparent.
If there had been FULL disclosure at the outset, many threads would likely not have to stretch to multiple pages.
My 2c
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?