WTK. If i can use arduino to make this

First of all I’m very new to the Arduino world and I dont have any experience with it
Here is what I want to do:
Take a varying input voltage from a MAF (mass airflow) sensor and use the arduino to control a series of switches based on the input voltage from the sensor.
Will I be able to easily do this, and what other parts would i need? also how difficult would it be to create a program for this?

Thank you

I would start by downloading the arduino IDE and reading some of the tutorials and playground projects here to get a feel for the programming needs and style then deceide if this is something you can do.

Yes you can do it with Arduino. The only issue here is how big a voltage the MAF is putting out. Arduinos ADC ( analog to digital converter) can handle a voltage in the 0 - 5V range and convert it to a number in the 0 - 1024 range (10 bit resolution).

If the voltage from the MAF can exceed 5V or if it is very low, some kind of scaling of the voltage is required. This i well known territory in Arduino land and relatively simple to do.

Yes! it does output 0-5v depending on air flow rate

would it control about 20 relays by itself or would i need additional circuitry to do this?
and if not how much relays would it control by itself?

Are you trying to replace the ECU in your car?

If so, what make/model of car?

no im not trying to replace the ecu but im doing a project at university for a additional fuel delivery system to supplement the present system

IMHO, you may run into boot time issues. If a standard fuel start and delayed switch to alternate / supplemental fuel system is ok, you should be good.

You can control as many relays as you need. For increasing the number beyond the standard pins of the ardunio, check this thread.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222113830/0

Depending on the relays you use, you would likely need some “additional circuitry” using transistors, etc.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222113830/0

I was looking at that thread myself and i think that im going to build the control system very similar to that, but im very uncertain about the actual programming that i would have to do to accomplish this

If you are talking about code to get the 74hc595 to work, there’s code samples here:

You can do a remarkable amount with cut and paste. If you are new to programming, there’s many java tutorials that could get you up to speed on the basic concepts quickly.

Thanks alot for the help so far, and yes I am very new to useful and applied programming.
I trying to get familiar with this language so i’ll tryout the basic tutorials 1st

thestroke,

What type of car is this?
Do you have a OBD interface in the car?
Would it work if you could meassure the real air flow g/s?

its a toyota grande mark II with a 1gfe engine.
yes it has obd interface but im making a supplementary system for the car so i dont want to use a readout from the present system onboard. and in any case the engine only has a temperature sensor and a map sensor as far as i can see thats on the intake.

i wrote some code today after reading various documents and examples on the website, please let me know if this is right and would be sufficient. i’m obviously now only using the digital outputs from the arduino board. the maf sensor gives a range 0-5v output this would be translated into a 0-1023 input for the program and based on the ranges i would control the relays. is this code right, what else would i need to do?

int relay1 = 0;
int relay2 = 1;
int relay3 = 2;
int relay4 = 3;
int relay5 = 4;
int relay6 = 5;
int relay7 = 6;
int relay8 = 7;
int relay9 = 8;
int relay10 = 9;
int relay11 = 10;
int relay12 = 11;
int relay13 = 12;
int relay14 = 13;

void setup()
{
pinMode (relay1,OUTPUT);
pinMode (relay2,OUTPUT);
pinMode (relay3,OUTPUT);
pinMode (relay4,OUTPUT);
pinMode (relay5,OUTPUT);
pinMode (relay6,OUTPUT);
pinMode (relay7,OUTPUT);
pinMode (relay8,OUTPUT);
pinMode (relay9,OUTPUT);
pinMode (relay10,OUTPUT);
pinMode (relay11,OUTPUT);
pinMode (relay12,OUTPUT);
pinMode (relay12,OUTPUT);
pinMode (relay13,OUTPUT);
pinMode (relay14,OUTPUT);
}
void loop()
{
maf = analogRead(0);
if (maf <=73)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,LOW);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
digitalWrite(relay9,LOW);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=146)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,LOW);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
digitalWrite(relay9,LOW);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=219)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,LOW);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
digitalWrite(relay9,LOW);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=292)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,LOW);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
digitalWrite(relay9,LOW);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=365)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,LOW);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
digitalWrite(relay9,LOW);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=438)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,LOW);
digitalWrite(relay8,LOW);
digitalWrite(relay9,LOW);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=511)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,LOW);
digitalWrite(relay9,LOW);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=584)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
digitalWrite(relay9,LOW);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=657)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
digitalWrite(relay9,HIGH);
digitalWrite(relay10,LOW);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=730)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
digitalWrite(relay9,HIGH);
digitalWrite(relay10,HIGH);
digitalWrite(relay11,LOW);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=803)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
digitalWrite(relay9,HIGH);
digitalWrite(relay10,HIGH);
digitalWrite(relay11,HIGH);
digitalWrite(relay12,LOW);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=876)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
digitalWrite(relay9,HIGH);
digitalWrite(relay10,HIGH);
digitalWrite(relay11,HIGH);
digitalWrite(relay12,HIGH);
digitalWrite(relay13,LOW);
digitalWrite(relay14,LOW);
}
else if (maf <=949)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
digitalWrite(relay9,HIGH);
digitalWrite(relay10,HIGH);
digitalWrite(relay11,HIGH);
digitalWrite(relay12,HIGH);
digitalWrite(relay13,HIGH);
digitalWrite(relay14,LOW);
}
else if (maf <=1023)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
digitalWrite(relay9,HIGH);
digitalWrite(relay10,HIGH);
digitalWrite(relay11,HIGH);
digitalWrite(relay12,HIGH);
digitalWrite(relay13,HIGH);
digitalWrite(relay14,HIGH);
}
}

stroke–

This looks like it would probably work. Depending on the voltage read by analogRead(0), you turn on between 1 and 14 relays, right?

A couple of things I would suggest:

  1. Your code uses pins 0 and 1, which are also used for tx/rx by the onboard serial port mechanism. It might be good to select different pins.
  2. I don’t see where “maf” is declared, but this is an oversight easily rectified.
  3. When you use the “cut-and-paste” style of code writing, it makes for difficult-to-maintain code. Bug fixes and tweaks become onerous and perilous when you have to repeat them 14 times. Here’s a condensation of your program that you can use as a sample if you want:

const int numrelays = 14;
const int pins[numrelays] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

void setup()
{
for (int i=0; i<numrelays; ++i)
pinMode(pins*, OUTPUT);*
}
void loop()
{

  • int maf = analogRead(0);*
  • for (int i=0; i<numrelays; ++i)*
    digitalWrite(pins_, (maf <= i * 1024.0 / numrelays) ? LOW : HIGH);_
    }[/quote]
    Best of luck. Let us know how it all works!
    Mikal

Thanks alot Mikal,
As you can see I am very new to Arduino programming.
Which other outputs to use other than pins 0 and 1?
Thank you so much, this is exactly what I wanted, but I must ask, would the code you gave me function the same as what mine did? I am really unsure of how your code functions exactly.

As you can see I am very new to Arduino programming.

Hey, you’re doing great! :slight_smile:

Which other outputs to use other than pins 0 and 1?

You could use, for example, pins 2-15 instead of 0-13. (In case you weren’t aware, the pins marked analog 0-5 may also be used as digital pins 14-19. Of course then you couldn’t use analog 0 as your input pin, but this is easily rectified by moving to, say, pin 2.

would the code you gave me function the same as what mine did?

Yes, with 1 or 2 VERY trivial differences . (For example, when maf is exactly 950, I think my code turns relay13 LOW.)

I am really unsure of how your code functions exactly.

Sometimes I make too many assumptions about peoples’ ability to read code, the same way people sometimes assume I can read a schematic! :slight_smile:

Here’s an annotation:

const int numrelays = 14; // there are 14 pins
const int analogPin = 2; // we’re going to read pin 2 instead of 0
// and these are the pin numbers, stored in an array of size 14
const int pins[numrelays] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};

void setup()
{
// create a loop (i goes from 0 to 13) and set each pin in the array to OUTPUT mode
for (int i=0; i<numrelays; ++i)
pinMode(pins*, OUTPUT);*
}
void loop()
{

  • // read the analog pin to get the voltage from 0 to 1023*
  • int maf = analogRead(analogPin);*
  • // make another loop just like the above*
  • for (int i=0; i<numrelays; ++i)*
  • // depending on whether the expression is true, set the pin high or low.*
    digitalWrite(pins_, (maf <= i * 1024.0 / numrelays) ? LOW : HIGH);_
    }
    The expression “maf <= i * 1024.0 / numrelays” is (almost) the same one you used to manually calculate your original values 73, 146, 219, etc. As i loops from 0 to 13, the value of “i * 1024.0 / numrelays” does this:
    i=0: 0
    i=1: 73.14
    i=2: 146.28
    i=3: 219.43
    etc., almost just like your program.
    Is that any clearer? If you feel uncomfortable with this looping stuff, feel free to use your original program structure. But do change the pin assignments first.
    Mikal

Thank You so much Mikal. Your help is so much appreciated and will help me so much with my project, you made me much more knowledgeable about the code by explaining it, thank you for your time!

Thank you for helping me get puzzling concepts like relays a little clearer in my brain. :slight_smile:

Mikal

hmmm

I built the circuit but the arduino cannot switch on the relay, is there some other IC I could use to amplify the signal using a external power source?