Hey,
I am all new to Arduino and started learning a few weeks ago, great stuff! I've been trying to set up a project using an Sharp dust sensor DN7C3CA006 but I cant get the readings stabilized. I might have misunderstood the datasheet but would be great if someone could point me in the right direction.
I have attached a photo of the set-up, code also the circuit diagram.
Components:
- Arduino Uno
- Sharp dust sensor DN7C3CA006, datasheet http://media.digikey.com/pdf/Data%20Sheets/Sharp%20PDFs/DN7C3CA006_Spec.pdf
- 5V DC supply
- 220uF capacitor (for sensor)
-150 ohm resistor (for sensor) - Transistor P2N2222AG
- 333 ohm resistor (for the transistor)
First 50 seconds I run the sensor without the fan and store read values to calculate an averaged Vs value. After set ref value I turn on the fan and start printing data (read voltage, difference between V0 and Vs, dust density). I've added the transistor to allow for a remote of the sensorFan by opening the transistor after I have set the reference point.
Ive seen a lot of people using the GP2Y1023AU0F but not the DN7C3CA006.
Hope for your help!
/Seb
// Declare variables for input/output pins
int measurePin = 0; // Analog pin 0 used as output voltage from sensor to Arduini
int ledPower = 12; // Digital pin 12 used as ON/OFF for sensor LED
int fanpowerPin= 8; // Digital pin 8 used as ON/OFF for sensor fan
// Declare variables for pulselength, pulse width, and when to read the output signal
int samplingTime = 280; // Sample 0.28ms into the pulse width
int deltaTime = 40; // time left of pulse width after read value
int sleepTime = 9680; //Pulse period 10ms. 10000ms-320ms=9680ms to wait before next led pulse
// Declare variables used to store data
float voMeasured = 0; // Stores measured output (0-1023) from sensor
float calcVoltage = 0; // Calculate actual voltage output from sensor
float dustDensity = 0; // Calculate dust density [ug/m3]
float vS = 0; // Vs reference value (no fan running for a 100 readings minutes
// Declare variables used to store reference voltage when sensor fan is not running
int countReading = 600; // Stores number of sensor readings when fan is not running
int vSrawvalue =0; // variable to store raw value from sensor when fan is not runnigng
float vSvoltage =0; // Variable to store output voltge from sensor when fan is not running
float vStotal =0; // variable to keep track of all readings to define Vs Reference voltage
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT); // set pin 12 as OUTPUT
pinMode(fanpowerPin, OUTPUT); // set pin 12 as OUTPUT
// Function to store a Vs referennce value when sensor fan is not running.
// Reference value will be recalculated every time the system reboots.
// The reference value will be calculated by reading the sensor output
// voltage and averaged for "countReading" seconds.
digitalWrite(fanpowerPin,LOW); // power off sensorFan
delay(2000); //Wait 2seconds
Serial.println("Preparing Vs Reference voltage");
Serial.print("Set time for Vs ref value: ");
Serial.print(countReading);
Serial.println(" seconds");
for (int i=0; i<=countReading; i++) {
delay(1000); // Wait 1 second between each reading
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(samplingTime); //Wait samplingTime before reading V0output
vSrawvalue = analogRead(measurePin); // read the dust value
delayMicroseconds(deltaTime); //Wait deltaTime before shuttign of LED
digitalWrite(ledPower,HIGH); // turn the LED off
vSvoltage= vSrawvalue*5.0/1024; // Calculate actual voltage [V]
vStotal = vStotal+vSvoltage; //Adding up all read voltages
Serial.print(" Vs Output [mV]: "); // Print Vs Output to see progress
Serial.print(vSvoltage*1000); // print mV
Serial.print(" VsTotal [mV]: "); // Print Vs Total to see progress
Serial.println(vStotal*1000);
}
// Calculate Vs reference value
vS=vStotal /(countReading) * 1000; //Calculate average output voltage when fan is not running. REFERENCE VALUE
digitalWrite(fanpowerPin,HIGH); // power on sensorFan
delay(5000); // Wait 5 seconds before starting void loop
}
void loop(){
// Read the sensor and print outputs...
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(samplingTime); //Wait samplingTime before reading V0output
voMeasured = analogRead(measurePin); // read the dust value
delayMicroseconds(deltaTime); //Wait deltaTime before shuttign of LED
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(sleepTime); // No use in this example
calcVoltage = voMeasured * (5.0 / 1024)*1000; // Calculate output voltage from Raw analog signal to mV
dustDensity = 0.6 * (calcVoltage-vS); //calculate dust voltage according to sensor datasheet formula, BETA=1
Serial.print("Vs [mV]: ");
Serial.print(vS);
Serial.print(" Raw Signal (0-1023): ");
Serial.print(voMeasured);
Serial.print(" V0 [mV]: ");
Serial.print(calcVoltage);
Serial.print(" (V0-Vs) [mV]: ");
Serial.print(calcVoltage - vS);
Serial.print(" Dust density [ug/m3]:");
Serial.println(dustDensity);
delay(2000); // Wait 2 seconds between each reading/printing
}
Dustsensor.ino (3.99 KB)