I need help in ascii on arduino

I need to put ascii ( this character º ) right before C can anyone help me?

#include <DHT2pin.h>
#include <DHT.h>

#define DHTPIN A2
#define DHTTYPE DHT11
#define BUTTON_UP_PIN 7
#define BUTTON_DOWN_PIN 6

DHT dht(DHTPIN, DHTTYPE);
int humidityThreshold = 60;
unsigned long previousButtonTime = 0;
unsigned long buttonCheckInterval = 100;
unsigned long previousDhtReadTime = 0;
unsigned long dhtReadInterval = 5000;

bool buttonUpState = HIGH;
bool buttonDownState = HIGH;
bool buttonUpPressed = false;
bool buttonDownPressed = false;
bool forceDhtRead = false;

void setup() {
  Serial.begin(9600);
  Serial.print("?G420");

  pinMode(5, OUTPUT);
  pinMode(BUTTON_UP_PIN, INPUT_PULLUP);
  pinMode(BUTTON_DOWN_PIN, INPUT_PULLUP);

  dht.begin();
 
}

void loop() {
  unsigned long currentTime = millis();

  // Button check
  if (currentTime - previousButtonTime >= buttonCheckInterval) {
    buttonUpState = digitalRead(BUTTON_UP_PIN);
    buttonDownState = digitalRead(BUTTON_DOWN_PIN);

    if (buttonUpState == LOW && !buttonUpPressed) {
      humidityThreshold += 1;
      buttonUpPressed = true;
      // Força uma leitura
      forceDhtRead = true;
    }
    else if (buttonUpState == HIGH) {
      buttonUpPressed = false;
    }

    if (buttonDownState == LOW && !buttonDownPressed) {
      humidityThreshold -= 1;
      buttonDownPressed = true;
      // Força uma leitura
      forceDhtRead = true;
    }
    else if (buttonDownState == HIGH) {
      buttonDownPressed = false;
    }

    previousButtonTime = currentTime;
  }

  // Toggle pin 5
  if (currentTime - previousButtonTime >= 500) {
    digitalWrite(5, HIGH);
  }
  if (currentTime - previousButtonTime >= 1000) {
    digitalWrite(5, LOW);
  }

  // DHT sensor reading
  if (forceDhtRead || currentTime - previousDhtReadTime >= dhtReadInterval) {
    forceDhtRead = false;  // Reseta a flag de leitura forçada

    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();

    if (isnan(temperature) || isnan(humidity)) {
      Serial.println("Falha ao ler o sensor DHT!");
      return;
    }

    Serial.print("?f");
    Serial.print("Temperatura = ");
    Serial.print(int(temperature));
    Serial.print("  C");
    Serial.print(" Humidade = ");
    Serial.print(int(humidity));
    Serial.println("%");
    Serial.print("Humidade Ideal: ");
    Serial.print(humidityThreshold);
    Serial.println("%");

    previousDhtReadTime = currentTime;
  }
}

x = ???; // the ASCII number for degree

Serial.print((char) x ) ;

Serial.print("C");

pls embed your code properly

"Degree" or "Grad" symbol.

it does this any idea why � C

im trying to use º btw

Can you show how you put this in your code?

Did you try this?

Serial.print("?f");
Serial.print("Temperatura = ");
Serial.print(int(temperature));
Serial.print((char) 248 ) ;
Serial.print(" C");
Serial.print(" Humidade = ");
Serial.print(int(humidity));
Serial.println("%");
Serial.print("Humidade Ideal: ");
Serial.print(humidityThreshold);
Serial.println("%");

You have the wrong value...

You will find "degree" on this page.

What device are you printing it to? It must support the extended character set.

1 Like

186

An lcd 117 smd mod

Close. : )

167

1 Like

Closer!

176
codes..

1 Like

The Serial monitor accepts UTF-8 coding, try this:

    Serial.print("  \302\260C");  //UTF-8 C2 B0 in octal coding

< edit > sorry, missed that it was a Serial LCD

I never can remember all those codes, so I made a "symbols.txt" file, if I want the "degree" symbol, I go to the file, select and copy it, then paste into my code.
Here's a piece of mine.

symbols.txt (229 Bytes)

Deg symbol: ° ℃ ℉

Ohms: Ω

micros: µ

frac: ¼ ½ ¾ ⅓ ⅖

misc: ± √ ∞ Δ

Am I nothing to you?
Kelvin.

2 Likes

My Lord, you are the beginning. :crazy_face: