0

I need to do this project:

Design a circuit that includes an Arduino Uno board, a temperature and humidity sensor (22DHT), two dot matrices with drivers, a touch sensor, and some resistors. The circuit works in such a way that by default, the temperature is displayed in the matrix when the touch sensor is not touched, and the humidity is displayed when the touch sensor is touched. The temperature or humidity is displayed in one matrix and the emoticon associated with whether that temperature or humidity is desirable, too high, or too low is displayed in the second matrix.

Currently I have designed this circuit in Proteus:

Circuit

This is my Code in Arduino CPP:

#include <LedControl.h>
#include <DHT.h>

#define DHTPIN 2        
#define DHTTYPE DHT22

#define TOUCHPIN 3      

#define DATAIN 11       
#define CLK    13       
#define LOAD1  10       
#define LOAD2   9       

DHT dht(DHTPIN, DHTTYPE);
LedControl lc1 = LedControl(DATAIN, CLK, LOAD1, 1);
LedControl lc2 = LedControl(DATAIN, CLK, LOAD2, 1);

void setup() {
  Serial.begin(9600);
  dht.begin();
  
  pinMode(TOUCHPIN, INPUT);

  lc1.shutdown(0, false);
  lc1.setIntensity(0, 8);
  lc1.clearDisplay(0);

  lc2.shutdown(0, false);
  lc2.setIntensity(0, 8);
  lc2.clearDisplay(0);
}

void loop() {
  float temp = dht.readTemperature();
  float hum = dht.readHumidity();

  if (isnan(temp) || isnan(hum)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  bool touch = digitalRead(TOUCHPIN);

  if (touch == HIGH) {
    displayNumber((int)hum, lc1);
    displayEmoticon(getEmoticon(hum, "hum"), lc2);
  } else {
    displayNumber((int)temp, lc1);
    displayEmoticon(getEmoticon(temp, "temp"), lc2);
  }

  delay(2000);
}

void displayNumber(int num, LedControl &lc) {
  lc.clearDisplay(0);
  if (num > 99) num = 99;
  lc.setChar(0, 1, (num / 10) + '0', false);
  lc.setChar(0, 0, (num % 10) + '0', false);
}

char getEmoticon(float value, String type) {
  if (type == "temp") {
    if (value < 18) return '-';
    if (value > 28) return '+';
    return ':';
  } else if (type == "hum") {
    if (value < 30) return '-';
    if (value > 70) return '+';
    return ':';
  }
  return '?';
}

void displayEmoticon(char emoticon, LedControl &lc) {
  lc.clearDisplay(0);
  switch (emoticon) {
    case '-':
      lc.setRow(0, 3, B00011000);
      lc.setRow(0, 4, B00011000);
      break;
    case '+':
      lc.setRow(0, 2, B00011000);
      lc.setRow(0, 3, B01111110);
      lc.setRow(0, 4, B01111110);
      lc.setRow(0, 5, B00011000);
      break;
    case ':':
      lc.setLed(0, 2, 3, true);
      lc.setLed(0, 5, 3, true);
      break;
    case '?':
    default:
      lc.setRow(0, 3, B01000010);
      lc.setRow(0, 4, B00100100);
      break;
  }
}

The problem is that when I start simulation, all dots in my displays turns on and they basically show nothing.

Circuit in simulation

1
  • lc1.shutdown(0, false); lc1.setIntensity(0, 8); lc1.clearDisplay(0); lc2.shutdown(0, false); lc2.setIntensity(0, 8); lc2.clearDisplay(0); u forgot to change the second time to 1 instead of 0 u just clean and setup the first display Commented Jun 1 at 21:34

1 Answer 1

0

Change from this in setup:

lc1.shutdown(0, false);
lc1.setIntensity(0, 8);
lc1.clearDisplay(0);

lc2.shutdown(0, false);
lc2.setIntensity(0, 8);
lc2.clearDisplay(0);

To this:

lc1.shutdown(0, false);
lc1.setIntensity(0, 8);
lc1.clearDisplay(0);

lc2.shutdown(1, false);
lc2.setIntensity(1, 8);
lc2.clearDisplay(1);

Or else you just initialize and clear the first display.

Sign up to request clarification or add additional context in comments.

2 Comments

Why? Each display driver is driven with their own CS pin.
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.