User:Boohyabuddha/ENES100/Project2

Project 2
Compost Monitoring Bin

Problem Statement
See Project 1 Link

Project Plan
- Construct sensor array - Create fan/sensor switch - Finalize overall construction (door, crank, chamber/tubes) - Test chain of events in bin usage (turning crank, fan timing, etc.)

Week 1
I was able to find a simple sketch for reading the gas sensors, outputting the RawADC for use in a later void(loop):

int gasSensor = 0; // select input pin for gasSensor int val = 0; // variable to store the value coming from the sensor

void setup { Serial.begin(9600); }

void loop { val = analogRead(gasSensor); // read the value from the pot Serial.println( val ); delay(100); }

The datasheet for the MQ-4 sensor doesn't list a necessary resistance, but I think using NPN transistors with small resistors, as well as a voltage regulator from the power source (9v wall wart). There doesn't seem to be an issue with overburning the sensors, more with too high voltage going back to the Arduino. MQ-4 Datasheet

The Figaro TGS 2602 sketch for this sensor will be a mirror of the MQ-4 sensor, changing the the input pins and output declarations as necessary. Figaro TGS 2602 Datasheet

void(loop):

int gasSensor = 1; // select input pin for gasSensor

int val = 0; // variable to store the value coming from the sensor

void setup { Serial.begin(9600); }

void loop { val = analogRead(gasSensor); // read the value from the pot Serial.println( val ); delay(100); }

Next steps will be to combine to two codes while testing with propane or other low grade gases in order to ensure that they are both picking up the gases being detected. After that, the next step will be to use isolated gases to determine if there is redundancy in their detection (since both detect methane at differing degrees) and also if the setup works to begin with in detecting the specific gases.

Also next will be to use the values put out by the sensors for sending a signal to an LED when HIGH values are reached, similar to this code:

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to const int ledPin = 13;                 // LED connected to digital pin 13 int sensorValue = 0;       // value read from the sensor

void setup { Serial.begin(9600); pinMode(ledPin, OUTPUT);     // sets the digital pin as output }

void loop { sensorValue = analogRead(analogInPin); if (sensorValue >= 750) {   digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }

Serial.print("sensor = " ); Serial.println(sensorValue);

delay(10); }

With regard to preheating/burning in the sensors, the solution I came up with is to use NPN transistors hooked up to the sensors which will allow the necessary 5v of power to preheat them while limiting the draw of power from the Arduino itself. The power source will go through a small voltage regulator to enable only the 5v necessary to reach the sensors.

See figure 2-10 for a basic schematic: Gas Sensor Tutorial

Now that the basic code is completed, I can focus on assembling the gas sensors and transistors and voltage regulator together with the power source, and test the effectiveness of the sensors using butane/propane and a hydrogen sulfide byproduct. After this, it will be a matter of toying with the code so that an LED will light when there is a high concentration (later to be changed/modified to another means of communicating the reading.)

Week 2
Problem: On the weekend when I was supposed to be programming the code and testing the gas sensors, my Arduino wasn't being recognized by my computer anymore. I attempted to get it working on my desktop assuming it was an issue with Linux, but I had no luck getting it to work on there as well.

Unable to test the sensors, I began further conceptualization of the bin and it's mechanisms and came up with the following:

This week I will cut the bin door and install hinges and tubing to seal the bin. The hinges will be small, standard hinges used on cabinets, and the tubing will be surgical tubing that's scored and placed on the edges of the lid to ensure a tight seal. (In theory.)

The holes in the crank will be drilled every 3in along the non-joint portions, and will be placed on alternating spots along each of 45-degree faces of each tube. We will also place the intake shaft into the crank. Unfortunately, due to lack of foresight on my part, I forgot to mark where the holes in the intake shaft should be prior to gluing the crank together, so we will have to measure where the joints are and drill holes into the shaft where the joints meet.

To seal the lid, we will use the same surgical tubing and glue it to the inside of the lid, and using clamps (yet TBD type of clamps) to tighten the lid into place on the bin.

A wooden wheel with a handle will be made to place on the end of the shaft for turning the crank, and a cap system will be used to cover the exposed end of the shaft when in use. In other words, the cap will be placed on when the crank is turned to ensure no excess outside air will be allowed in, and the cap will be removed when not in use to allow aeration.

Sensor placement: in class this week we can determine the exact locations for the DHT11 relative humidity/temperature sensor (most likely in the upper corner of the bin away from the crank blades) and the moisture/internal temperature sensor (on the bottom of the bin in a way that prevents contact with the blades). The reed switch (still to be purchased) will be placed on the bin itself, while the magnet will be placed on the rotating wheel; this is simply so that the wires of the reed switch and the switch itself are stationary and will be interfered with minimally. We can also begin deciding where in the gas chamber we will place the sensors and how to place them in there without disrupting the integrity of the sealing.

Power supply: The power supply can be a 9v wall wart that is split to the Arduino and also the the voltage regulator that will be connected to the gas sensors for preheating. Another option is to use a 12v wall wart with two voltage regulators: one for the gas sensors, and another for the Arduino, since the Arduino can only handle up to 9v, and even then risks overheating.

Once an auxiliary Arduino is attached and the gas sensors can be tested, our next step (outside of putting the whole system together) will be to test the over all functionality of the non-electronic parts, i.e. crank, siphoning, sealing, etc. We can do this by using a smoke bomb or smoldering some material that will emit smoke and allow us to track the air flow and detect sealant issues. Regarding the next step with electronics, we can being to physically connect all of the sensors and power together and integrate it into the bin. We will do this not so much focusing on the sensors working in unison, but more to ensure that there are no physical limitations we haven't uncovered yet, such as lack of necessary inputs, physical interference of the wires and different parts, insufficient power supply, etc.

Week 3
First task: Convert vacuum pump from batteries to AC power.

My initial trial with just splicing the AC wall wart wire and using the motor's positive and negative contacts didn't work. The light on the wall wart would turn off on contact, probably meaning that the power is too high.

Using Ohm's Law, I figured out that the motor resistance when used with 2.2A/6v batteries in series is 2.7272Ohms. Plugging in the 7v wall wart we've tried to use, that puts the current at 2.567A, which might be the source of the issue. We will have to lower the current by bringing the resistance total (motor + resistor(s)) down by adding roughly .5Ohms. We can do this by adding a 1Ohm/1Ohm resistor parallel to the circuit, which should add .5Ohm, bringing the current down to about 2.16A. However, this doesn't take into account the Ampere rating of the wall wart. There are two ways to approach this problem:

1) Drop the voltage to 6V, disregarding current.

2) Drop the current using the 1Ohm resistors in parallel, keeping the 7v power.

3) Create a voltage regulator circuit using an LM350, with 2.7Kohm in R2 and 700Ohm in R1 (or any two resistors that when R2/R1=3.8...)

Barring this not working, the following are still options, we will have to use the batteries and solder a relay that can be controlled by the Arduino to turn on and off the vacuum pump.

Second Task: Wire sensors to Arduino

With a new Arduino cable, I was able to load the gas sensor code from week 1 onto the Arduino. Unfortunately, my propane tank on my grill was either too low to affect the reading, or the sensor was unable to detect the propane inside of the grill due to too much air being allowed in. However, I was getting RawADC readings on the serial monitor from the gas sensor, but I was unable to verify that the readings would vary based on LDG prescence. There's also a chance that they hadn't preheated long enough to burn in the baseline; I let the sensor run hot for about 6 hours (since I didn't feel safe leaving it running for the 24 hours necessary) while a cat and other elements are present. I will have to run the sensors for up to 48 hours to get a basic burnt in reading, which will have to be done in a controlled environment, most likely at class and stowed away before testing with butane or another LDG.

Next steps: How to display/save the information?

As of now, the information is merely being forwarded to the serial monitor on the computer, which, for testing and calibration purposes, is fine; however, to truly integrate it into the whole bin concept, it will need to provide a more compact means of displaying this information. One option that's available to me right now is a 2x16 LCD screen. This will require Arduino code manipulation and organization, as well as clever tricks to display all the data on such a small display, while providing the updates necessary for the user.

Next steps: Timing with reed switch

We also need to start integrating the reed switch into the Arduino code and compost bin. This will be sent to the Professor for purchasing and we can start thinking of how to time the vacuum pump and sensors so that the air is drawn out of the bin and into the chamber, and then flushed out after a reading has taken place. Reed Switch

Next steps: Shared power source?

As of now, we haven't given thought to how to provide power to the whole system. It will really depend on how the pump is powered; if it is batteries with a relay switch, then it can be powered by the 5v wall wart that the Arduino and sensors will run on. If we decide to create dummy batteries, then we can use the same wall wart for the pump and Arduino, but will have to regulate the voltage coming from the wall wart to the Arduino since it optimally operates at the 5v range. Voltage Regulator

Next steps: Transistors/voltage regulator

The Arduino cannot reliably power the gas sensors and other sensors on the same power source; the gas sensors, as mentioned in Week 1, will have to be powered by an external power source that runs through a voltage regulator and npn transistors that are controlled by the Arduino. Once the gas sensors are proven to function as intended, I can then breadboard the sensors with the transistors and voltage regulator, and use a 5v or so wall wart to power the sensors to enable a constant state of readiness (i.e., it will be preheated always; this is the only way to get immediate readings while using the bin since activating the power to the sensors upon use will not provide sufficient and convenient usage considering the preheat times necessary for the sensors.)

Week 4
I successfully wired together a relay to the vacuum pump. I desoldered the toggle switch and replaced it with ground/5V wires attached to the triggered side of the relay, and successfully turned it on by connecting the switch side of the relay to a battery pack. I then placed the ends into an Arduino to run a simple code that would turn on and off the digital pin, and it worked perfectly!

The gas sensor is preheated finally after my computer/USB hub was messed with. I soldered the MQ-4 according to the datasheet (Wiring Sample) with three prongs soldered to 5v, two soldered to ground with a 10Kohm resistor to act as a voltage divider, and the third prong to A0. Using a serial.print application, I was able to see the RawADC fluctuate but stay under 10. I then attempted to use a butane lighter without the flame to see if that would increase the RawADC, but it didn't affect it. I'm not sure if butane won't change the RawADC, or if I wired it incorrectly, but there was no change. I will have to play around with it to see if it's the wiring or using the incorrect gas. The simplest way to test would be to use actual methane, but I don't have ready access to it, so I will have to find a way to test.

Next steps I think are to begin working on a power supply that will work with the Arduino and gas sensors using NPN transistors, and also creating a basic code so that the vacuum pump is triggered by the reed switch. Also, the internal thermistor will need to be rebuilt, and the internal moisture reader will need to be refined.