// 로드 셀 센서(2,3), led링
//모터 : 스텝모터 1개, dc모터 1개 서보모터 2개(2,9), 워터 펌프 4개 //led : (led스트랩, 링) led, lcd화면 //센서 : (로드셀 센서) //블루투스 연결
송신부: 스텝모터1개, lcd화면, 블루투스 연결, led 스트랩 , 로드셀, led링
수신부: 서보모터2개 , dc모터 1개, 워터 펌프 4개
송신부
//완성
//송신부
//스텝모터1개(8,9,10,11), lcd화면(아날로그0,1), 블루투스 연결(2,3), led 스트랩(12) , 초음파(5,6)
#include "HX711.h"
#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#include <LiquidCrystal_I2C.h>
#include "LedControl.h"
#include <Stepper.h>
LiquidCrystal_I2C lcd(0x27,16,2);
SoftwareSerial BTSerial(2,3);
const int stepsPerRevolution = 200;
Stepper myStepper = Stepper(stepsPerRevolution, 8, 9, 10, 11);
// 초음파센서
int trig = 5;
int echo = 6;
void setup() {
Serial.begin(9600);
//블루투스
BTSerial.begin(9600);
//lcd setup
lcd.init();
lcd.backlight();
lcd.print("HELLO!");
lcd.setCursor(0,1);
lcd.print("CHOOSE COCKTAIL");
//스텝모터
myStepper.setSpeed(100);
//초음파
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
//초음파 테스트 led
pinMode(7,OUTPUT);
}
void loop() {
cooling();
//초음파 센서
digitalWrite(trig, LOW);
digitalWrite(echo, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
unsigned long duration = pulseIn(echo, HIGH);
float distance = duration / 29.0 / 2.0;
lcd.clear();
lcd.print("HELLO!");
lcd.setCursor(0,1);
lcd.print("CHOOSE COCKTAIL");
// 로드셀 신호 받아서 블루투스로 보내기
// 컵 올려 놓으면
if(distance<20){
//블루투스 신호 보내기
BTSerial.println("1");
//led 링
digitalWrite(7,HIGH);
}
//컵 없으면
else {
//블루투스 신호 보내기
BTSerial.println("0");
//led링
digitalWrite(7,LOW);
}
// 블루투스 신호 조건문
if(BTSerial.available() > 0) {
char command= BTSerial.read();
lcd.clear();
// 1일때 진토닉
if(command=='1'){
// lcd
lcd.home();
lcd.print("making...");
lcd.setCursor(0,1);
lcd.print("JIN TONIC");
//스텝모터(진)
delay(500);
myStepper.step(400);
cooling();
delay(500);
//액츄에이터 서보모터
Serial.write('a');
delay(5000);
//스텝모터(워터 펌프)
delay(500);
myStepper.step(400);
cooling();
delay(500);
//워터 펌프(사이다)
Serial.write('4');
delay(5000);
//워터 펌프(라임주스)
Serial.write('1');
delay(5000);
//스텝모터(스터러)
delay(500);
myStepper.step(400);
cooling();
delay(500);
//서보 모터,dc모터(스터러)
Serial.write('b');
delay(5000);
//스텝모터(원래 자리로 시계반대방향으로 돌아서 오기)
delay(500);
myStepper.step(-400);
cooling();
delay(500);
//완성신호 보내기
BTSerial.println('2');
//lcd 화면 출력
lcd.clear();
lcd.home();
lcd.print("Take the");
lcd.setCursor(0,1);
lcd.print("JIN TONIC");
delay(5000);
//스텝모터(원래 자리로 시계반대방향으로 돌아서 오기)
myStepper.step(-400);
cooling();
}
//2일때 마가리따
else if(command=='2'){
// lcd
lcd.home();
lcd.print("making...");
lcd.setCursor(0,1);
lcd.print("MAGARITA");
//스텝모터(데낄라)
myStepper.step(400);
cooling();
delay(500);
//액츄에이터 서보모터
Serial.write('a');
delay(5000);
//스텝모터(트리플 섹)
myStepper.step(400);
cooling();
delay(500);
//액츄에이터 서보모터
Serial.write('a');
delay(5000);
//스텝모터(트리플 섹)
myStepper.step(400);
cooling();
//워터 펌프(라임쥬스)
Serial.write('1');
delay(5000);
//스텝모터(스터러)
myStepper.step(400);
cooling();
//스터러
Serial.write('b');
delay(5000);
//스텝모터
myStepper.step(-400);
cooling();
delay(500);
//완성신호 보내기
BTSerial.println('3');
//lcd 화면 출력
lcd.clear();
lcd.home();
lcd.print("Take the");
lcd.setCursor(0,1);
lcd.print("MAGARITA");
delay(5000);
}
//피치크러쉬
else if(command=='3'){
// lcd
lcd.home();
lcd.print("making...");
lcd.setCursor(0,1);
lcd.print("PEACH CRUSH");
//스텝모터(크렌베리주스)
myStepper.step(400);
cooling();
delay(5000);
//워터 펌프(크렌베리쥬스)
Serial.write('a');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
delay(500);
//액츄에이터 서보모터
Serial.write('a');
delay(5000);
//스텝모터(스터러)
myStepper.step(400);
cooling();
delay(500);
//스터러
Serial.write('b');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
delay(500);
//완성신호 보내기
BTSerial.println('3');
//lcd 화면 출력
lcd.clear();
lcd.home();
lcd.print("Take the");
lcd.setCursor(0,1);
lcd.print("PEACH CRUSH");
delay(5000);
//스텝모터(원래자리로 돌아가기)
myStepper.step(-400);
cooling();
delay(500);
}
//슬레머
else if(command=='4'){
// lcd
lcd.home();
lcd.print("making...");
lcd.setCursor(0,1);
lcd.print("SLAMMER");
//스텝모터(데낄라)
myStepper.step(400);
cooling();
//액츄에이터 서보모터
Serial.write('a');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//워터 펌프(사이다)
Serial.write('4');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//스텝모터(스터러)
Serial.write('b');
//스텝모터
myStepper.step(400);
cooling();
//완성신호 보내기
BTSerial.println('3');
//lcd 화면 출력
lcd.clear();
lcd.home();
lcd.print("Take the");
lcd.setCursor(0,1);
lcd.print("SLAMMER");
delay(5000);
}
//모히또
else if(command=='5'){
// lcd
lcd.home();
lcd.print("making...");
lcd.setCursor(0,1);
lcd.print("MOJITO");
//스텝모터(진)
myStepper.step(400);
cooling();
//액츄에이터 서보모터
Serial.write('a');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//워터 펌프(라임쥬스)
Serial.write('1');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//스터러
Serial.write('b');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//완성신호 보내기
BTSerial.println('3');
//lcd 화면 출력
lcd.clear();
lcd.home();
lcd.print("Take the");
lcd.setCursor(0,1);
lcd.print("MOJITO");
delay(5000);
}
//피치 코코
else if(command=='6'){
// lcd
lcd.home();
lcd.print("making...");
lcd.setCursor(0,1);
lcd.print("PEACH COCO");
//스텝모터(피치트리)
myStepper.step(400);
cooling();
//액츄에이터 서보모터
Serial.write('a');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//워터 펌프(크렌베리쥬스)
Serial.write('3');
delay(5000);
//워터 펌프(레몬쥬스)
Serial.write('2');
delay(5000);
myStepper.step(400);
cooling();
//스텝모터(스터러)
Serial.write('b');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//완성신호 보내기
BTSerial.println('3');
//lcd 화면 출력
lcd.clear();
lcd.home();
lcd.print("Take the");
lcd.setCursor(0,1);
lcd.print("PEACH COCO");
delay(5000);
}
//소맥 약한거
else if(command=='7'){
// lcd
lcd.home();
lcd.print("making...");
lcd.setCursor(0,1);
lcd.print("SOMAC");
//스텝모터(소주)
myStepper.step(400);
cooling();
//액츄에이터 서보모터(소주)
Serial.write('a');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//액츄에이터 서보모터(맥주)
Serial.write('a');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//스터러
Serial.write('b');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//완성신호 보내기
BTSerial.println('3');
//lcd 화면 출력
lcd.clear();
lcd.home();
lcd.print("Take the");
lcd.setCursor(0,1);
lcd.print("SOMAC");
delay(5000);
}
//소맥 센거
else if(command=='8'){
// lcd
lcd.home();
lcd.print("making...");
lcd.setCursor(0,1);
lcd.print("STRONG SOMAC");
//스텝모터(소주)
myStepper.step(400);
cooling();
//액츄에이터 서보모터(소주)
Serial.write('a');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//액츄에이터 서보모터(맥주)
Serial.write('a');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//스터러
Serial.write('b');
delay(5000);
//스텝모터
myStepper.step(400);
cooling();
//완성신호 보내기
BTSerial.println('3');
//lcd 화면 출력
lcd.clear();
lcd.home();
lcd.print("Take the");
lcd.setCursor(0,1);
lcd.print("STRONG SOMAC");
delay(5000);
}
}
}
void cooling(){
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
}
수신부
//1라임 2레몬 3크렌베리 4사이다
#include <SoftwareSerial.h>*
#include <Servo.h>
//스터러 dc모터
int dcMotor=9;
//워터펌프
int pump1=5;
int pump2=6;
int pump3=7;
int pump4=8;
//서보 모터
Servo stirerServo;
Servo actuatorServo;
int pos = 0; // variable to store the servo position
void setup() {
Serial.begin(9600);
//워터 펌프
pinMode(pump1,OUTPUT);
pinMode(pump2,OUTPUT);
pinMode(pump3,OUTPUT);
pinMode(pump4,OUTPUT);
//서보모터 설정
stirerServo.attach(10);
actuatorServo.attach(2);
//스터러 dc모터
pinMode(dcMotor,OUTPUT);
}
void loop() {
while(Serial.available()){
char data=Serial.read();
if(data=='a'){
//엑츄에이터 서보모터
for (pos = 180; pos >= 90; pos -= 1) { // goes from 180 degrees to 0 degrees
// in steps of 1 degree
actuatorServo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
actuatorServo.write(90);
delay(3000);
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
actuatorServo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
actuatorServo.write(90);
}
else if(data=='b'){
//스터러 서보모터 내려가기
for (pos = 180; pos >= 90; pos -= 1) { // goes from 180 degrees to 0 degrees
stirerServo.write(pos); // tell servo to go to position in variable 'pos'
delay(27); // waits 15ms for the servo to reach the position
}
stirerServo.write(90);
//스터러 dc모터
digitalWrite(dcMotor,HIGH);
delay(1000);
digitalWrite(dcMotor,LOW);
//스터러 서보모터 올라가기
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
stirerServo.write(pos); // tell servo to go to position in variable 'pos'
delay(27); // waits 15ms for the servo to reach the position
}
stirerServo.write(90);
}
else if(data=='1'){
//워터펌프 1
digitalWrite(pump1,HIGH);
delay(2000);
digitalWrite(pump1,LOW);
}
else if(data=='2'){
//워터펌프 2
digitalWrite(pump2,HIGH);
delay(2000);
digitalWrite(pump2,LOW);
}
else if(data=='3'){
//워터펌프 3
digitalWrite(pump3,HIGH);
delay(2000);
digitalWrite(pump3,LOW);
}
else if(data=='4'){
//워터펌프 4
digitalWrite(pump4,HIGH);
delay(2000);
digitalWrite(pump4,LOW);
}
}}