Arduino Manager Development for All

Hey all,

I just recently started to get into Arduino. I am absolutely a complete novice and like many, this really seemed like it would be very difficult to learn.

Yes at first it is a bit hard to get started, but if you just watch the many tutorials and start from the beginning its gets easy.

I can now at least write some simple code and now know enough to take apart the example codes, modify them and put bits and pieces together to make my own working code.

So the reason for this thread is to share code and info on systems related to gasifier control systems.

I will start with my project; to develop a working system to control an air intake mixing system.

Below are all the parts you need to build this.

5 v Regulator (Qty 2 pcs)

http://www.ebay.com/itm/221034363897?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

Servo Motor (Qty 1)

Arduino UNO R3 (Qty 1)

http://www.ebay.com/itm/251459710321?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

Potentiometer (Qty 1)

http://www.ebay.com/itm/231020751109?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

Screw Shield for Arduino Board (Qty 1)

http://www.ebay.com/itm/Proto-Screw-Shield-Assembled-Arduino-Compatible-USA-INSTOCK-Ready-to-Ship/381028511132?_trksid=p2047675.c100011.m1850&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D27538%26meid%3Da92891355451485e991b19baf7834509%26pid%3D100011%26prg%3D11353%26rk%3D1%26rkt%3D10%26sd%3D380647258164

O2 Sensor kit with 5v analog input leads (Qty 1)

http://www.ebay.com/itm/271089987747?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

To learn how to set this up here is a pretty good tutorial on servos. This shows how the 5v reg needs to be set up.

2 Likes

I have multiple code for this project, The code Im going to list here is a “case” code. My project is set up with two inputs, one from the o2 sensor and one from a potentiometer for manual operation. Both inputs are wire to a dual pole relay. I have the pot switch wired to the normally closed position of the relay while the O2 sensor is wired to the normally open side. The lead out is then wired to the Input A0 of the arduino. So in manual mode the relay is off (Pot Input) and in auto mode the realy is on (O2 sens input)

I am going to run all code and will give details on the progress. You can copy and past this into the Arduino IDE and then upload it to your Arduino

#include < Servo.h >

Servo myservo; // create servo object to control a servo

int pos = 0; // variable to store the servo position

const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 1023; // sensor maximum, discovered through experiment

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}

void loop()
{
int sensorReading = analogRead(A0);

 // read the input on analog pin 0:

int sensorValue = analogRead(A0);
Serial.println(analogRead(A0));

  int SensepinVal = map(sensorReading, sensorMin, sensorMax, 0, 36);

switch (SensepinVal) {

case 0:
myservo.write(180); // Moves servo positive 10 degrees
break;
case 1:
myservo.write (175); // Moves servo negative 10 degrees
break;
case 2:
myservo.write (170); // Moves servo positive 20 degrees
break;
case 3:
myservo.write (165); // Moves servo negative 20 degrees
break;
case 4:
myservo.write (160); // Moves servo positive 40 degrees
break;
case 5:
myservo.write (155); // Moves servo negative 40 degrees
break;
case 6:
myservo.write (150); // Moves servo positive 80 degrees
break; 
case 7:
myservo.write (145); // Moves servo positive 120 degrees
break;     
case 8:    
 myservo.write(140); 
break;
case 9:    
myservo.write(135); //Machine is happy do nothing
break;
case 10:
myservo.write(130); // Moves servo positive 10 degrees
break;
case 11:
myservo.write (125); // Moves servo negative 10 degrees
break;
case 12:
myservo.write (120); // Moves servo positive 20 degrees
break;
case 13:
myservo.write (115); // Moves servo negative 20 degrees
break;
case 14:
myservo.write (110); // Moves servo positive 40 degrees
break;
case 15:
myservo.write (105); // Moves servo negative 40 degrees
break;
case 16:
myservo.write (100); // Moves servo positive 80 degrees
break; 
case 17:
myservo.write (95); // Moves servo positive 80 degrees
break; 
 case 18:
myservo.write(90); // Moves servo positive 10 degrees
break;
case 19:
myservo.write (85); // Moves servo negative 10 degrees
break;
case 20:
myservo.write (80); // Moves servo positive 20 degrees
break;
case 21:
myservo.write (75); // Moves servo negative 20 degrees
break;
case 22:
myservo.write (70); // Moves servo positive 40 degrees
break;
case 23:
myservo.write (65); // Moves servo negative 40 degrees
break;
case 26:
myservo.write (60); // Moves servo positive 80 degrees
break; 
case 27:
myservo.write (55); // Moves servo positive 80 degrees
break;   
case 28:
myservo.write (50); // Moves servo positive 20 degrees
break;
case 29:
myservo.write (45); // Moves servo negative 20 degrees
break;
case 30:
myservo.write (40); // Moves servo positive 40 degrees
break;
case 31:
myservo.write (35); // Moves servo negative 40 degrees
break;
case 32:
myservo.write (30); // Moves servo positive 80 degrees
break; 
case 33:
myservo.write (25); // Moves servo positive 80 degrees
break;    
case 34:
myservo.write (20); // Moves servo negative 40 degrees
break;
case 35:
myservo.write (15); // Moves servo positive 80 degrees
break; 
case 36:
myservo.write (10); // Moves servo positive 80 degrees
break;  
case 37:
myservo.write (5); // Moves servo positive 80 degrees
break; 
case 38:
myservo.write (0); // Moves servo positive 80 degrees
break;  

}
delay(500);
}

This code is using “if else” statements. This one still needs the relay to switch to an auto mode; however, the pot switch input is wired to another input pin for manual operation. When the code reads the O2 sensor input it will not look at the the input from the potentiometer and should skip over it. But in order for the pot switch to work the input from the O2 sensor needs to be turned off.

Here is this code “O2 Sensor v0.1.6”

#include < Servo.h >

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
// These constants won’t change:
const int analogPin = A0; // pin that the sensor is attached to

const int threshold1 = 500;
const int threshold2 = 700; // an arbitrary threshold level that’s in the range of the analog input
const int threshold3 = 200;
const int threshold4 = 800;

int pos = 0; // variable to store the servo position
int potpin = 1; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// initialize serial communications:
Serial.begin(9600);
}

void loop()
{
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);

// if the analog value is high enough, turn on the LED:
if (analogValue > threshold1)
{
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(180); // tell servo to go to position in variable ‘pos’
delay(25); // waits 15ms for the servo to reach the position
break;
}}
else (analogValue > threshold2);
{
for(pos = 180; pos>=0; pos -=1 ) // goes from 180 degrees to 0 degrees

myservo.write(0);              // tell servo to go to position in variable 'pos' 
delay(25);    // waits 15ms for the servo to reach the position 

}
if (analogValue < threshold3);
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 50, 950, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(2000); // waits for the servo to get there
}
if (analogValue > threshold4);
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 50, 950, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(2000); // waits for the servo to get there
}}

1 Like

That would be fun to learn, but a steep learning curve for us oldsters. I appreciate your list of “toys”, but gagged on the O2 sensor. Serious toys there! Also our friend Jeremy, like most “youngsters” talks over the speed limit, and don’t bother pronouncing certain consonants that make it easier for us “oldsters” to understand what the heck he’s saying. Still, very interesting stuff, and I thank you for a beginners list of parts.

1 Like

I should mention the text after the “//” is annotation. Do not pay too much attention to it on my code. It needs to be updated as I have copied and pasted this from other code and some of it does not pertain to my code.

1 Like

Ill try my best Carl. Hope some others will help out here. I really think the arduino is the next step for us to get gasification technology to the next level. I hope I can find some time to do a video on this with all the details so you guys can follow along.

2 Likes

Yeah I know Carl most of the tutorials are like that. They don’t explain the basics of the basics well enough. Why things need to be formatted the way they are and the simple things like this. I bought Arduino for dummies, this has been a great help

1 Like

Matt,
Are these useful in just stationary units?

1 Like

To be perfectly honest I don’t know at this point. I still need to fire up a machine and try it out. But yes the intent is for all gasified engines. If it will work on our stationary V8 I don’t see why it would not work on something with altering throttle movements. The arduino is very fast and the servo movement should be quick enough to respond to acceleration.

We are on track to finish the big machine this week, if we don’t run into any more challenges we should be ready to run on Friday. Ill post a video on this as soon as I can.

2 Likes

Matt
Can a narrow band o2 sensor be used? I was surprised by how well the cheap gauges work with woodgas. On gasoline they provide a lightshow at best.

Marvin

1 Like

From what I understand the narrow band sensors do not provide a signal that is useful for an input. Im not sure what you would need to use the raw signal from either narrowband or wideband sensor. This is why I buy the kit with the provided 5v signal wires, might cost a little extra but it comes with a display. Without the physical display it will be difficult to know what is going on so this is good tool to add. Im sure this can be done cheaper as well. I like the AEM kits because of their quality and simple installation.

1 Like

is our friend Jeremy using? This shows how dumb I am.

1 Like

Carl
I think he says in this video. (I didn’t understand but I think it’s there).
Marvin

1 Like

Hi Matt.
I do a bit of Arduino stuff myself.
What is the servo going to control? And, is it strong enough?

I have been testing an O2 sensor myself recently and I was surprised to discover how stable my narrow band sensor’s output is with varying changes in carburetor main jet setting. Just as you just said, I had thought that the opposite would be true. In my case, a throttle position sensor being pushed by a governor arm is a LOT better indicator that the engine needs more gas.

See:
http://www.spaco.org/JXQ10A.htm
and look down the page a little way to the entry
“July testing of Throttle Position Sensor and Oxygen Sensor on Generator”
This test was running on gasoline only.
I ran a short dual fuel test of this system in September (which I think I have already reported on) but I didn’t run an engine long enough for the O2 sensor to heat up enough to get into its operating range.
I suppose woodgas could be different animal, and I will find that out shortly if it doesn’t go below zero in the next week or two.

Pete Stanaitis

1 Like

Arduino language, or simplified “C”.

1 Like

Hey there Pete, you are light years ahead of me on the Arduino. This echoes what Marvin is stating as well. I hope that you can keep us posted on your progress. I think this is one of the missing pieces to make gasifier engines systems much more practical any application. If we can source less expensive parts to make a working system this would be a great thing. I will keep my code updated as we go as well. We are very close to testing the electrical, If all goes well tomorrow I will be in a position to fire up the electrical. Then if everything passes we will fire up the machine and test run the engine on Saturday.

I like the data logger is something you created or is this available somewhere for download?

The Servo Im using is a high torque metal gear not sure what the torque speck is. However, I am operating a 55 mm throttle body I picked up on Ebay. I took out one of the return springs and it takes no effort for this servo to move it. Ill take some pictures of this tomorrow and post.

@Carl good question, I think this is a language specific to arduino, but it is simplified and based on C. If im am incorrect someone please correct me.

1 Like

I looked up the torque on that servo:

  • Model: TowerPro MG995 Metal Servo
  • Dimensions: :4.071.974.29cm
  • Speed: 0.2sec/60°(4.8V)
  • Torque: 10kg-cm
  • Rated Voltage: 4.8-7.2V
    Dimensions: 0 in x 0 in x 0 in
    Weight: 2.4 oz
    the Google converter says that’s 0.7 ft lb
    or
    9 pound inches

I asked that because it takes a lot of force to move some valves that are designed for water flow and such. I think Steve A. has done some work to loosen up one of those valves to be operated with a similar servo.

Datalogger:
I got the idea from the GEK guys and their GCU (Gasifier Control Unit). They build and sell a custom device that does much more than mine does and it’s all professionally done. It already has all the inputs and outputs that any of us would need and all the basic code has already been written and debugged. They have several versions of it at varying prices.
As you can see from my webpage, mine device is totally home-brew.

Car: regarding the Arduino Language:
I’m not a programmer, but we have a couple of them in our small Arduino group and he says this:
Before the Arduino arrived on the scene, there was a Language out there called “Processing”. It was (I think) written in the JAVA programming language. Tbat language was used to convert inputs from outside of the computer so it could be displayed and managed inside the computer. I think this language was designed to be used by non-programmer artistic people who wanted to be able to do art on the computer, or something like that.

When the Arduino was being born, it’s developers hitchhiked on that Processing language
to develop a language for the Arduino specifically, that followed a similar path, that is, a language that us non-programmer types could understand and use.
If I got it right, most or all of the “Arduino IDE” (Interactive Development Environment) was based on the Processing software, but written in the “C” language, more specifically a later version of “C” called “C++”.
Confused yet?
What they did was to take tons of arcane (to me) code and translate it into words that we might understand.

If you want to get a handle on this instead of watching reruns of the “Mountain Man” gasifier program, you could go to:

But I have to warn you that this stuff can become addictive. At last night’s meeting, one guy brought in a package he just received from china. It had 10 Arduino clones in it on Monday. But by Thursday, he had already put 6 of them into projects. They cost $6.60 cents each.

Pete Stanaitis

I have some new code, this is still untested and only ran under simulation. But this is what I have been looking for.

I ran a simulation on this with a pot switch in place of the O2 Sensor input. So if I simulate a rich condition, the servo will search in increments opening the valve and vise versa if I lean out the sensor input.

The trick is also to get another input signal, so you can manually adjust the valving for start ups. So what the code looks for first is a near 0 voltage signal, if this condition is true I can then move the valve using the pot on the control panel. To ensure i have no voltage coming from the O2 sensor I have an override switch that signal run through. So I can basically find the sweet spot manually during start up and get things into the right parameters.

Then when the engine is up and running I can then turn on the switch supplying voltage from the sensor. The conditions will then be beyond near 0 voltage and the other two sets of code can then intervene.

In the code, is a set of parameters (thresholds) that the code is trying to satisfy. These parameters can be changed so this can be tuned to the sweet spot. The second set of code looks for voltage lower than (threshold 1) and the third set of code looks for a lean condition voltage higher then (threshold 2). I have the parameters set up with a gap somewhere in the middle of the available signal. So if the input signal falls in this gap nothing will change.

In the second and third set is a time delay, this is how fast the code is read. Basically if a condition is not met the controller will out put for the time set in the delay for that part of the code. So if a lean condition is detected, the servo will try and move fully closed. If I give it too much time it will fully close before moving on to the next set of code. We don’t want this, we just want the servo to move a tiny bit and then the code to be looked at again to see if conditions are met. If not the servo will move again and so on.

So the delay can also be changed to allow for longer or shorter movement between readings.

In this code I have it set for 2 ms. I think this will be too fast and tweak on this tomorrow. For now Ill post this if any one wants to play with it.

#include < Servo.h >

Servo myservo; // create servo object to control a servo

// These constants won’t change:

const int threshold1 = 450;
const int threshold2 = 550; // an arbitrary threshold level that’s in the range of the analog input
const int threshold3 = 200;

int analogPin = A0; // pin that the 02 sensor is attached to
int pos = 0; // variable to store the servo position
int potpin = 1; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// initialize serial communications:
Serial.begin(9600);
}

void loop()
{
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);

if (analogValue < threshold3)
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 50, 950, 0, 180); // scale it to use it with the servo (value between 0 and 180)
delay(15); // waits for the servo to get there
}
else if (analogValue < threshold1)
{
for(pos = 180; pos>=0; pos -=1 ); // goes from 180 degrees to 0 degrees
delay(2); // waits 2ms for the servo to reach the position
}
else (analogValue > threshold2);
{
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
delay(2); // waits 2ms for the servo to reach the position
}
}

1 Like

Hi Matt,

Just a thought on the Arduino PLC solution. I have found success in creating an array to average/smooth the readings from the O2 sensor.

-Joe

1 Like

Hi Joe can you give us an example of your code?

Here is my latest and greatest version, I have tested a previous version and it worked. I was having an issue when called to a lean condition and the servo would delay too long. I think I figured this out the last line had a write position of + 10 and I think this was hanging it up. So changed this last line to write the actual position of 180 and this seemed to fix it on my proto experiment.

I will be giving this another shot tomorrow.

Video will come later this week. We are finally getting over a lot of challenges we had ran into with this machine. The HGRS system is working as planned, the machine is processing fuels with 30% moisture and dropping lots of moister while the left overs are super heated and processed. I think we have something here!!

Here is the new code

#include < Servo.h >

Servo myservo; // create servo object to control a servo

int pos = 0; // variable to store the servo position
int lastpos = 90; // variable to store the servo last position
int potpin = 1; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 1023; // sensor maximum, discovered through experiment

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);

}

void loop()
{

int sensorReading = analogRead(A0);

int SensepinVal = map(sensorReading, sensorMin, sensorMax, 0, 10);
switch (SensepinVal) {

  case 0:
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023,0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(1);                           // waits for the servo to get there 
     break;
  case 1:
     // we need to move the servo 10 degrees in the POSITIVE
     // direction so we need to add ADD to the last known 
     // position.
     myservo.write (lastpos + 10); // Moves servo positive 10 degrees

     // now we need to save that last position value 
     lastpos = (179);
     delay (20);
     break;
  case 2:
     // we need to move the servo 10 degrees in the POSITIVE
     // direction so we need to add ADD to the last known 
     // position.
     myservo.write (lastpos + 10); // Moves servo positive 10 degrees

     // now we need to save that last position value 
     lastpos = lastpos + 10;
    delay (20);
    break;  
    case 3:
     // we need to move the servo 10 degrees in the POSITIVE
     // direction so we need to add ADD to the last known 
     // position.
     myservo.write (lastpos + 10); // Moves servo positive 10 degrees

     // now we need to save that last position value 
     lastpos = lastpos + 10;
    delay (20);
    break; 
    case 4:
     // we need to move the servo 10 degrees in the POSITIVE
     // direction so we need to add ADD to the last known 
     // position.
     myservo.write (lastpos + 10); // Moves servo positive 10 degrees

     // now we need to save that last position value 
     lastpos = lastpos + 10;
    delay (30);
    break; 
      case 5:   
     // we need to move the servo 10 degrees in the POSITIVE
     // direction so we need to add ADD to the last known 
     // position.
     myservo.write (lastpos + 10); // Moves servo positive 10 degrees

     // now we need to save that last position value 
     lastpos = lastpos + 10;
    delay (50);
    break;
    case 6:
     // All is well and nothing has to change 
     // so we do not need to move the servo
     // myservo.write(0); //Machine is happy do nothing
     delay (500);
     break;    
  case 7:
     // we need to move the servo 10 degrees in the NEGATIVE
     // direction so we need to SUBTRACT 10 to the last known 
     // position.
     myservo.write (lastpos = lastpos - 10); // Moves servo negative 10 degrees

     // now we need to save that last position value 
     lastpos = lastpos - 10;
     delay (60);
     break;  
   case 8:
     // we need to move the servo 10 degrees in the NEGATIVE
     // direction so we need to SUBTRACT 10 to the last known 
     // position.
     myservo.write (lastpos = lastpos - 10); // Moves servo negative 10 degrees

     // now we need to save that last position value 
     lastpos = lastpos - 10;
     delay (40);
     break;        
  case 9:
     // we need to move the servo 10 degrees in the NEGATIVE
     // direction so we need to SUBTRACT 10 to the last known 
     // position.
     myservo.write (lastpos = lastpos - 10); // Moves servo negative 10 degrees

     // now we need to save that last position value 
     lastpos = lastpos -10;
     delay (30);
     break;
  case 10:
     // we need to move the servo 10 degrees in the NEGATIVE
     // direction so we need to SUBTRACT 10 to the last known 
     // position.
     myservo.write (lastpos = lastpos - 10); // Moves servo negative 10 degrees

     // now we need to save that last position value 
     lastpos = (0);
     delay (30);
     break;      

}
}

1 Like