Arduino due capacitor

I'm sorry my English is not good.

my previous post was disappeared, so I repost it.

#include "U8glib.h"
#include <avr/dtostrf.h>
//#include <Capacitor.h>
#include <CapacitorLite.h>

#define R1 679
#define Vin 5

char temperature [8];
char humidity [5];
float capacitor;
float mvolt;
float resis;
float temp;
float filtervalue;
float sensorvalue;

//Digital pin 7, analog pin 2
CapacitorLite cap(7, A2);

U8GLIB_ST7920_128X64 u8g(SCK,MOSI,10, U8G_PIN_NONE);

void setup() {  
  // flip screen, if required
  // u8g.setRot180();
  // set SPI backup if required

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
  pinMode(8, OUTPUT);

void loop() {
  //LCD (draw)
  do {   
  } while( u8g.nextPage() );
void draw(){

  u8g.drawStr(19, 13, "Temperature");   
  u8g.drawStr(40, 28, temperature);   
  u8g.drawStr(75, 28, "\xb0");
  u8g.drawStr(80, 28, "C");//°

  u8g.drawStr(30, 46, "Humidity");         
  u8g.drawStr(40, 61, humidity); 
  u8g.drawStr(80, 61, "%");

void readTemperature()
  //sensorvalue = analogRead(A0);
  filtervalue = 0;
  for(int i=0;i<10;i++) {
    filtervalue += analogRead(A0);
  filtervalue /= 10;
  //second type filtervalue finish

  //0~5V convert-> mV convert!
  mvolt = (filtervalue*Vin*1000)/4095.0;

  //volt to resistance
  resis = R1 * mvolt / (Vin*1000 - mvolt);
  temp = (resis - 923.87)/3.6514;
  dtostrf(temp, 4, 1, temperature);

void readHumidity()
  capacitor = cap.Measure();
  capacitor /= 100;
  dtostrf(capacitor, 3, 1, humidity);

I want to see temperature and humidity on LCD, but when I operate my code, I can get wrong capacity value.
On previous post, someone said that Capacitor library measures total capacity...
So, how can I get right humidity on my code?


The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed). It's fairly simple to use but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old.

no I use the sensor in development...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.