No outputs activating

I am a novice programmer, and for a mock project I am trying to make a temperature control system but the code is not working. It uses an arduino uno r4 wifi, a sparkfun bme280 and an adafruit OLED display.

This is the code:

#include <Wire.h>               // Includes I2C connections
#include <SparkFun BME280.h>    // Includes the SparkFun BME280 library
#include <U8g2lib.h>            // Includes the U8g2 library

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels
#define ALTITUDE 37       // The altitude

BME280 bme;                                        // Creates an instance of the SparkFun BME280 sensor
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0); // Creates a U8g2 object for the OLED

int bme280Address = 0x77;        // Sets the adress for the temperature sensor
const int HeaterControlPin = A3; // Sets a constant for the controlling the mosfet to analogue pin 3
const int CfanPin = 5;           // sets the constant for controlling the cooling fan to digital pin 5
const int HfanPin = 6;           // sets a constant for controlling the heating fan to digital pin 6
const int HeaterOn = 255;        // sets a constant for turning the heater on
const int HeaterOff = 0;         // sets a constant for turning the heater off

void setup() {
    Serial.begin(9600);     // Starts the communication to the terminal at 9600 bits/s
    Wire.begin();           // Initialize I2C communication
    u8g2.begin();           // Initialize the display using the u8g2 library
    SparkFunBME280.begin(); // Initialises the Sparkfun sensor
    
    pinMode(CfanPin, OUTPUT);            // Set the cooling fan pin as an output
    pinMode(HfanPin, OUTPUT);            // Set the heating fan pin as an output
    pinMode(HeaterControlPin, OUTPUT);   // Set the A3 pin as an output for the heating element
}

void loop() {
    float celsius = bme.readTempC();          //Reads the temperature 
    float humidity = bme.readFloatHumidity(); //Reads the humidity

    Serial.print("Celsius: ");  // Prints "celcius: " on the serial monitor
    Serial.println(celsius);    // Prints the value of temperature(in celcius) afterwards
    Serial.print("Humidity: "); // Prints "Humidity: " on the serial monitor
    Serial.println(humidity);   // Prints the value of the humuidity afterwards

    u8g2.clearBuffer();                  // Clears the buffer in the library
    u8g2.setFont(u8g2_font_ncenB08_tr);  // Set the font from the library
    u8g2.setCursor(0, 10);               // Set the start cursor for temperature
    u8g2.print("Temp: ");                // Prints "Temp: " on the display at (0, 10)
    u8g2.print(celsius)                  // Prints the temperature value afterwards
    u8g2.print(" C");                    // Prints the unit "C" for celcius afterwards
    u8g2.setCursor(0, 50);               // Set the start cursor for humidity
    u8g2.print("Humidity: ");            // Print "Humidity: " on the display at (0, 50)
    u8g2.print(humidity);                // Prints the humidity value afterwards
    u8g2.print(" %");                    // Prints the unit "%" afterwards
    u8g2.sendBuffer();                   // Updates the display for new content

if (celsius >= 32) {                              // If the temperature is greater than/equal to 32, then:
        analogWrite(HeaterControlPin, HeaterOff); // Turns the heating element off
        digitalWrite(CfanPin, HIGH);              // Turns on the cooling fan
        digitalWrite(HfanPin, LOW);               // Turns off the heating fan
    } else {                                      // If it isnt(all other values below 32), then:
        analogWrite(HeaterControlPin, HeaterOn);  // Turns the heating element on
        digitalWrite(CfanPin, LOW);               // Turn off the cooling fan
        digitalWrite(HfanPin, HIGH);              // Turns on the heating fan
    }
    
    delay(30000); // Delays for 30 seconds
}

And this is a picture of the system:


(the 3 sensors are supposed to represent the fans, and the solar panel the heating pad. a4 and a5 are going to scl and sda on the temperature sensor too)
Thanks for reading!

Welcome to the forum

What exactly does that mean ?

For instance, do you see anything in the Serial monitor ?

I see nothing on the serial monitor, or in the system itself.

Put a print statement such as

Serial.println("starting loop()");

as the first statement in the loop() function. Do you see it printed and if so, how often ?

And srsly, even if you want this to only be functional twice a minute, reduce the delay severely for now - life is short. Try 777 milliseconds, you won't break anything.

Does the serial monitor window agree with the baud rate you are using?

    Serial.begin(9600); 

a7

1 Like

:+1:

Just a random number.

a7

1 Like

The serial monitor doesnt print anything, but now there is an error on line 32 saying "Compilation error: 'SparkFunBME280' was not declared in this scope" that wasnt there before.

also the baud rate does match the serial monitor

In which case you made a mistake somewhere. Time to post your revised sketch as we can't see what you did.

What is the "thing" in series with Vin....?
Heaps of other questionable connections also.
Suggest you start again.

Oh yeah I forgot about that. Sorry about that.

#include <Wire.h>               // Includes I2C connections
#include <SparkFunBME280.h>    // Includes the SparkFun BME280 library
#include <U8g2lib.h>            // Includes the U8g2 library

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels
#define ALTITUDE 37       // The altitude in Melbourne

BME280 bme;                                        // Creates an instance of the SparkFun BME280 sensor
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0); // Creates a U8g2 object for the OLED

int bme280Address = 0x77;        // Sets the adress for the temperature sensor
const int HeaterControlPin = A3; // Sets a constant for the controlling the mosfet to analogue pin 3
const int CfanPin = 5;           // sets the constant for controlling the cooling fan to digital pin 5
const int HfanPin = 6;           // sets a constant for controlling the heating fan to digital pin 6
const int HeaterOn = 255;        // sets a constant for turning the heater on
const int HeaterOff = 0;         // sets a constant for turning the heater off

void setup() {
    Serial.begin(9600);     // Starts the communication to the terminal at 9600 bits/s
    Wire.begin();           // Initialize I2C communication
    u8g2.begin();           // Initialize the display using the u8g2 library
    SparkFunBME280.begin(); // Initialises the Sparkfun sensor
    
    pinMode(CfanPin, OUTPUT);            // Set the cooling fan pin as an output
    pinMode(HfanPin, OUTPUT);            // Set the heating fan pin as an output
    pinMode(HeaterControlPin, OUTPUT);   // Set the A3 pin as an output for the heating element
}

void loop() {
  Serial.println("starting loop()");

    float celsius = bme.readTempC();          //Reads the temperature 
    float humidity = bme.readFloatHumidity(); //Reads the humidity

    Serial.print("Celsius: ");  // Prints "celcius: " on the serial monitor
    Serial.println(celsius);    // Prints the value of temperature(in celcius) afterwards
    Serial.print("Humidity: "); // Prints "Humidity: " on the serial monitor
    Serial.println(humidity);   // Prints the value of the humuidity afterwards

    u8g2.clearBuffer();                  // Clears the buffer in the library
    u8g2.setFont(u8g2_font_ncenB08_tr);  // Set the font from the library
    u8g2.setCursor(0, 10);               // Set the start cursor for temperature
    u8g2.print("Temp: ");                // Prints "Temp: " on the display at (0, 10)
    u8g2.print(celsius);                 // Prints the temperature value afterwards
    u8g2.print(" C");                    // Prints the unit "C" for celcius afterwards
    u8g2.setCursor(0, 50);               // Set the start cursor for humidity
    u8g2.print("Humidity: ");            // Print "Humidity: " on the display at (0, 50)
    u8g2.print(humidity);                // Prints the humidity value afterwards
    u8g2.print(" %");                    // Prints the unit "%" afterwards
    u8g2.sendBuffer();                   // Updates the display for new content

if (celsius >= 32) {                              // If the temperature is greater than/equal to 32, then:
        analogWrite(HeaterControlPin, HeaterOff); // Turns the heating element off
        digitalWrite(CfanPin, HIGH);              // Turns on the cooling fan
        digitalWrite(HfanPin, LOW);               // Turns off the heating fan
    } else {                                      // If it isnt(all other values below 32), then:
        analogWrite(HeaterControlPin, HeaterOn);  // Turns the heating element on
        digitalWrite(CfanPin, LOW);               // Turn off the cooling fan
        digitalWrite(HfanPin, HIGH);              // Turns on the heating fan
    }
    
    delay(777); // Delays for 10 seconds
}

I also got my numbers muddled up so it was on line 23, my bad.

This creates the an instance of BME280 called bme. You use the bme object / variable everywhere except in the below. You do not have an object / variable called SparkFunBME280, you have an object / variable called bme.

You created a BME280 object earlier

You have a sensor connected to pin 1 which is also used for the USB and will stop the serial monitor working .

That’s in your diagram , but not the code !

You have what looks like a potentiometer in series with Vin , that should stop things working too !

I would pull all the wires out !
Then see if you can write to the serial monitor z, then see if you can toggle the outputs - that way you can see any error immediately .
If you have sensors , try a library example first .
Then build your project up

Looks like a power switch to me, when I zoom in on it.

Could be anything I guess ! I went with pot as no handle , assumed it was a trimmer pot … we may never know !

Should I just switch the A1 wire to A2?

Yeah that is a switch to turn the circuit on/off

Im basing this project off of this on > Controlling Heating Pads with Arduino Uno | Astronomers Anonymous < so if this helps.

No ! I’m talking about the wire on the Tx pin .