The Idea is to use a 10K potentiometer to change the LCD to display 32 different "speeds" and at the same time turn on and off 8 different outputs
The 10K pot. is wired to A0 and is working well.
The LED display is serial and when not active in a loop it too works well, when active in a loop it flickers.
The outputs are wired to a 8 Relay module that is powered by a extra 5vdc supply, it too works well as long as there is only one condition.
The Problem I am having is in the code (that I have copy and pasted a lot) is after testing the a " if ((sensorValue >= 64) && (sensorValue < 96))
{{ digitalWrite(Relay_25, LOW);}
mySerial.write(12); //Clear
delay(10);
mySerial.print(".021 in.pm");
mySerial.write(13);
mySerial.print(".52 mm.pm");}
else { digitalWrite(Relay_25, HIGH);}
by its self works great relays are solid LCD flickers a little but useable
as soon as I put more "if" conditions in the loop the relays change but chatter on and off at a fast rate
Any Ideas?
Oh yea this is my first project and first posting and don't mean to offend anybody with my lack of knowledge or that they might see that I have used there code inappropriately.
#include <Boards.h>
#include <Firmata.h>
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to //
const int TxPin = 6;
#define RELAY_ON 0
#define RELAY_OFF 1
/-----( Declare objects )-----/
/-----( Declare Variables )-----/
#define Relay_25 8 // Arduino Digital I/O pin number
#define Relay_26 9
#define Relay_27 10
#define Relay_31 11
#define Relay_70 12
#define Relay_33 13#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);int sensorValue = 0;
int outputValue = 0;// value read from the pot
// value output to the PWM (analog out)void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
digitalWrite(Relay_25, RELAY_OFF);
digitalWrite(Relay_26, RELAY_OFF);
digitalWrite(Relay_27, RELAY_OFF);
digitalWrite(Relay_31, RELAY_OFF);
digitalWrite(Relay_70, RELAY_OFF);
digitalWrite(Relay_33, RELAY_OFF);
pinMode(Relay_25, OUTPUT);
pinMode(Relay_26, OUTPUT);
pinMode(Relay_27, OUTPUT);
pinMode(Relay_31, OUTPUT);
pinMode(Relay_70, OUTPUT);
pinMode(Relay_33, OUTPUT);
delay(4000); //Check that all relays are inactive at Reset
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
mySerial.begin(9600);
delay(100);
mySerial.write(17); //Back light on
}void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);if ((sensorValue >= 0) && (sensorValue < 32))
mySerial.write(12); //Clear
delay(10);
mySerial.print(".012 in.pm");
mySerial.write(13);
mySerial.print(".28 mm.pm");
delay(2);
if ((sensorValue >= 32) && (sensorValue < 64))
{{ digitalWrite(Relay_26, LOW);}
mySerial.write(12); //Clear
delay(10);
mySerial.print(".016 in.pm");
mySerial.write(13);
mySerial.print(".4 mm.pm");}else { digitalWrite(Relay_26, HIGH);}
delay(2);
if ((sensorValue >= 64) && (sensorValue < 96))
{{ digitalWrite(Relay_25, LOW);}
mySerial.write(12); //Clear
delay(10);
mySerial.print(".021 in.pm");
mySerial.write(13);
mySerial.print(".52 mm.pm");}else { digitalWrite(Relay_25, HIGH);}
delay(2);
if ((sensorValue >= 96) && (sensorValue < 128))
{{ digitalWrite(Relay_25, LOW);}
digitalWrite(Relay_26, LOW);
mySerial.write(12); //Clear
delay(10);
mySerial.print(".029 in.pm");
mySerial.write(13);
mySerial.print(".71 mm.pm");}
else { digitalWrite(Relay_25, HIGH);
digitalWrite(Relay_26, HIGH);}delay(2);
}
analog_milling_speed_feed.ino (2.86 KB)