major changes
- switched to the correct DHT library - cleaned out cruft - got more light sensors connected - display on the LCD Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
66ab550699
commit
bb0c226c31
1 changed files with 114 additions and 91 deletions
193
soler_chager.ino
193
soler_chager.ino
|
@ -1,22 +1,30 @@
|
|||
#include <Wire.h>
|
||||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
#include <DHT.h>
|
||||
#include <dht11.h>
|
||||
#include <BH1750.h>
|
||||
#include <Servo.h>
|
||||
|
||||
#define DHT11_PIN 7
|
||||
#define photoL1 A0
|
||||
#define photoL2 A1
|
||||
#define photoL3 A2
|
||||
#define photoL4 A3
|
||||
#define LED 3
|
||||
#define button 2
|
||||
#define buzzer 6
|
||||
#define circleServoPin 9
|
||||
#define tiltServoPin 10
|
||||
#define LED 3//define the pin of LED as D10
|
||||
|
||||
BH1750 lightMeter;
|
||||
DHT dht(DHT11_PIN, DHT11);
|
||||
dht11 DHT;
|
||||
volatile int buttonState;
|
||||
volatile int lightReadL1 = 0;
|
||||
int count;
|
||||
volatile int lightReadL2 = 0;
|
||||
volatile int lightReadL3 = 0;
|
||||
volatile int lightReadL4 = 0;
|
||||
int value;
|
||||
int servoPin = 9;//set the pin of the servo
|
||||
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
||||
Servo circleServo;
|
||||
Servo tiltServo;
|
||||
|
@ -24,38 +32,39 @@ Servo tiltServo;
|
|||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("");
|
||||
Serial.print("setting up!\n");
|
||||
pinMode(LED, OUTPUT); //initialize digital pin LED as an output.
|
||||
pinMode(button, INPUT);
|
||||
pinMode(buzzer, OUTPUT);
|
||||
circleServo.attach(circleServoPin);
|
||||
tiltServo.attach(tiltServoPin);
|
||||
|
||||
Serial.print("init lcd\n");
|
||||
lcd.init();
|
||||
lcd.backlight();
|
||||
lcd.setCursor(0,0);
|
||||
lcd.printstr("Hello, World!");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.printstr("hello, Roald!");
|
||||
lcd.printstr("setting up!");
|
||||
//lcd.setCursor(0,1);
|
||||
//lcd.printstr("hey,human!");
|
||||
|
||||
dht.begin(20);
|
||||
pinMode(LED, OUTPUT); //initialize digital pin LED as an output.
|
||||
pinMode(button, INPUT);
|
||||
pinMode(buzzer, OUTPUT);
|
||||
//circleServo.attach(circleServoPin);
|
||||
//tiltServo.attach(tiltServoPin);
|
||||
|
||||
Serial.print("done setting up!\n");
|
||||
lcd.clear();
|
||||
lcd.setCursor(0,0);
|
||||
lcd.printstr("done");
|
||||
|
||||
//Intialize the 12C bus
|
||||
Wire.begin();
|
||||
//On esp8266 you can select SCL and SDA pins using Wire.begin
|
||||
//For Wemos /Lolin D1 Mini Pro and the Ambient Light shield use
|
||||
Wire.begin();
|
||||
lightMeter.begin();
|
||||
Serial.println(F("BH1750 Test begin"));
|
||||
}
|
||||
|
||||
void loop(){
|
||||
//Serial.print("[");
|
||||
//Serial.print(count);
|
||||
//Serial.print("] hey\n");
|
||||
|
||||
void loop()
|
||||
{
|
||||
/*
|
||||
delay(300);
|
||||
for (int i = 180; i > 0; i--) {
|
||||
circleServo.write(i);
|
||||
|
@ -67,92 +76,106 @@ void loop(){
|
|||
tiltServo.write(i);
|
||||
delay(10);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
servopulse(servoPin, 0);//rotate to 0 degree
|
||||
delay(200);//delay in 1s
|
||||
servopulse(servoPin, 90);//rotate to 90 degrees
|
||||
delay(200);
|
||||
servopulse(servoPin, 180);//rotate to 1800 degrees
|
||||
delay(200);
|
||||
|
||||
lightReadL1 = analogRead(photoL1);
|
||||
if (lightReadL1 > 300){
|
||||
digitalWrite(LED, HIGH);
|
||||
}
|
||||
else{
|
||||
digitalWrite(LED, LOW);
|
||||
}
|
||||
*/
|
||||
|
||||
float lux = lightMeter.readLightLevel();
|
||||
float hum = dht.readTemperature();
|
||||
float temp = dht.readHumidity();
|
||||
int chk;
|
||||
chk = DHT.read(DHT11_PIN);
|
||||
switch (chk)
|
||||
{
|
||||
Serial.print("hum: ");
|
||||
Serial.print(hum);
|
||||
Serial.print(" temp: ");
|
||||
Serial.print(dht.convertCtoF(temp));
|
||||
Serial.print(" L1: ");
|
||||
Serial.print(lightReadL1);
|
||||
Serial.print(" PanL: ");
|
||||
Serial.print(lux);
|
||||
Serial.println("lx");
|
||||
delay(50);
|
||||
case DHTLIB_OK:
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.println("[ERR] dht11 checksum");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
Serial.println("[ERR] dht11 timeout");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//delay(100);
|
||||
float lux = lightMeter.readLightLevel();
|
||||
lightReadL1 = analogRead(photoL1);
|
||||
lightReadL2 = analogRead(photoL2);
|
||||
lightReadL3 = analogRead(photoL3);
|
||||
lightReadL4 = analogRead(photoL4);
|
||||
{
|
||||
char buf[40];
|
||||
char lStr[6];
|
||||
dtostrf(lux, 4, 2, lStr); // https://forum.arduino.cc/t/sprintf-with-float-values/937562
|
||||
sprintf(buf, "h: %d%%, t: %dF, l: %s, ", DHT.humidity, CtoF(DHT.temperature), lStr);
|
||||
Serial.print(buf);
|
||||
|
||||
//blink();
|
||||
sprintf(buf, "L1: %d, L2: %d, L3: %d, L4: %d", lightReadL1, lightReadL2, lightReadL3, lightReadL4);
|
||||
Serial.println(buf);
|
||||
|
||||
lcd.clear();
|
||||
// the LCD has two rows and 17 columns ...
|
||||
sprintf(buf, "h:%d,t:%d,l:%s", DHT.humidity, CtoF(DHT.temperature), lStr);
|
||||
lcd.setCursor(0,0);
|
||||
lcd.printstr(buf);
|
||||
|
||||
sprintf(buf, "%d,%d,%d,%d", lightReadL1, lightReadL2, lightReadL3, lightReadL4);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.printstr(buf);
|
||||
}
|
||||
delay(2000);
|
||||
|
||||
/*
|
||||
{
|
||||
Serial.print("hum: ");
|
||||
Serial.print(DHT.humidity);
|
||||
Serial.print(", temp: ");
|
||||
Serial.print(CtoF(DHT.temperature));
|
||||
Serial.print(", L1: ");
|
||||
Serial.print(lightReadL1);
|
||||
Serial.print(", L2: ");
|
||||
Serial.print(lightReadL2);
|
||||
Serial.print(", L3: ");
|
||||
Serial.print(lightReadL3);
|
||||
Serial.print(", L4: ");
|
||||
Serial.print(lightReadL4);
|
||||
Serial.print(", lx: ");
|
||||
Serial.println(lux);
|
||||
delay(500);
|
||||
}
|
||||
*/
|
||||
|
||||
buttonState = digitalRead(button);
|
||||
if(buttonState == 0) {
|
||||
digitalWrite(LED, HIGH);
|
||||
birthdaySong();
|
||||
for(value = 0; value < 255; value +1){
|
||||
analogWrite (LED, value);//LED lights gradually light up
|
||||
}
|
||||
} else {
|
||||
digitalWrite(LED, LOW);
|
||||
value = 0;
|
||||
}
|
||||
//delay(100);
|
||||
|
||||
//count++;
|
||||
}
|
||||
|
||||
void birthdaySong() {
|
||||
tone(buzzer, 294);
|
||||
delay(250);
|
||||
tone(buzzer, 440);
|
||||
delay(250);
|
||||
tone(buzzer, 392);
|
||||
delay(250);
|
||||
tone(buzzer, 532);
|
||||
delay(250);
|
||||
tone(buzzer, 494);
|
||||
delay(500);
|
||||
tone(buzzer, 392);
|
||||
delay(250);
|
||||
tone(buzzer, 440);
|
||||
delay(250);
|
||||
tone(buzzer, 392);
|
||||
delay(250);
|
||||
noTone(buzzer);
|
||||
tone(buzzer, 587);
|
||||
delay(250);
|
||||
tone(buzzer, 532);
|
||||
delay(500);
|
||||
tone(buzzer, 392);
|
||||
delay(250);
|
||||
tone(buzzer, 784);
|
||||
delay(250);
|
||||
tone(buzzer, 659);
|
||||
delay(250);
|
||||
tone(buzzer, 532);
|
||||
delay(250);
|
||||
tone(buzzer, 494);
|
||||
delay(250);
|
||||
tone(buzzer, 440);
|
||||
delay(250);
|
||||
tone(buzzer, 698);
|
||||
delay(375);
|
||||
tone(buzzer, 659);
|
||||
delay(250);
|
||||
tone(buzzer, 532);
|
||||
delay(250);
|
||||
tone(buzzer, 587);
|
||||
delay(250);
|
||||
tone(buzzer, 532);
|
||||
delay(500);
|
||||
noTone(buzzer);
|
||||
int CtoF(int temp)
|
||||
{
|
||||
return temp * 1.8 + 32;
|
||||
}
|
||||
|
||||
int FtoC(int temp)
|
||||
{
|
||||
return (temp - 32) * 0.55555;
|
||||
}
|
||||
|
||||
void blink()
|
||||
|
|
Loading…
Reference in a new issue