Home Code AM2303 and LCD Keypad shield example

AM2303 and LCD Keypad shield example

by shedboy71

In this example we take our Nucleo and AM2303 sensor example and we add an LCD Keypad shield and display the temperature and humidity on this. Here is  a picture of that shield

lcd keypad shield

lcd keypad shield

You will need to add the freetronics LCD shield library

Code

[codesyntax lang=”cpp”]

#include "mbed.h"
#include "AM2303.h"
#include "freetronicsLCDShield.h"

 
freetronicsLCDShield lcd(D8, D9, D4, D5, D6, D7, D1, A0);
 
 
/* Humidity sensor */
AM2303 h(D12);
 
/* The main function */
int main()
{
    /* Variables */
        lcd.cls();
    lcd.printf("AM2303 Humidity");
    lcd.setCursorPosition(1, 0);
    int state;
 
    /* Infinate loop */
    while(true) 
    {
        /* Wait for measurement */
        wait(2.0);
 
        /* Read the measured results */
        state = h.readData();
        lcd.setCursorPosition(1, 0);
        /* Show the data, otherwise error */
        if (state != AM2303::OK) 
        {
            lcd.printf("<Error: %d>\n", state);
        } 
        else 
        {
            
            lcd.printf("T:%2.1fC, H:%2.1f%%\n", h.readTemperature(), h.readHumidity());
        }
 

    }
}

[/codesyntax]

 

Links

DHT22 AM2302 Digital Temperature Humidity Sensor Chip Electronic Brick

1602 LCD Board Keypad Shield Blue Backlight

Share

You may also like