Hey guys, I'm currently attempting to use an NO2 2 Click sensor with an Arduino Mega 2560. I'm quite new to Arduino, so I'm currently doubting my work. Any help/ pointers would be appreciated, especially regarding the connections of the sensor to the Arduino Board, as well as the code itself.
The pins are connected as follows:
(Using an Arduino Mega 2560)
CS - 53
SCK - 52
SDO - 50
I had the PHT pin connected to PWM (pin 3), but I found it wasn't making a difference to anything, when connected or disconnected. I can't figure out exactly what purpose this PHT connection has, as there's no resources about it online. If anyone could help me understand what this pin is/ how it should interact with the Arduino that would be greatly appreciated!
My code so far is as follows:
#include <SPI.h>
// Define the SPI pins
int pinCS = 53; // Chip Select (CS or SS) pin
int pinSCK = 52; // SPI Clock (SCK) pin
int spiMISO = 50; // MISO (Master In Slave Out) pin
// Define calibration constants for the sensor
int Offset = 0;
int Sensitivity = 2;
void setup(void)
{
Serial.begin(115200);
pinMode(pinCS, OUTPUT); // Set the CS HIGH - idle
digitalWrite(pinCS, HIGH); // Set the CS HIGH - idle
//start the SPI
SPI.begin();
SPI.setBitOrder( MSBFIRST );
SPI.setDataMode( SPI_MODE3 ); // Modes 0-3 - collect data on different settings
SPI.setClockDivider( SPI_CLOCK_DIV16 );
}
void loop() {
digitalWrite(pinCS, LOW); // Select the Sensor (as it collects data when low)
// Read data from the sensor
// using float instead of int to be able to obtain decimal places
float(SensorValue) = SPI.transfer(0x00);
digitalWrite(pinCS, HIGH); // Deselect the Sensor
Serial.print(SensorValue);
// Convert the bytes to numbers
float(SensorReading) = map(SensorValue, 0, 255, 0, 1023);
//adjust for the sensitivity and calibration
float(NO2_Conc) = (SensorReading - Offset)/Sensitivity;
// Display the reading in the Serial Monitor
Serial.print("Sensor Reading: ");
Serial.print(NO2_Conc);
Serial.println(" ppb");
delay(1000); // Frequency of sample rate
}
This returns a value to me in the Serial Monitor. However, the values don't seem very organic. They read as ~48, with little variation, and then jump up to ~500 for a while, and then back down. I'm worried that this isn't measuring NO2 concentration, and is actually just returning an arbitrary value from the sensor/voltage source or something. Any help/guidance would be greatly appreciated.
Cheers