Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 251507a

Browse files
Merge pull request #3 from mikebionic/uncub_upd
some updates of incubator
2 parents b882b8c + 62b25a9 commit 251507a

File tree

2 files changed

+223
-21
lines changed

2 files changed

+223
-21
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
#include <HT1621.h>
2+
#define LCD_CS_PIN 13
3+
#define LCD_WR_PIN 11
4+
#define LCD_DATA_PIN 9
5+
HT1621 lcd;
6+
7+
#include <Servo.h>
8+
#include "DHT.h"
9+
10+
11+
#define DHTPIN 8
12+
#define DHTTYPE DHT11
13+
DHT dht(DHTPIN, DHTTYPE);
14+
float dht_humi;
15+
float dht_temp;
16+
17+
Servo cyglyk_s;
18+
Servo motor_s;
19+
20+
int slow_servo_state = 0;
21+
int setted_slow_servo_state = 0;
22+
long slow_servo_millis;
23+
int slow_servo_speed = 20;
24+
25+
26+
int motor_turn_time_h = 2;
27+
unsigned long motor_turn_time_ms = 10800000;//60000; ///2 * 60 * 60 * 1000;
28+
29+
const int c_s_pin = 4;
30+
const int m_s_pin = 5;
31+
const int fan_pin = 6;
32+
const int lmp_pin = 7;
33+
const int pot_pin = A0;
34+
const int sbtn_pin= 12;
35+
36+
int pot_val;
37+
int setted_T;
38+
unsigned long temp_millis;
39+
unsigned long motor_millis;
40+
41+
int motor_s_down_val = 165;
42+
int motor_s_up_val = 15;
43+
int cyglyk_s_down_val = 179;
44+
int cyglyk_s_up_val = 1;
45+
int motor_current_state = 1;
46+
47+
byte u[8] =
48+
{
49+
0b01010,
50+
0b00000,
51+
0b10001,
52+
0b10001,
53+
0b10001,
54+
0b10011,
55+
0b01101,
56+
0b00000
57+
};
58+
59+
void setup() {
60+
Serial.begin(9600);
61+
dht.begin();
62+
//-----PINS-----
63+
pinMode(fan_pin,OUTPUT);
64+
pinMode(lmp_pin,OUTPUT);
65+
pinMode(pot_pin,INPUT);
66+
pinMode(sbtn_pin,INPUT);
67+
68+
cyglyk_s.attach(c_s_pin);
69+
motor_s.attach(m_s_pin);
70+
71+
//-----LCD------
72+
lcd.begin(LCD_CS_PIN, LCD_WR_PIN, LCD_DATA_PIN);
73+
lcd.backlight();
74+
lcd.clear();
75+
lcd.print("incubi");
76+
lcd.setBatteryLevel(1);
77+
delay(200);
78+
lcd.setBatteryLevel(2);
79+
delay(200);
80+
lcd.setBatteryLevel(3);
81+
delay(200);
82+
lcd.setBatteryLevel(0);
83+
84+
85+
//checking the motor
86+
cyglyk_s.write(cyglyk_s_down_val);
87+
delay(200);
88+
cyglyk_s.write(cyglyk_s_up_val);
89+
delay(200);
90+
cyglyk_s.write(cyglyk_s_down_val);
91+
delay(200);
92+
lcd.clear();
93+
}
94+
95+
96+
void loop() {
97+
temp();
98+
temp_sazlayjy();
99+
humidity_controller();
100+
motor_s_turning();
101+
servo_write_slow();
102+
sbtn_motor_manual_control();
103+
}
104+
105+
106+
// collect temperature info from sensor
107+
void temp(){
108+
if ((temp_millis + 5000) < millis()){
109+
dht_humi = dht.readHumidity();
110+
dht_temp = dht.readTemperature();
111+
lcd.printCelsius(dht_temp);
112+
113+
temp_millis = millis();
114+
}
115+
}
116+
117+
118+
// Control the temperature by switching heater on/off
119+
void temp_sazlayjy() {
120+
pot_val = analogRead(pot_pin);
121+
setted_T = map(pot_val,0,1023,36,40);
122+
int view_T = map(setted_T,36,39,0,3);
123+
lcd.setBatteryLevel(view_T);
124+
// // printing the elapsed time to turn the holder
125+
// lcd.print(((motor_millis + motor_turn_time_ms) - millis())/1000);
126+
// lcd.print(" ");
127+
// lcd.print(setted_T);
128+
// lcd.print("*C ");
129+
if (setted_T > dht_temp ) {
130+
digitalWrite(lmp_pin, 1);
131+
} else if (setted_T < dht_temp) {
132+
digitalWrite(lmp_pin, 0);
133+
}
134+
}
135+
136+
137+
// Control the humidity with servo and fan
138+
void humidity_controller(){
139+
if (dht_humi > 50) {
140+
cyglyk_s.write (cyglyk_s_up_val);
141+
digitalWrite(fan_pin, 1);
142+
}
143+
else{
144+
cyglyk_s.write(cyglyk_s_down_val);
145+
digitalWrite(fan_pin, 0);
146+
}
147+
if (dht_temp > 40){
148+
digitalWrite(fan_pin,1);
149+
} else {
150+
digitalWrite(fan_pin,0);
151+
}
152+
}
153+
154+
155+
void motor_s_turning() {
156+
if((motor_millis + motor_turn_time_ms) < millis()){
157+
if (motor_current_state == 1){
158+
// motor_s.write(motor_s_up_val);
159+
setted_slow_servo_state = motor_s_up_val;
160+
motor_current_state = 0;
161+
} else {
162+
setted_slow_servo_state = motor_s_down_val;
163+
motor_current_state = 1;
164+
}
165+
motor_millis = millis();
166+
}
167+
}
168+
169+
170+
void servo_write_slow(){
171+
if (slow_servo_state <= setted_slow_servo_state){
172+
if (slow_servo_millis + slow_servo_speed < millis()){
173+
motor_s.write(slow_servo_state);
174+
slow_servo_state++;
175+
slow_servo_millis = millis();
176+
}
177+
}
178+
if (slow_servo_state >= setted_slow_servo_state){
179+
if (slow_servo_millis + slow_servo_speed < millis()){
180+
motor_s.write(slow_servo_state);
181+
slow_servo_state--;
182+
slow_servo_millis = millis();
183+
}
184+
}
185+
}
186+
187+
188+
// change egg holder motor state by pressing button
189+
void sbtn_motor_manual_control() {
190+
int sbtn_state = digitalRead(sbtn_pin);
191+
if (sbtn_state == 1){
192+
if (motor_current_state == 1){
193+
motor_current_state = 0;
194+
setted_slow_servo_state = motor_s_up_val;
195+
} else {
196+
motor_current_state = 1;
197+
setted_slow_servo_state = motor_s_down_val;
198+
}
199+
200+
slow_servo_millis = 0;
201+
motor_millis = millis();
202+
delay(500);
203+
}
204+
}

‎incubator-nano/naval_incubator.cpp‎ renamed to ‎incubator-nano/naval_incubator_LCDI2C.cpp‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LiquidCrystal_I2C lcd(0x27, 16, 2);
88
#define DHTTYPE DHT11
99
DHT dht(DHTPIN, DHTTYPE);
1010
float dht_humi;
11-
unsignedint dht_temp;
11+
float dht_temp;
1212

1313
Servo cyglyk_s;
1414
Servo motor_s;
@@ -20,7 +20,7 @@ int slow_servo_speed = 20;
2020

2121

2222
int motor_turn_time_h = 2;
23-
long motor_turn_time_ms = 10800000; ///2 * 60 * 60 * 1000;
23+
unsignedlong motor_turn_time_ms = 60000;//10800000; ///2 * 60 * 60 * 1000;
2424

2525
const int c_s_pin = 4;
2626
const int m_s_pin = 5;
@@ -31,8 +31,8 @@ const int sbtn_pin= 12;
3131

3232
int pot_val;
3333
int setted_T;
34-
long temp_millis;
35-
long motor_millis;
34+
unsignedlong temp_millis;
35+
unsignedlong motor_millis;
3636

3737
int motor_s_down_val = 165;
3838
int motor_s_up_val = 15;
@@ -64,7 +64,7 @@ void setup() {
6464
lcd.setCursor(4,0);
6565
lcd.print("Salam!!");
6666
lcd.setCursor(0,1);
67-
lcd.print("Zayebal ;)");
67+
lcd.print("Kubi ;)");
6868

6969
//-----PINS-----
7070
pinMode(fan_pin,OUTPUT);
@@ -98,26 +98,20 @@ void loop() {
9898

9999
// collect temperature info from sensor
100100
void temp(){
101-
if ((temp_millis + 4000) < millis()){
101+
if ((temp_millis + 5000) < millis()){
102102
dht_humi = dht.readHumidity();
103103
dht_temp = dht.readTemperature();
104104

105105
lcd.setCursor(0,0);
106-
lcd.print ("Tmp ");
106+
lcd.print ("T ");
107107
lcd.print (dht_temp);
108-
lcd.print ("*C ");
108+
lcd.print ("*C ");
109109
lcd.setCursor (0,1);
110-
lcd.print ("Cyg ");
110+
lcd.print ("H ");
111111
lcd.print (dht_humi);
112112
lcd.print ("%");
113113
lcd.setCursor (7,1);
114114
lcd.print (" ");
115-
Serial.print ("Temp = ");
116-
Serial.print (dht_temp);
117-
Serial.print (" *C ");
118-
Serial.print ("Cyglylyk ");
119-
Serial.print (dht_humi);
120-
Serial.println (" %");
121115
temp_millis = millis();
122116
}
123117
}
@@ -127,19 +121,18 @@ void temp(){
127121
void temp_sazlayjy() {
128122
pot_val = analogRead(pot_pin);
129123
setted_T = map(pot_val,0,1023,30,41);
130-
lcd.setCursor(9,0);
124+
lcd.setCursor(11,0);
131125

132126
// printing the elapsed time to turn the holder
133127
lcd.print(((motor_millis + motor_turn_time_ms) - millis())/1000);
134128
lcd.print(" ");
135129
lcd.setCursor(12,1);
136130
lcd.print(setted_T);
137131
lcd.print("*C ");
138-
Serial.println(setted_T);
139132
if (setted_T > dht_temp ) {
140-
digitalWrite(lmp_pin, 0);
141-
} else if (setted_T < dht_temp) {
142133
digitalWrite(lmp_pin, 1);
134+
} else if (setted_T < dht_temp) {
135+
digitalWrite(lmp_pin, 0);
143136
}
144137
}
145138

@@ -154,6 +147,11 @@ void humidity_controller(){
154147
cyglyk_s.write(cyglyk_s_down_val);
155148
digitalWrite(fan_pin, 0);
156149
}
150+
if (dht_temp > 40){
151+
digitalWrite(fan_pin,1);
152+
} else {
153+
digitalWrite(fan_pin,0);
154+
}
157155
}
158156

159157

@@ -178,7 +176,7 @@ void servo_write_slow(){
178176
motor_s.write(slow_servo_state);
179177
slow_servo_state++;
180178
slow_servo_millis = millis();
181-
}
179+
}
182180
}
183181
if (slow_servo_state >= setted_slow_servo_state){
184182
if (slow_servo_millis + slow_servo_speed < millis()){
@@ -206,4 +204,4 @@ void sbtn_motor_manual_control() {
206204
motor_millis = millis();
207205
delay(500);
208206
}
209-
}
207+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /