hello everyone,
I'm new to arduino and currently doing project which is Smart Medicine Dispenser (SMD). this project remind the user to take medicine on time and contain 3 compartment for 3 kinds of medicine. My code below are only for 1 compartment and i don't know what to add to make it to 3 compartments.
what i initially what to do is for each number user key in, it will represent the delay that the buzzer will activated. for example if the user push 1, the delay will be 1 hour. but in the code below, any number pushed by user the delay is only 10 seconds.
flow of the code :
The user need to key-in time for each compartment and i just use delay instead of using RTC. when the user push a number on keypad, it will be displayed on LCD and time will be delayed for 10 seconds. after 10 seconds, buzzer will activated together with LED and when the user push the button, buzzer and LED will be low. If the button still not pushed, buzzer n LED will continue activated.
what should i add to make the compartment 3?
#include <Keypad.h>
#include <LiquidCrystal.h>
#define switch1 44 // pin untuk switch
#define LED 50;
#define c 3830 // 261 Hz
#define d 3400 // 294 Hz
#define e 3038 // 329 Hz
#define f 2864 // 349 Hz
#define g 2550 // 392 Hz
#define a 2272 // 440 Hz
#define b 2028 // 493 Hz
#define C 1912 // 523 Hz
int buzzerPin=52;//Connect the buzz positive Pin to Digital Pin 8
int val=0; // untuk declare switch
LiquidCrystal lcd(8,9,4,5,6,7);
const byte ROWS = 4; // four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {22,24,26,28}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {30,32,34}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
pinMode(50,OUTPUT); // led
pinMode (switch1, INPUT); //untuk switch
lcd.begin(16,2);
lcd.setCursor( 1, 0 ); //upper left lcd
lcd.print( "Welcome!" );
lcd.setCursor( 0, 1 ); //bottom left lcd
lcd.print( "enter time" );
}
void loop()
{
int loop1 = 1;
char keys =keys2 = keypad.getKey(); // user tekan keypad
if (keys > 0) // untuk nombor '1'
{
lcd.clear();
lcd.setCursor( 1, 0 ); //upper left lcd
lcd.print( "C1 time : " );
lcd.setCursor( 0, 1 );
lcd.print(keys);
lcd.print( " hours " );
delay(10000); // 10*1000ms = 10 saat
analogWrite(50,HIGH);
tone(buzzerPin, c, 100);
delay(500);
tone(buzzerPin, d, 100);
delay(500);
tone(buzzerPin, e, 100);
delay(500);
tone(buzzerPin, f, 100);
delay(500);
tone(buzzerPin, g, 100);
delay(500);
tone(buzzerPin, a, 100);
delay(500);
tone(buzzerPin, b, 100);
delay(500);
tone(buzzerPin, c, 100);
delay(100);
while(loop1 == 1)
{ //Open Loop1
val = digitalRead(switch1);
if (val == HIGH) // switch ditekan
{
digitalWrite(buzzerPin,LOW);//Be quiet
analogWrite(50,LOW);
loop1 = 0;
}
else
{
digitalWrite(buzzerPin ,HIGH);
analogWrite(50,HIGH );
}
} // Close Loop1
}
}
please help me.
Thank you for reading.