Hi all. First off sorry if this is in the wrong forum location and please feel free to move it if required.
I am trying to use the Arduino along with a AM2302 humidity sensor to decide when to turn on and off a Peltier unit. With the Peltier on, it will cool an aluminium heatsink to draw water out of the air to reduce the relative humidity of the surrounding air. I am making this to replace an existing controller in my camera dry box which has since stopped working.
I have gotten the Arduino working as I intended it to but I am having problem regulating the power to both the Arduino and the Peltier at the same time. When the Peltier turns "on" the Arduino seems to be starved of power and there is a drop in voltage across the power supply. I need to run both the Peltier and Arduino off one power supply as I cannot have multiple power input into the confined space in the dry box. Can anybody help me and tell me where I went wrong please? The image below is one of the last configuration I have.
Appreciate any help, I am still very new to this.
#include "DHT.h"
#define DHTPIN 9
#define DHTTYPE DHT22
DHT dht22(DHTPIN, DHTTYPE);
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
int n = 1;
int t;
int Dew;
int h;
int hTarget;
int peltier = 10;
int switchDown = 5;
int switchUp = 6;
int switchBacklight = 11;
boolean switchDownCState = LOW;
boolean switchUpCState = LOW;
boolean switchBacklightCState = LOW;
boolean switchDownLState = LOW;
boolean switchUpLState = LOW;
boolean switchBacklightLState = LOW;
boolean BacklightState = HIGH;
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
byte termometru[8] =
{
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte picatura[8] =
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
boolean debounce(boolean last, int switchPin)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}
void setup()
{
dht22.begin();
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
lcd.begin(16, 2);
lcd.createChar(1,termometru);
lcd.createChar(2,picatura);
hTarget = 55;
pinMode(peltier, OUTPUT);
pinMode(switchDown, INPUT);
pinMode(switchUp, INPUT);
pinMode(switchBacklight, INPUT);
}
void loop()
{
t = dht22.readTemperature();
h = dht22.readHumidity();
Dew = dewPointFast(t, h);
lcd.setCursor(0, 0);
lcd.write(1);
lcd.setCursor(2, 0);
lcd.print(t);
lcd.setCursor(4, 0);
lcd.print((char)0xDF);
lcd.print("C");
lcd.setCursor(7, 0);
lcd.write(2);
lcd.setCursor(9, 0);
lcd.print(h);
lcd.setCursor(11, 0);
lcd.print("%");
if (h > hTarget)
{
lcd.setCursor(13, 0);
lcd.print("ON ");
digitalWrite(peltier, HIGH);
}
else
{
lcd.setCursor(13, 0);
lcd.print("OFF");
digitalWrite(peltier, LOW);
}
lcd.setCursor(0, 1);
lcd.print("Set for: ");
lcd.setCursor(9, 1);
lcd.print(hTarget);
lcd.setCursor(11, 1);
lcd.print("%");
switchDownCState = debounce(switchDownLState, switchDown);
if (switchDownLState == LOW && switchDownCState == HIGH && hTarget > 25)
{
hTarget=hTarget-1;
}
switchDownLState = switchDownCState;
switchUpCState = debounce(switchUpLState, switchUp);
if (switchUpLState == LOW && switchUpCState == HIGH && hTarget < 90)
{
hTarget=hTarget+1;
}
switchUpLState = switchUpCState;
switchBacklightCState = debounce(switchBacklightLState, switchBacklight);
if (switchBacklightLState == LOW && switchBacklightCState == HIGH)
{
if (BacklightState == LOW)
{
lcd.setBacklight(HIGH);
lcd.display();
BacklightState = HIGH;
delay(1000);
}
if (BacklightState == HIGH && digitalRead(switchBacklight) == HIGH)
{
lcd.setBacklight(LOW);
lcd.noDisplay();
BacklightState = LOW;
}
}
switchBacklightLState = switchBacklightCState;
}
Dehumidifier 20160726.1330.zip (48.4 KB)
