setup uno problems

Hi guys
Im working on a proyect and facing some newby diffis.
intention is that at a given value from BOTH A0 and A1
a led light comes up and if its below to go of, once this is working i would go for a dimm effect the higher the input value is the higher brightness.
once it drops down under the set values to shut led off.
this is so far what i managed to do, thanks for reading.

const int analogIn = A0;
const int RevSignal = A1;
int LED = 2; (in a future will move to a pwm)
int SensorValue = 0;
int Revvalue = 0;
void setup() {
// put your setup code here, to run once:

Serial.begin(9600);

}

void loop() {
SensorValue = analogRead(analogIn);

Serial.print(" tps = "); // prefix to give name to the numbers shown
Serial.println(SensorValue); //angle of attack shown on serial

Revvalue = analogRead(RevSignal);// what needs to be read
Serial.print("\t \t revs = "); //assuming this is the rpm signal cable
Serial.println(Revvalue);//revv a value signal in upto5v
if (analogIn > 100);//minimum value to be reached
if (Revvalue > 400);//minium value to be reached ( BOTH IF values have to meet criteria
{digitalWrite(LED, HIGH);}
if (analogIn < 100);//minimum value to be reached
if (Revvalue < 400);//minium value to be reached ( BOTH IF values have to meet criteria
{digitalWrite(LED, LOW);}

delay(200);
}

thank you all for reading

if (analogIn > 100);oops.

Please remember to use code tags when posting code

 if (analogIn > 100);

A semi-colon tells the compiler that it is the end of the statement, so you should not have one at the end of that line. The general style of an IF should be

if (analogIn > 100 ) {
   // stuff to happen when the test is true
}

...R

Shouldn't you be checking the value of "SensorValue" rather than "analogin"?
All of your if statements need to have the semi colons removed.

I am guessing you meant something like:

if (SensorValue > 100) //minimum value to be reached
{
if (Revvalue > 400) //minium value to be reached ( BOTH IF values have to meet criteria
{
digitalWrite(LED, HIGH);
}
}

or more simply:
if (SensorValue > 100 && Revvalue > 400) digitalWrite(LED, HIGH);

Hi

Thanks for reply
yes, i am looking that i need to go have 2 values at least reaching that threshold before allowing the action.
and below that to go off.
when i checked de serial print the two potientomenters were giving me feedback that i could use to check tps to lauch the functions i need.
Im new to this so all this simple errors for me atm are quite something due to lack of knoweldge, did read a very basic book that has given me a bit of light here.
i appreciate your time to reply.
thank you

i have set this, and the led just is a bit bright, BUT without reaching the criteria.
also now only one potentiomenter attached and i get the values in serial monitor as if BOTH potentiometers are conected doing sinchronuos raise or lower as i turn it.
--update
have solved the problem with
if (SensorValue < 100 or Revvalue < 400) digitalWrite(LED, LOW);
to turn it down.
i am facing the problem now that the shield depending how much i turn the potentiometer it resets.

Danny1000:
i am facing the problem now that the shield depending how much i turn the potentiometer it resets.

You need to post the latest version of your program so we can see exactly what you have done.

...R

this is the update i have done

if (SensorValue > 20 && Revvalue > 25) digitalWrite(LED, HIGH);
if (SensorValue < 20 or Revvalue < 25) digitalWrite(LED, LOW);
if (SensorValue > 20 && Revvalue > 25) Serial.print ("ACTIVATED");
if (SensorValue < 20 or Revvalue < 25) Serial.print ("OFFLINE");

have also sudden drops in value reading, as soon i push a bit the potentiometer the values spike and later go back down and stay stable.

Thank you

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Also before you post your code, in the IDE press CTRL-T, it will format the layout of your code with indents to make it easier to read.

Thanks.. Tom.. :slight_smile:

Danny1000:
this is the update i have done

That's no good on its own. Post the complete program.

...R

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Also before you post your code, in the IDE press CTRL-T, it will format the layout of your code with indents to make it easier to read.

Thanks.. Tom.. :slight_smile:

thanks for the info Tom, Wildo :slight_smile:

const int analogIn = A0;
const int RevSignal = A1;
int LED = 2; //static to test on board this one should be for relay//pws to pitnle for open close function
int LEDPower = 13;//standby 
int LEDboardon = 12;//for activated signal on dash
int LEDshut = 8;//for offline oon dash
int Vled = A2; //for config a stepping with rev increase for prime ?? need to check if works
int SensorValue = 0;
int Revvalue = 0;
void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  pinMode (LEDPower, OUTPUT);
  pinMode (LEDboardon, OUTPUT);
  pinMode (LEDshut, OUTPUT);


}

void loop() {
  SensorValue = analogRead(analogIn);
  Revvalue = analogRead(RevSignal);// what needs to be read

  Serial.print("\t     tps = "); // prefix to give name to the numbers shown
  Serial.println(SensorValue); //angle of attack shown on serial


  Serial.print("\t     revs = "); //assuming this is the rvs signal cable
  Serial.println(Revvalue);//print pulse value
  delay(1500);//for readibilty,readibility 3



  if (SensorValue > 500 && Revvalue > 25) digitalWrite(LED, HIGH);
  if (SensorValue < 500 or Revvalue < 25) digitalWrite(LED, LOW);
  if (SensorValue > 500 && Revvalue > 25) Serial.print ("ACTIVATED");
  if (SensorValue < 500 or Revvalue < 25) Serial.print ("OFFLINE");
  if (SensorValue < 500 or Revvalue < 25) digitalWrite (LEDshut, HIGH);
  if (SensorValue > 500 && Revvalue > 25) digitalWrite (LEDboardon, HIGH);
  if (SensorValue < 500 or Revvalue < 25) digitalWrite (LEDboardon, LOW);
}

this is how the code looks now.
the board craps out because of lack of juice, i need to feed it more power,how to?

thank you all!!

const int analogIn = A0;
const int RevSignal = A1;
"const" means constant, read only, fixed.
I'm sure you don't want that.

and == &&
or == ||

There is a Help>Reference tab in the IDE.
Leo..

thank you for reply.

both const int are meant to be read only, as they have to read only the value the potientomenters are giving.
those will condition the function of the leds and the injector that will be moved to a pwm to get a variable power delivery.
is this correct?
also how con i give more voltage and amps to the circuit or elements? my one seems to dry out.

thank you again

Danny1000:
this is how the code looks now.

I think this does exactly the same thing and is much easier to read IMHO

   if (SensorValue > 500 && Revvalue > 25) {
        digitalWrite(LED, HIGH);
        Serial.print ("ACTIVATED");
        digitalWrite (LEDboardon, HIGH);
    }
    
    if (SensorValue < 500 or Revvalue < 25) {
        digitalWrite(LED, LOW);
        Serial.print ("OFFLINE");
        digitalWrite (LEDshut, HIGH);
        digitalWrite (LEDboardon, LOW);
    }

You can use and and or as easier-to-understand alternatives to && and ||

the board craps out because of lack of juice

I don't understand

...R

Danny1000:
both const int are meant to be read only...

Corrected.
The names put me on the wrong track.
It's always wise to give meaningful names to pins.
const byte sensorPin = A0; and
const byte revPin = A2; would have been better.
I think of revSignal as a value from a revPin.
Leo..

Hi,

the board craps out because of lack of juice, i need to feed it more power,how to?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Please include your power supplies and output devices.

Can you please post a picture of your project?

Thanks,,, Tom :slight_smile:

Hi guys
Sorry for delay

I managed to get it working with the potentiometers.
no wantet to attach this to te rev signal of the engine..and after going through one by one one the cluster i found them.

promblem is that the values are stuck at max 1023 and the revs still go higher, how do i manage to fix this?
currently code looks like this, im sure there are ways to simplify this, for me it works for now as a complete newby :wink: .

i have attached a oled to give me readings without needing the pc.

-the ground has one to the arduino and the other to the chassis of the vehicle and has a steady idle reading of 90 to 100 on the screen, once i flip the switch and revs go up it goes over and signal at halfway are already 1023

int LED1 = 2;           //pin 2
int LED2 = 3;           //pin 3
int LED3 = 4;           //pin 4
int LED4 = 5;           //pin 5
const int register1 = A0;    // input from potentiometer to read value
const int register2 = A1;    // input for register value to be read
int registB = 0;
int registA = 0;      //initial potentiometer value for serial port
#include "ssd1306.h" //oled library
#include <Adafruit_SSD1306.h> //oled library
#define OLED_RESET 4 //oled library
Adafruit_SSD1306 display(OLED_RESET); //oled library

void setup() {
  Serial.begin (9600);      //baudrate
  pinMode (LED1, OUTPUT);   //led 1 out
  pinMode (LED2, OUTPUT);   // led 2 out
  pinMode (LED3, OUTPUT);   // led 3 out
  pinMode (LED4, OUTPUT);   // led 4 out



  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)

  display.display();
  
  // Clear the buffer.
  display.clearDisplay();
  display.setTextSize(1);   //from display begin to display set color is done wor all its work
  display.setCursor(0, 0);
  display.setTextColor(WHITE);

}

void loop() {
  float registA = analogRead(A0);// all this for the oled screen
  display.setCursor(0, 0);
  display.print("REVS: ");
  display.println(registA);
  display.display(); //you have to tell the display to...display
  delay(50);
   
  display.clearDisplay();
  if (registA > 300)display.print ("<<     test     >>");
  
 

  registA = analogRead(register1);   //assign value from readed value from the port A0
  Serial.print("\t  Resistance = ");      //assign preffix in console serial
  Serial.println (registA);             //assign what to show, in this case the live feed from A0 refered as to int potevalue begining from 0
  if (registA > 200 ) digitalWrite(LED1, HIGH);
  if (registA < 200 ) digitalWrite(LED1, LOW);

  if (registA > 300 ) digitalWrite(LED2, HIGH);
  if (registA < 300 ) digitalWrite(LED2, LOW);

  if (registA > 400 ) digitalWrite(LED3, HIGH);
  if (registA < 400 ) digitalWrite(LED3, LOW);

  if (registA > 500 ) digitalWrite(LED4, HIGH);
  if (registA < 500 ) digitalWrite(LED4, LOW);



  if (registA > 550 ) digitalWrite(LED1, LOW);
  if (registA > 550 ) digitalWrite(LED2, LOW);
  if (registA > 550 ) digitalWrite(LED3, LOW);
  if (registA > 550 ) digitalWrite(LED4, LOW);
  delay (50);
  if (registA > 550 ) digitalWrite(LED1, HIGH);
  if (registA > 550 ) digitalWrite(LED2, HIGH);
  if (registA > 550 ) digitalWrite(LED3, HIGH);
  if (registA > 550 ) digitalWrite(LED4, HIGH);
  delay (50);




}

thanks guys.
next i will take picture of it wired up

I have not studied it carefully, but can't this

  if (registA > 200 ) digitalWrite(LED1, HIGH);
  if (registA < 200 ) digitalWrite(LED1, LOW);

  if (registA > 300 ) digitalWrite(LED2, HIGH);
  if (registA < 300 ) digitalWrite(LED2, LOW);

  if (registA > 400 ) digitalWrite(LED3, HIGH);
  if (registA < 400 ) digitalWrite(LED3, LOW);

  if (registA > 500 ) digitalWrite(LED4, HIGH);
  if (registA < 500 ) digitalWrite(LED4, LOW);

be done more neatly (and with less typing) like this

if (registA < 200) {
   digitalWrite(LED1, LOW);
}
else if (registA < 300) {
   digitalWrite(LED2, LOW);
}
else if //etc etc

...R