Components and supplies
Arduino Nano R3
IR receiver 3pin
Keypad
Jumper wires (generic)
Duble taped 3M
SG90 Micro-servo motor
Cardboard
Apps and platforms
Arduino IDE
Universal Remote app and device
Alexa Voice Service
Project description
Code
Smart Coin Feeder
arduino
1/* 2 * Device for retrieve coins in a given amount. 3 * Works Manually trough keypad presses (only 1 to 9) 4 * Works remotely with a remote control. 5 * Works with voice commands trough Alexa or other vice assistants. Need also an Universal Remota Controlfor home automation. 6 * Make the UR learn the remote control and configura apropriate scenes and routines in Alexa. 7 * 8 * Feel free to develop and improve! and please let me know. 9 * 10 * Arduino Project Hub 11 * NerdFatherRj - Rio de Janeiro - BRA - Dec.2020. 12 * 13 */ 14 15 16#include <IRremote.h> 17#include <ir_Lego_PF_BitStreamEncoder.h> 18 19#include <Servo.h> 20#include <Keypad.h> 21Servo Srv; 22 23int RECV_PIN = 12; //digital port for IR Led 24float armazenavalor1; 25float armazenavalor2; 26IRrecv irrecv(RECV_PIN); 27decode_results results; 28 29const byte LINHAS = 4; // keypad lines 30const byte COLUNAS = 4; // keypad columns 31 32const char TECLAS_MATRIZ[LINHAS][COLUNAS] = { // keyboard mapping 33 {'1', '2', '3', 'A'}, 34 {'4', '5', '6', 'B'}, 35 {'7', '8', '9', 'C'}, 36 {'*', '0', '#', 'D'} 37}; 38 39const byte PINOS_LINHAS[LINHAS] = {9, 8, 7, 6}; // keypad lines 40const byte PINOS_COLUNAS[COLUNAS] = {5, 4, 3, 2}; // keypad columns 41Keypad teclado_personalizado = Keypad(makeKeymap(TECLAS_MATRIZ), PINOS_LINHAS, PINOS_COLUNAS, LINHAS, COLUNAS); // keypad on 42 43int Fora = 50; //Must calibrate to suit your needs. 44int Dentro = 150; //Must calibrate to suit your needs. 45 46void setup() { 47Serial.begin(9600); 48pinMode(12,INPUT);// ir module 49irrecv.enableIRIn(); // ir initialize 50Srv.attach(11); 51delay(250); 52Srv.write(Fora); //lever out waiting for pushing the coins. 53} 54 55void loop() { 56 57char leitura_teclas = teclado_personalizado.getKey(); 58 switch (leitura_teclas){ 59 60 case '1': //keypad 1 pressed and so on 61 pushPull1(); 62break; 63 64 case '2': 65 pushPull2(); 66 break; 67 68 case '3': 69 pushPull3(); 70 break; 71 72 case '4': 73 pushPull4(); 74break; 75 76 case '5': 77 pushPull5(); 78 break; 79 80 case '6': 81 pushPull6(); 82 83 break; 84 85 case '7': 86 pushPull7; 87 88break; 89 case '8': 90 pushPull8(); 91 break; 92 93 case '9': 94 pushPull9(); 95break; 96 97} //end switch 98 99/* Routines for IR control */ 100 101if (irrecv.decode(&results)) { 102 Serial.print("Valor lido : "); 103 Serial.println(results.value, HEX); 104 armazenavalor1 = (results.value); 105 irrecv.resume(); 106 armazenavalor2 = (results.value); 107delay(500); 108 109 110 if (armazenavalor1 == 0xFF30CF ){ //button "1" pressed 111 pushPull1(); 112} 113irrecv.resume(); 114 115if (armazenavalor1 == 0xFF18E7 ){ //button "2" pressed 116pushPull2(); 117} 118irrecv.resume(); //Le o prximo valor 119 120if (armazenavalor1 == 0xFF7A85 ){ //button "3" pressed 121pushPull3(); 122} 123 124irrecv.resume(); //Le o prximo valor 125 126if (armazenavalor1 == 0xFF10EF ){ //button "4" pressed 127pushPull4(); 128} 129 130irrecv.resume(); //Le o prximo valor 131 132if (armazenavalor1 == 0xFF38C7 ){ //button "5" pressed 133pushPull5(); 134} 135 136irrecv.resume(); //Le o prximo valor 137 138if (armazenavalor1 == 0xFF5AA5 ){ //button "6" pressed 139pushPull6(); 140} 141irrecv.resume(); //Le o prximo valor 142 143if (armazenavalor1 == 0xFF42BD ){ //button "7" pressed 144pushPull7(); 145} 146irrecv.resume(); //Le o prximo valor 147 148if (armazenavalor1 == 0xFF4AB5 ){ //button "8" pressed 149pushPull8(); 150} 151 152irrecv.resume(); //Le o prximo valor 153 154if (armazenavalor1 == 0xFF52AD ){ //button "9" pressed 155pushPull9(); 156} 157 158irrecv.resume(); //Le o prximo valor 159 160 }//end if decodresults 161} //end loop 162 163 164 void pushPull(){ 165Srv.write(Dentro); 166 delay(300); 167 Srv.write(Fora); 168 delay(300); 169 } 170 171 void pushPull1() { 172pushPull(); 173} 174 175 void pushPull2() { 176pushPull(); 177pushPull(); 178} 179 180 void pushPull3() { 181pushPull(); 182pushPull(); 183pushPull(); 184} 185 186 void pushPull4() { 187pushPull(); 188pushPull(); 189pushPull(); 190pushPull(); 191} 192 193 void pushPull5() { 194pushPull(); 195pushPull(); 196pushPull(); 197pushPull(); 198pushPull(); 199} 200 201 void pushPull6() { 202pushPull(); 203pushPull(); 204pushPull(); 205pushPull(); 206pushPull(); 207pushPull(); 208} 209 210 void pushPull7() { 211pushPull(); 212pushPull(); 213pushPull(); 214pushPull(); 215pushPull(); 216pushPull(); 217pushPull(); 218} 219 220 void pushPull8() { 221pushPull(); 222pushPull(); 223pushPull(); 224pushPull(); 225pushPull(); 226pushPull(); 227pushPull(); 228pushPull(); 229} 230 231 void pushPull9() { 232pushPull(); 233pushPull(); 234pushPull(); 235pushPull(); 236pushPull(); 237pushPull(); 238pushPull(); 239pushPull(); 240pushPull(); 241 } 242
Downloadable files
Scheme
Its showed with Arduino Uno but I did use a Nano board and the same pins
Scheme
Scheme
Its showed with Arduino Uno but I did use a Nano board and the same pins
Scheme
Comments
Only logged in users can leave comments
NerdFatherRJ
0 Followers
•0 Projects
Table of contents
Intro
0
0