Ozone 2 Click to control 12VDC fan with Arduino Uno

I have been trying to adjust a fan speed depending on the concentration of ozone determined by the Ozone 2 Click sensor. I have my current wiring setup pictured below with actual pictures and a wiring diagram. I tested the fan and it responds correctly to the test code also linked below (Note: code was made to test that the fan speed could be adjusted, not necessarily to be used directly with the ozone sensor). I am not sure how to code for the ozone sensor.
What changes to the ozone sensor wiring do I need to make?
How can I code the ozone sensor to control fan speed and also display the determined ozone concentration in real time?
Thank you!

Fan Used (12VDC 1.5 A 4 wire) : OD8038-12HBVXC10A Orion Fans | Fans, Thermal Management | DigiKey

Ozone Sensor Used (Ozone 2 Click): MIKROE-2767 MikroElektronika | Development Boards, Kits, Programmers | DigiKey

Arduino (Uno SMD): A000073: Arduino Uno SMD R3

Fan code:

const int fan_control_pin = 9;
int count = 0;
unsigned long start_time;
int rpm;

void setup() {

TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
TCCR1B = _BV(WGM13) | _BV(CS10);
ICR1 = 320;
pinMode(fan_control_pin, OUTPUT);
OCR1A  = 0;
OCR1B = 0;
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(2), counter, RISING);
}

void loop() 
{
  for(int pwm = 0; pwm <= 320; pwm += 64){
    OCR1A = pwm;
    delay(5000);
    start_time = millis();
    count = 0;
    while((millis() - start_time) <1000){
    }
    rpm = count * 30;
    Serial.print("PWM = ");
    Serial.print(map(pwm, 0, 320, 0, 100));
    Serial.print("%, Speed = ");
    Serial.print(rpm);
    Serial.println(" rpm");
    } 
}
void counter() 
{
  count++;
}





Note: I ran the code shown above before I added all the wiring directly relating to the ozone sensor and it worked. Now that I have the setup shown in the pictures and wiring diagram, the code no longer uploads to the Arduino and gives and Exit Status 1 error. After disconnecting the ozone sensor wiring, the code uploads to the Arduino. After uploading the fan code and reconnecting the ozone wiring, the fan works again and properly responds to the code. Not sure if this is relevant.

The picture is not cleare, post an annotated schematic showing how you have wired it and also post links to technical information on all of the hardware items.

Taken from your sensor data sheet.

If you plan on using the SPI interface I suggest you give this a read.

Looking at the data sheet for the sensor:
Ozone 2 click carries an MQ131 sensor for Ozone (O3). The sensor outputs an analog voltage, which is converted by the onboard MCP3551 22-bit ADC converter or it is sent to the microcontroller via AN pin on the mikroBUS™, depending on the position of ADC SEL. jumper. The click is designed to run on 5V power supply. It communicates with the target microcontroller over SPI interface or AN pin on the mikroBUS™ line.

The sensor module has two outputs. The SPI output should give a value betaeen 10‐1000 ppm for Ozone concentration. The sensor module also looks to have an analog output pin so there should be an analog voltage out proportional to the Ozone concentration. Have you looked at the analog output at all?

If there is an analog out proportional to Ozone concentration I would likely think about using that. For example run an analog value from your sensor to A0 and read it. Next I would MAP it to a PWM out. Analog IN, PWM Out.

Next if using the SPI interface I would do about the same. Read the Ozone concentration between 10 and 100 PPM and MAP that value to a PWM out.

The following is just a basic example of Analog In / PWM Out. It would be modified a little for your application. Especially the mapping.

// Constants, pin naming conventions:
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int pwmOutPin = 5; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)
int percentValue = 0;       // pump speed percent full scale

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
  
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // map pump speed percent of full scale
  percentValue = map (outputValue, 0, 255, 0, 100);
  // change the analog out value:
  analogWrite(pwmOutPin, outputValue);

  // print the results to the Serial Monitor:
  //Serial.print("\t Speed Input = ");
  Serial.print(A0);
  //Serial.print("\t Speed Output = ");
  //Serial.print(outputValue);
  //Serial.print("\t Motor Speed Percentage = ");
  //Serial.println(percentValue);

  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
 delay(500); // Allow 0.5 Second and Loop Again
}

Ron

Did you see the library for that sensor on the Digikey product page?
Leo..

Sorry I cannot follow the wiring diagram. A schematic will look a lot different.

I believe these files are for a different application, not Arduino IDE. If there is one on there that will work with IDE, let me know

That's for you to find out...
I saw different platform files in the .zip file, including AVR.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.