What's new

Aokiji_Master

Forum Veteran
swing servo motor back and forth when detected a sound by sound sensor or a rain sensor has detected and stop when thiers no detected
 
code for oled 0.9 display testing
Here's a simple example code to test the OLED 0.9 inch display with Arduino:

Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0,0);
  display.println("OLED Display Testing!");
  display.display();
}

void loop() {
  //nothing to do here
}

This code sets up the OLED display, clears it, and displays a text in the first line. The display is updated once in the setup() function and then it waits in the loop(). You can modify the text and font size to test different configurations of the OLED display.
 
Here's a simple example code to test the OLED 0.9 inch display with Arduino:

Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0,0);
  display.println("OLED Display Testing!");
  display.display();
}

void loop() {
  //nothing to do here
}

This code sets up the OLED display, clears it, and displays a text in the first line. The display is updated once in the setup() function and then it waits in the loop(). You can modify the text and font size to test different configurations of the OLED display.
code for humidity and sensor using arduino uno
 
code for humidity and sensor using arduino uno
Here's an example code for reading humidity and temperature data from a DHT11 sensor and displaying it on the serial monitor with Arduino:

Code:
#include <DHT.h>

#define DHTPIN 2     // what pin the DHT11 is connected to
#define DHTTYPE DHT11   // DHT 11 

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C");
  delay(2000);
}

This code reads the humidity and temperature data from the DHT11 sensor connected to pin 2 and displays it on the serial monitor with a delay of 2 seconds between readings. You can modify the pin number and sensor type depending on your setup.
 
Here's the circuit diagram for the medicine reminder using the materials you listed:

Circuit Diagram


The code for the medicine reminder can be written as follows:

Code:
c++
#include <Wire.h> 
#include <LiquidCrystal.h>
#include <RTClib.h>

// Initialize LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Initialize RTC
RTC_DS3231 rtc;

// Initialize Buzzer
int buzzer = 9;

// Initialize LED
int redLed = 6;
int yellowLed = 7;
int greenLed = 8;

// Initialize Buttons
int hourButton = A0;
int minuteButton = A1;
int setButton = A2;

int alarmHour = 0;
int alarmMinute = 0;

void setup() {
  // Start Serial Communication
  Serial.begin(9600);

  // Initialize LCD
  lcd.begin(16, 2);

  // Initialize Buzzer
  pinMode(buzzer, OUTPUT);

  // Initialize LED
  pinMode(redLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(greenLed, OUTPUT);

  // Initialize Buttons
  pinMode(hourButton, INPUT_PULLUP);
  pinMode(minuteButton, INPUT_PULLUP);
  pinMode(setButton, INPUT_PULLUP);

  // Start RTC
  if (! rtc.begin()) {
    lcd.print("RTC failed");
    while (1);
  }

  // Set RTC Time (Uncomment and modify if necessary)
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}

void loop() {
  DateTime now = rtc.now();

  // Display RTC Time on LCD
  lcd.setCursor(0, 0);
  lcd.print("Time:");
  lcd.setCursor(6, 0);
  lcd.print(now.hour(), DEC);
  lcd.print(":");
  lcd.print(now.minute(), DEC);
  lcd.print(":");
  lcd.print(now.second(), DEC);

  // Check if Alarm Time
  if (now.hour() == alarmHour && now.minute() == alarmMinute) {
    lcd.setCursor(0, 1);
    lcd.print("Time to take med!");

    // Turn on LED and Buzzer for 30 seconds
    digitalWrite(greenLed, HIGH);
    digitalWrite(redLed, LOW);
    digitalWrite(yellowLed, LOW);
    tone(buzzer, 1000, 30000);
  } else {
    // Turn off LED and Buzzer
    digitalWrite(greenLed, LOW);
    digitalWrite(redLed, LOW);
    digitalWrite(yellowLed, LOW);
    noTone(buzzer);
  }

  // Change Alarm Time
  if (digitalRead(setButton) == LOW) {
    lcd.clear();
    lcd.print("Set Alarm Time");

    while (digitalRead(setButton) == LOW);

    // Set Alarm Hour
    lcd.setCursor(0, 1);
    lcd.print("Hour:");
    lcd.setCursor(6, 1);
    lcd.print(alarmHour, DEC);

    while (digitalRead(hourButton) == HIGH) {
      if (digitalRead(setButton) == LOW) {
        alarmHour++;
        if (alarmHour > 23) {
          alarmHour = 0;
        }
        lcd.setCursor(6, 1);
        lcd.print(alarmHour, DEC);
      }
    }

    // Set Alarm Minute
    lcd.setCursor(0, 1);
    lcd.print("Minute:");
    lcd.setCursor(8, 1);
    lcd.print(alarmMinute, DEC);

    while (digitalRead(minuteButton) == HIGH) {
      if (digitalRead(setButton) == LOW) {
        alarmMinute++;
        if (alarmMinute > 59) {
          alarmMinute = 0;
        }
        lcd.setCursor(8, 1);
        lcd.print(alarmMinute, DEC);
      }
    }

    // Display Alarm Time
    lcd.clear();
    lcd.print("Alarm Time Set");
    lcd.setCursor(0, 1);
    lcd.print(alarmHour, DEC);
    lcd.print(":");
    lcd.print(alarmMinute, DEC);
    delay(2000);
    lcd.clear();
  }

  // Change LED Color based on Time
  if (now.hour() < 8) {
    digitalWrite(greenLed, LOW);
    digitalWrite(redLed, HIGH);
    digitalWrite(yellowLed, LOW);
  } else if (now.hour() < 18) {
    digitalWrite(greenLed, LOW);
    digitalWrite(redLed, LOW);
    digitalWrite(yellowLed, HIGH);
  } else {
    digitalWrite(greenLed, HIGH);
    digitalWrite(redLed, LOW);
    digitalWrite(yellowLed, LOW);
  }

  // Delay 1 Second
  delay(1000);
}

This code will display the current time on the LCD and check if it's time to take medicine based on the alarm time set by the user. If it's time, it will turn on the LED and buzzer for 30 seconds. The user can also change the alarm time by pressing the set button and using the hour and minute buttons. The LED color will change based on the time of day.
 
Here's the circuit diagram for the medicine reminder using the materials you listed:

Circuit Diagram


The code for the medicine reminder can be written as follows:

Code:
c++
#include <Wire.h>
#include <LiquidCrystal.h>
#include <RTClib.h>

// Initialize LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Initialize RTC
RTC_DS3231 rtc;

// Initialize Buzzer
int buzzer = 9;

// Initialize LED
int redLed = 6;
int yellowLed = 7;
int greenLed = 8;

// Initialize Buttons
int hourButton = A0;
int minuteButton = A1;
int setButton = A2;

int alarmHour = 0;
int alarmMinute = 0;

void setup() {
  // Start Serial Communication
  Serial.begin(9600);

  // Initialize LCD
  lcd.begin(16, 2);

  // Initialize Buzzer
  pinMode(buzzer, OUTPUT);

  // Initialize LED
  pinMode(redLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(greenLed, OUTPUT);

  // Initialize Buttons
  pinMode(hourButton, INPUT_PULLUP);
  pinMode(minuteButton, INPUT_PULLUP);
  pinMode(setButton, INPUT_PULLUP);

  // Start RTC
  if (! rtc.begin()) {
    lcd.print("RTC failed");
    while (1);
  }

  // Set RTC Time (Uncomment and modify if necessary)
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}

void loop() {
  DateTime now = rtc.now();

  // Display RTC Time on LCD
  lcd.setCursor(0, 0);
  lcd.print("Time:");
  lcd.setCursor(6, 0);
  lcd.print(now.hour(), DEC);
  lcd.print(":");
  lcd.print(now.minute(), DEC);
  lcd.print(":");
  lcd.print(now.second(), DEC);

  // Check if Alarm Time
  if (now.hour() == alarmHour && now.minute() == alarmMinute) {
    lcd.setCursor(0, 1);
    lcd.print("Time to take med!");

    // Turn on LED and Buzzer for 30 seconds
    digitalWrite(greenLed, HIGH);
    digitalWrite(redLed, LOW);
    digitalWrite(yellowLed, LOW);
    tone(buzzer, 1000, 30000);
  } else {
    // Turn off LED and Buzzer
    digitalWrite(greenLed, LOW);
    digitalWrite(redLed, LOW);
    digitalWrite(yellowLed, LOW);
    noTone(buzzer);
  }

  // Change Alarm Time
  if (digitalRead(setButton) == LOW) {
    lcd.clear();
    lcd.print("Set Alarm Time");

    while (digitalRead(setButton) == LOW);

    // Set Alarm Hour
    lcd.setCursor(0, 1);
    lcd.print("Hour:");
    lcd.setCursor(6, 1);
    lcd.print(alarmHour, DEC);

    while (digitalRead(hourButton) == HIGH) {
      if (digitalRead(setButton) == LOW) {
        alarmHour++;
        if (alarmHour > 23) {
          alarmHour = 0;
        }
        lcd.setCursor(6, 1);
        lcd.print(alarmHour, DEC);
      }
    }

    // Set Alarm Minute
    lcd.setCursor(0, 1);
    lcd.print("Minute:");
    lcd.setCursor(8, 1);
    lcd.print(alarmMinute, DEC);

    while (digitalRead(minuteButton) == HIGH) {
      if (digitalRead(setButton) == LOW) {
        alarmMinute++;
        if (alarmMinute > 59) {
          alarmMinute = 0;
        }
        lcd.setCursor(8, 1);
        lcd.print(alarmMinute, DEC);
      }
    }

    // Display Alarm Time
    lcd.clear();
    lcd.print("Alarm Time Set");
    lcd.setCursor(0, 1);
    lcd.print(alarmHour, DEC);
    lcd.print(":");
    lcd.print(alarmMinute, DEC);
    delay(2000);
    lcd.clear();
  }

  // Change LED Color based on Time
  if (now.hour() < 8) {
    digitalWrite(greenLed, LOW);
    digitalWrite(redLed, HIGH);
    digitalWrite(yellowLed, LOW);
  } else if (now.hour() < 18) {
    digitalWrite(greenLed, LOW);
    digitalWrite(redLed, LOW);
    digitalWrite(yellowLed, HIGH);
  } else {
    digitalWrite(greenLed, HIGH);
    digitalWrite(redLed, LOW);
    digitalWrite(yellowLed, LOW);
  }

  // Delay 1 Second
  delay(1000);
}

This code will display the current time on the LCD and check if it's time to take medicine based on the alarm time set by the user. If it's time, it will turn on the LED and buzzer for 30 seconds. The user can also change the alarm time by pressing the set button and using the hour and minute buttons. The LED color will change based on the time of day.
wiring diagram for this
 
wiring diagram for this
Here's the wiring diagram for the medicine reminder using the materials you listed:

Wiring Diagram


The connections are as follows:

  • Arduino Nano 5V to Breadboard Positive Rail
  • Arduino Nano GND to Breadboard Negative Rail
  • RTC DS3231 SDA to Arduino Nano A4
  • RTC DS3231 SCL to Arduino Nano A5
  • LCD VSS to Breadboard Negative Rail
  • LCD VDD to Breadboard Positive Rail
  • LCD V0 to Breadboard wiper of 10k potentiometer
  • LCD RS to Arduino Nano D12
  • LCD RW to Breadboard Negative Rail
  • LCD EN to Arduino Nano D11
  • LCD D4 to Arduino Nano D5
  • LCD D5 to Arduino Nano D4
  • LCD D6 to Arduino Nano D3
  • LCD D7 to Arduino Nano D2
  • Buzzer positive leg to Arduino Nano D9
  • Buzzer negative leg to Breadboard Negative Rail
  • Red LED anode to Arduino Nano D6
  • Red LED cathode to Breadboard Negative Rail
  • Yellow LED anode to Arduino Nano D7
  • Yellow LED cathode to Breadboard Negative Rail
  • Green LED anode to Arduino Nano D8
  • Green LED cathode to Breadboard Negative Rail
  • Hour button to Arduino Nano A0 and Breadboard Positive Rail (with 10k resistor between A0 and Positive Rail)
  • Minute button to Arduino Nano A1 and Breadboard Positive Rail (with 10k resistor between A1 and Positive Rail)
  • Set button to Arduino Nano A2 and Breadboard Positive Rail (with 10k resistor between A2 and Positive Rail)

Note: The resistors used here are 10k ohms, but you can use any value between 1k and 100k ohms. The 10k potentiometer is used to adjust the contrast of the LCD.
 
Here's a sample code for a medicine reminder with set increment button and three LED bulbs using an Arduino Nano, 16x2 LCD, and DS3231 module:

Code:
#include <Wire.h> 
#include <LCD.h> 
#include <LiquidCrystal_I2C.h> 
#include <RTClib.h> 

RTC_DS3231 rtc;

LiquidCrystal_I2C lcd(0x27, 16, 2);

int setIncrement = 0;
int hours, minutes, seconds;

const int led1 = 2;
const int led2 = 3;
const int led3 = 4;

void setup() {
  lcd.init();
  lcd.backlight();

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);

  if (! rtc.begin()) {
    lcd.print("RTC not found");
    while (1);
  }

  if (rtc.lostPower()) {
    lcd.print("RTC lost power");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  lcd.clear();
  lcd.print("Medicine Reminder");
}

void loop() {
  DateTime now = rtc.now();

  hours = now.hour();
  minutes = now.minute();
  seconds = now.second();

  lcd.setCursor(0, 1);
  lcd.print("Time: ");
  lcd.print(hours);
  lcd.print(":");
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);

  if (setIncrement == 0) {
    lcd.setCursor(0, 0);
    lcd.print("Set Increment: ");
    lcd.print(setIncrement);
  } else {
    lcd.setCursor(0, 0);
    lcd.print("Next Dose in: ");
    lcd.print(setIncrement);
    lcd.print(" hrs");

    if (setIncrement == 1) {
      digitalWrite(led1, HIGH);
    } else if (setIncrement == 2) {
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
    } else if (setIncrement == 3) {
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
      digitalWrite(led3, HIGH);
    } else {
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
    }
  }

  if (hours == 0 && minutes == 0 && seconds == 0) {
    setIncrement = 0;
    lcd.clear();
    lcd.print("Medicine Reminder");
  }

  if (setIncrement == 0) {
    if (digitalRead(A0) == HIGH) {
      setIncrement = 1;
    }
  }

  delay(1000);
}

The code initializes the LCD and LEDs, checks if the RTC is available, and displays the current time on the LCD. It also checks if it's time to take the medicine (setIncrement is not 0), and turns on the corresponding LED bulbs. The setIncrement value is set to 0 at midnight, and the user can set the increment by pressing a button connected to the A0 pin.
 
Here's a sample code for a medicine reminder with set increment button and three LED bulbs using an Arduino Nano, 16x2 LCD, and DS3231 module:

Code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>

RTC_DS3231 rtc;

LiquidCrystal_I2C lcd(0x27, 16, 2);

int setIncrement = 0;
int hours, minutes, seconds;

const int led1 = 2;
const int led2 = 3;
const int led3 = 4;

void setup() {
  lcd.init();
  lcd.backlight();

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);

  if (! rtc.begin()) {
    lcd.print("RTC not found");
    while (1);
  }

  if (rtc.lostPower()) {
    lcd.print("RTC lost power");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  lcd.clear();
  lcd.print("Medicine Reminder");
}

void loop() {
  DateTime now = rtc.now();

  hours = now.hour();
  minutes = now.minute();
  seconds = now.second();

  lcd.setCursor(0, 1);
  lcd.print("Time: ");
  lcd.print(hours);
  lcd.print(":");
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);

  if (setIncrement == 0) {
    lcd.setCursor(0, 0);
    lcd.print("Set Increment: ");
    lcd.print(setIncrement);
  } else {
    lcd.setCursor(0, 0);
    lcd.print("Next Dose in: ");
    lcd.print(setIncrement);
    lcd.print(" hrs");

    if (setIncrement == 1) {
      digitalWrite(led1, HIGH);
    } else if (setIncrement == 2) {
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
    } else if (setIncrement == 3) {
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
      digitalWrite(led3, HIGH);
    } else {
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
    }
  }

  if (hours == 0 && minutes == 0 && seconds == 0) {
    setIncrement = 0;
    lcd.clear();
    lcd.print("Medicine Reminder");
  }

  if (setIncrement == 0) {
    if (digitalRead(A0) == HIGH) {
      setIncrement = 1;
    }
  }

  delay(1000);
}

The code initializes the LCD and LEDs, checks if the RTC is available, and displays the current time on the LCD. It also checks if it's time to take the medicine (setIncrement is not 0), and turns on the corresponding LED bulbs. The setIncrement value is set to 0 at midnight, and the user can set the increment by pressing a button connected to the A0 pin.
code for medicine remiender with set inc ok button with three led bulb with this materials

arduino nano
16x2 lcd display
rtc ds3231 module
 
code for medicine remiender with set inc ok button with three led bulb with this materials

arduino nano
16x2 lcd display
rtc ds3231 module
Here's a sample code for a medicine reminder with set increment button and three LED bulbs using an Arduino Nano, 16x2 LCD, and DS3231 module:

Code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>

RTC_DS3231 rtc;

LiquidCrystal_I2C lcd(0x27, 16, 2);

int setIncrement = 0;
int hours, minutes, seconds;

const int led1 = 2;
const int led2 = 3;
const int led3 = 4;

void setup() {
  lcd.init();
  lcd.backlight();

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);

  if (! rtc.begin()) {
    lcd.print("RTC not found");
    while (1);
  }

  if (rtc.lostPower()) {
    lcd.print("RTC lost power");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  lcd.clear();
  lcd.print("Medicine Reminder");
}

void loop() {
  DateTime now = rtc.now();

  hours = now.hour();
  minutes = now.minute();
  seconds = now.second();

  lcd.setCursor(0, 1);
  lcd.print("Time: ");
  lcd.print(hours);
  lcd.print(":");
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);

  if (setIncrement == 0) {
    lcd.setCursor(0, 0);
    lcd.print("Set Increment: ");
    lcd.print(setIncrement);
  } else {
    lcd.setCursor(0, 0);
    lcd.print("Next Dose in: ");
    lcd.print(setIncrement);
    lcd.print(" hrs");

    if (setIncrement == 1) {
      digitalWrite(led1, HIGH);
    } else if (setIncrement == 2) {
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
    } else if (setIncrement == 3) {
      digitalWrite(led1, HIGH);
      digitalWrite(led2, HIGH);
      digitalWrite(led3, HIGH);
    } else {
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
    }
  }

  if (hours == 0 && minutes == 0 && seconds == 0) {
    setIncrement = 0;
    lcd.clear();
    lcd.print("Medicine Reminder");
  }

  if (setIncrement == 0) {
    if (digitalRead(A0) == HIGH) {
      setIncrement = 1;
    }
  }

  delay(1000);
}

The code initializes the LCD and LEDs, checks if the RTC is available, and displays the current time on the LCD. It also checks if it's time to take the medicine (setIncrement is not 0), and turns on the corresponding LED bulbs. The setIncrement value is set to 0 at midnight, and the user can set the increment by pressing a button connected to the A0 pin.
 
Here is a wiring diagram for connecting an Arduino Nano, a 16x2 LCD display, and an RTC DS3231:

Arduino Nano, 16x2 LCD display, and RTC DS3231 wiring diagram


Image source: How to use DS3231 RTC with Arduino and LCD Display - Tutorial

Here is a link to the image:
 
Sure, here is an example code for Arduino Nano and 16x2 LCD display:

Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("Hello, world!");
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print("Arduino Nano");
  delay(1000);
  lcd.clear();
  lcd.print("LCD Display");
  delay(1000);
  lcd.clear();
}

This code initializes the LCD display in the setup() function and prints "Hello, world!" on the first line. In the loop() function, it updates the display every 1 second by printing "Arduino Nano" and "LCD Display" on alternate lines. The lcd.clear() function is used to clear the display before printing a new message.

Note that the pins used for the LCD display (12, 11, 5, 4, 3, 2) may vary depending on your wiring. Make sure to connect your LCD display pins to the appropriate Arduino Nano pins.
 
Sure, here's some sample code for displaying text on a 16x2 LCD display with an Arduino Uno:

Code:
#include <LiquidCrystal.h>  // include the LiquidCrystal library 

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Hello, World!");
}

void loop() {
  // Do nothing here because we only want to display the message once
}

This code initializes the LiquidCrystal library and sets up the interface pins for the LCD display. It then initializes the display with 16 columns and 2 rows and prints the message "Hello, World!" to the display. The loop() function is empty because we only want to display the message once, but you could add additional code here to continuously update the display with new information.
 
Sure, here's some sample code for displaying text on a 16x2 LCD display with an Arduino Uno:

Code:
#include <LiquidCrystal.h>  // include the LiquidCrystal library

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Hello, World!");
}

void loop() {
  // Do nothing here because we only want to display the message once
}

This code initializes the LiquidCrystal library and sets up the interface pins for the LCD display. It then initializes the display with 16 columns and 2 rows and prints the message "Hello, World!" to the display. The loop() function is empty because we only want to display the message once, but you could add additional code here to continuously update the display with new information.
code for humidity temperature sensor to 0.9 oled
 
code for humidity temperature sensor to 0.9 oled
Sure, here's some sample code for reading data from a DHT11 humidity and temperature sensor and displaying it on a 0.96" OLED display with an Arduino Uno:

Code:
#include <Adafruit_GFX.h>    // include the Adafruit graphics library
#include <Adafruit_SSD1306.h> // include the Adafruit OLED display library
#include <DHT.h>             // include the DHT library

#define OLED_RESET 4
#define SCREEN_WIDTH 128    // OLED display width, in pixels
#define SCREEN_HEIGHT 64    // OLED display height, in pixels

// OLED display object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// DHT sensor object
#define DHTPIN 2          // digital pin for DHT11 data line
#define DHTTYPE DHT11     // DHT11 sensor type
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // initialize the OLED display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C address of the display
  display.clearDisplay();                   // clear the display buffer
  display.display();

  // initialize the DHT sensor
  dht.begin();
}

void loop() {
  // read data from the DHT sensor
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  // display the data on the OLED display
  display.clearDisplay();
  display.setTextSize(1);             // set text size to 1
  display.setTextColor(SSD1306_WHITE);// set text color to white
  display.setCursor(0, 0);            // set cursor to top left corner
  display.print("Temperature: ");
  display.print(temperature);
  display.print(" C");

  display.setCursor(0, 10);           // set cursor to second line
  display.print("Humidity: ");
  display.print(humidity);
  display.print(" %");

  display.display();                  // update the OLED display
  delay(2000);                         // wait for 2 seconds before updating again
}

This code uses the Adafruit graphics and OLED display libraries to initialize and display data on a 0.96" OLED display. It also uses the DHT library to read temperature and humidity data from the DHT11 sensor connected to pin 2 of the Arduino. The temperature and humidity data is then displayed on the OLED display in Celsius and percentages, respectively. The loop() function continuously reads and displays data every 2 seconds. Note that you may need to adjust the pin numbers and sensor type in the code to match your specific setup.
 
Sure, here's some sample code for reading data from a DHT11 humidity and temperature sensor and displaying it on a 0.96" OLED display with an Arduino Uno:

Code:
#include <Adafruit_GFX.h>    // include the Adafruit graphics library
#include <Adafruit_SSD1306.h> // include the Adafruit OLED display library
#include <DHT.h>             // include the DHT library

#define OLED_RESET 4
#define SCREEN_WIDTH 128    // OLED display width, in pixels
#define SCREEN_HEIGHT 64    // OLED display height, in pixels

// OLED display object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// DHT sensor object
#define DHTPIN 2          // digital pin for DHT11 data line
#define DHTTYPE DHT11     // DHT11 sensor type
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // initialize the OLED display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C address of the display
  display.clearDisplay();                   // clear the display buffer
  display.display();

  // initialize the DHT sensor
  dht.begin();
}

void loop() {
  // read data from the DHT sensor
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  // display the data on the OLED display
  display.clearDisplay();
  display.setTextSize(1);             // set text size to 1
  display.setTextColor(SSD1306_WHITE);// set text color to white
  display.setCursor(0, 0);            // set cursor to top left corner
  display.print("Temperature: ");
  display.print(temperature);
  display.print(" C");

  display.setCursor(0, 10);           // set cursor to second line
  display.print("Humidity: ");
  display.print(humidity);
  display.print(" %");

  display.display();                  // update the OLED display
  delay(2000);                         // wait for 2 seconds before updating again
}

This code uses the Adafruit graphics and OLED display libraries to initialize and display data on a 0.96" OLED display. It also uses the DHT library to read temperature and humidity data from the DHT11 sensor connected to pin 2 of the Arduino. The temperature and humidity data is then displayed on the OLED display in Celsius and percentages, respectively. The loop() function continuously reads and displays data every 2 seconds. Note that you may need to adjust the pin numbers and sensor type in the code to match your specific setup.
code to display temperature and humidity on 0.9 oled display
 

Similar threads

Back
Top