• DTMF decoder for DIYer with arduino, control over several kilometers

QC

DTMF decoder for DIYer with arduino, control over several kilometers

In this tutorial we will see how to create a circuit to connect to our laptop, in this case a Baofeng UV-5R

Devices and components

Arduino Mini Pro-ATmega168 5V

Software and tools

rogerbit.

Project description

Source code

Source code

1#include <Arduino.h>
2#include <U8g2lib.h>
3#ifdef U8X8_HAVE_HW_SPI
4#include <SPI.h>
5#endif
6#ifdef U8X8_HAVE_HW_I2C
7#include <Wire.h>
8#endif
9U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); //Display SSD1306 de 128x32
10
11int codigo;
12const int Pin12 = 12;
13const int Pin11 = 11;
14const int Pin10 = 10;
15const int Pin9 = 9;
16const int Pin8 = 8;
17const int Pin7 = 7;
18const int Pin6 = 6;
19const int Pin5 = 5;
20const int Pin4 = 4;
21const int Pin3 = 3;
22const int Pin2 = 2;
23
24int EstadoPin2 = 0;
25int EstadoPin3 = 0;
26int EstadoPin4 = 0;
27int EstadoPin5 = 0;
28int EstadoPin6 = 0;
29
30void setup() {
31 Serial.begin(9600);//Velocidad del puerto serial
32 u8g2.begin();//Inicializamos el display
33 // Ponemos los pines 2 al 6 como entradas para el circuto integrado MT8870DE
34 pinMode(Pin2, INPUT);
35 pinMode(Pin3, INPUT);
36 pinMode(Pin4, INPUT);
37 pinMode(Pin5, INPUT);
38 pinMode(Pin6, INPUT);
39 //Salidas control de luces, motores, relay, triac, etc
40 pinMode(Pin7, OUTPUT);
41 pinMode(Pin8, OUTPUT);
42 pinMode(Pin9, OUTPUT);
43 pinMode(Pin10, OUTPUT);
44 pinMode(Pin11, OUTPUT);
45 pinMode(Pin12, OUTPUT);
46 //Inicializamos el display con la leyenda "Preparado"
47 codigo = 17;
48 displayOled();
49}
50
51void loop() {
52
53 // Leemos el estado de los pines 2 al 6
54 EstadoPin2 = digitalRead(Pin2);
55 EstadoPin3 = digitalRead(Pin3);
56 EstadoPin4 = digitalRead(Pin4);
57 EstadoPin5 = digitalRead(Pin5);
58 EstadoPin6 = digitalRead(Pin6);
59 delay(110);
60//Boton 1 10001
61 if (EstadoPin6 == HIGH && EstadoPin5 == LOW && EstadoPin4 == LOW && EstadoPin3 == LOW && EstadoPin2 == HIGH ) {
62
63 Serial.print("1");
64 while(EstadoPin6 == HIGH && EstadoPin5 == LOW && EstadoPin4 == LOW && EstadoPin3 == LOW && EstadoPin2 == HIGH){
65 EstadoPin2 = digitalRead(Pin2);
66 EstadoPin3 = digitalRead(Pin3);
67 EstadoPin4 = digitalRead(Pin4);
68 EstadoPin5 = digitalRead(Pin5);
69 EstadoPin6 = digitalRead(Pin6);
70 codigo = 1;
71 digitalWrite(Pin7, HIGH);
72 displayOled();
73 }
74 }
75 //Boton 2 01001
76 if (EstadoPin6 == LOW && EstadoPin5 == HIGH && EstadoPin4 == LOW && EstadoPin3 == LOW && EstadoPin2 == HIGH ) {
77
78 Serial.print("2");
79 while(EstadoPin6 == LOW && EstadoPin5 == HIGH && EstadoPin4 == LOW && EstadoPin3 == LOW && EstadoPin2 == HIGH ){
80 EstadoPin2 = digitalRead(Pin2);
81 EstadoPin3 = digitalRead(Pin3);
82 EstadoPin4 = digitalRead(Pin4);
83 EstadoPin5 = digitalRead(Pin5);
84 EstadoPin6 = digitalRead(Pin6);
85 digitalWrite(Pin7, LOW);
86 codigo = 2;
87 displayOled();
88 }
89 }
90 //Boton 3 11001
91 if (EstadoPin6 == HIGH && EstadoPin5 == HIGH && EstadoPin4 == LOW && EstadoPin3 == LOW && EstadoPin2 == HIGH ) {
92
93 Serial.print("3");
94 while(EstadoPin6 == HIGH && EstadoPin5 == HIGH && EstadoPin4 == LOW && EstadoPin3 == LOW && EstadoPin2 == HIGH ){
95 EstadoPin2 = digitalRead(Pin2);
96 EstadoPin3 = digitalRead(Pin3);
97 EstadoPin4 = digitalRead(Pin4);
98 EstadoPin5 = digitalRead(Pin5);
99 EstadoPin6 = digitalRead(Pin6);
100 digitalWrite(Pin8, HIGH);
101 codigo = 3;
102 displayOled();
103 }
104 }
105 //Boton 4 00101
106 if (EstadoPin6 == LOW && EstadoPin5 == LOW && EstadoPin4 == HIGH && EstadoPin3 == LOW && EstadoPin2 == HIGH ) {
107
108 Serial.print("4");
109 while(EstadoPin6 == LOW && EstadoPin5 == LOW && EstadoPin4 == HIGH && EstadoPin3 == LOW && EstadoPin2 == HIGH ){
110 EstadoPin2 = digitalRead(Pin2);
111 EstadoPin3 = digitalRead(Pin3);
112 EstadoPin4 = digitalRead(Pin4);
113 EstadoPin5 = digitalRead(Pin5);
114 EstadoPin6 = digitalRead(Pin6);
115 digitalWrite(Pin8, LOW);
116 codigo = 4;
117 displayOled();
118 }
119 }
120 //Boton 5 10101
121 if (EstadoPin6 == HIGH && EstadoPin5 == LOW && EstadoPin4 == HIGH && EstadoPin3 == LOW && EstadoPin2 == HIGH ) {
122
123 Serial.print("5");
124 while(EstadoPin6 == HIGH && EstadoPin5 == LOW && EstadoPin4 == HIGH && EstadoPin3 == LOW && EstadoPin2 == HIGH ){
125 EstadoPin2 = digitalRead(Pin2);
126 EstadoPin3 = digitalRead(Pin3);
127 EstadoPin4 = digitalRead(Pin4);
128 EstadoPin5 = digitalRead(Pin5);
129 EstadoPin6 = digitalRead(Pin6);
130 digitalWrite(Pin9, HIGH);
131 codigo = 5;
132 displayOled();
133 }
134 }
135 //Boton 6 01101
136 if (EstadoPin6 == LOW && EstadoPin5 == HIGH && EstadoPin4 == HIGH && EstadoPin3 == LOW && EstadoPin2 == HIGH ) {
137
138 Serial.print("6");
139 while(EstadoPin6 == LOW && EstadoPin5 == HIGH && EstadoPin4 == HIGH && EstadoPin3 == LOW && EstadoPin2 == HIGH ){
140 EstadoPin2 = digitalRead(Pin2);
141 EstadoPin3 = digitalRead(Pin3);
142 EstadoPin4 = digitalRead(Pin4);
143 EstadoPin5 = digitalRead(Pin5);
144 EstadoPin6 = digitalRead(Pin6);
145 digitalWrite(Pin9, LOW);
146 codigo = 6;
147 displayOled();
148 }
149 }
150 //Boton 7 11101
151 if (EstadoPin6 == HIGH && EstadoPin5 == HIGH && EstadoPin4 == HIGH && EstadoPin3 == LOW && EstadoPin2 == HIGH ) {
152
153 Serial.print("7");
154 while(EstadoPin6 == HIGH && EstadoPin5 == HIGH && EstadoPin4 == HIGH && EstadoPin3 == LOW && EstadoPin2 == HIGH ){
155 EstadoPin2 = digitalRead(Pin2);
156 EstadoPin3 = digitalRead(Pin3);
157 EstadoPin4 = digitalRead(Pin4);
158 EstadoPin5 = digitalRead(Pin5);
159 EstadoPin6 = digitalRead(Pin6);
160 digitalWrite(Pin10, HIGH);
161 codigo = 7;
162 displayOled();
163 }
164 }
165 //Boton 8 00011
166 if (EstadoPin6 == LOW && EstadoPin5 == LOW && EstadoPin4 == LOW && EstadoPin3 == HIGH && EstadoPin2 == HIGH ) {
167
168 Serial.print("8");
169 while(EstadoPin6 == LOW && EstadoPin5 == LOW && EstadoPin4 == LOW && EstadoPin3 == HIGH && EstadoPin2 == HIGH ){
170 EstadoPin2 = digitalRead(Pin2);
171 EstadoPin3 = digitalRead(Pin3);
172 EstadoPin4 = digitalRead(Pin4);
173 EstadoPin5 = digitalRead(Pin5);
174 EstadoPin6 = digitalRead(Pin6);
175 digitalWrite(Pin10, LOW);
176 codigo = 8;
177 displayOled();
178 }
179 }
180 //Boton 9 10011
181 if (EstadoPin6 == HIGH && EstadoPin5 == LOW && EstadoPin4 == LOW && EstadoPin3 == HIGH && EstadoPin2 == HIGH ) {
182
183 Serial.print("9");
184 while(EstadoPin6 == HIGH && EstadoPin5 == LOW && EstadoPin4 == LOW && EstadoPin3 == HIGH && EstadoPin2 == HIGH ){
185 EstadoPin2 = digitalRead(Pin2);
186 EstadoPin3 = digitalRead(Pin3);
187 EstadoPin4 = digitalRead(Pin4);
188 EstadoPin5 = digitalRead(Pin5);
189 EstadoPin6 = digitalRead(Pin6);
190 digitalWrite(Pin11, HIGH);
191 codigo = 9;
192 displayOled();
193 }
194 }
195 //Boton 0 01011
196 if (EstadoPin6 == LOW && EstadoPin5 == HIGH && EstadoPin4 == LOW && EstadoPin3 == HIGH && EstadoPin2 == HIGH ) {
197
198 Serial.print("0");
199 while(EstadoPin6 == LOW && EstadoPin5 == HIGH && EstadoPin4 == LOW && EstadoPin3 == HIGH && EstadoPin2 == HIGH ){
200 EstadoPin2 = digitalRead(Pin2);
201 EstadoPin3 = digitalRead(Pin3);
202 EstadoPin4 = digitalRead(Pin4);
203 EstadoPin5 = digitalRead(Pin5);
204 EstadoPin6 = digitalRead(Pin6);
205 digitalWrite(Pin11, LOW);
206 codigo = 0;
207 displayOled();
208 }
209 }
210 //Boton * 11011
211 if (EstadoPin6 == HIGH && EstadoPin5 == HIGH && EstadoPin4 == LOW && EstadoPin3 == HIGH && EstadoPin2 == HIGH ) {
212
213 Serial.print("*");
214 while(EstadoPin6 == HIGH && EstadoPin5 == HIGH && EstadoPin4 == LOW && EstadoPin3 == HIGH && EstadoPin2 == HIGH ){
215 EstadoPin2 = digitalRead(Pin2);
216 EstadoPin3 = digitalRead(Pin3);
217 EstadoPin4 = digitalRead(Pin4);
218 EstadoPin5 = digitalRead(Pin5);
219 EstadoPin6 = digitalRead(Pin6);
220 digitalWrite(Pin12, HIGH);
221 codigo = 11;
222 displayOled();
223 }
224 }
225 //Boton # 00111
226 if (EstadoPin6 == LOW && EstadoPin5 == LOW && EstadoPin4 == HIGH && EstadoPin3 == HIGH && EstadoPin2 == HIGH ) {
227
228 Serial.print("#");
229 while(EstadoPin6 == LOW && EstadoPin5 == LOW && EstadoPin4 == HIGH && EstadoPin3 == HIGH && EstadoPin2 == HIGH ){
230 EstadoPin2 = digitalRead(Pin2);
231 EstadoPin3 = digitalRead(Pin3);
232 EstadoPin4 = digitalRead(Pin4);
233 EstadoPin5 = digitalRead(Pin5);
234 EstadoPin6 = digitalRead(Pin6);
235 digitalWrite(Pin12, LOW);
236 codigo = 12;
237 displayOled();
238 }
239 }
240//Boton MENU 10111
241 if (EstadoPin6 == HIGH && EstadoPin5 == LOW && EstadoPin4 == HIGH && EstadoPin3 == HIGH && EstadoPin2 == HIGH ) {
242
243 Serial.print("MENU");
244 while(EstadoPin6 == HIGH && EstadoPin5 == LOW && EstadoPin4 == HIGH && EstadoPin3 == HIGH && EstadoPin2 == HIGH ){
245 EstadoPin2 = digitalRead(Pin2);
246 EstadoPin3 = digitalRead(Pin3);
247 EstadoPin4 = digitalRead(Pin4);
248 EstadoPin5 = digitalRead(Pin5);
249 EstadoPin6 = digitalRead(Pin6);
250 codigo = 13;
251 displayOled();
252 }
253 }
254 //Boton ALTO 01111
255 if (EstadoPin6 == LOW && EstadoPin5 == HIGH && EstadoPin4 == HIGH && EstadoPin3 == HIGH && EstadoPin2 == HIGH ) {
256
257 Serial.print("UP");
258 while(EstadoPin6 == LOW && EstadoPin5 == HIGH && EstadoPin4 == HIGH && EstadoPin3 == HIGH && EstadoPin2 == HIGH ){
259 EstadoPin2 = digitalRead(Pin2);
260 EstadoPin3 = digitalRead(Pin3);
261 EstadoPin4 = digitalRead(Pin4);
262 EstadoPin5 = digitalRead(Pin5);
263 EstadoPin6 = digitalRead(Pin6);
264 codigo = 14;
265 displayOled();
266 }
267 }
268 //Boton BAJO 11111
269 if (EstadoPin6 == HIGH && EstadoPin5 == HIGH && EstadoPin4 == HIGH && EstadoPin3 == HIGH && EstadoPin2 == HIGH ) {
270
271 Serial.print("DOWN");
272 while(EstadoPin6 == HIGH && EstadoPin5 == HIGH && EstadoPin4 == HIGH && EstadoPin3 == HIGH && EstadoPin2 == HIGH ){
273 EstadoPin2 = digitalRead(Pin2);
274 EstadoPin3 = digitalRead(Pin3);
275 EstadoPin4 = digitalRead(Pin4);
276 EstadoPin5 = digitalRead(Pin5);
277 EstadoPin6 = digitalRead(Pin6);
278 codigo = 15;
279 displayOled();
280 }
281 }
282 //Boton EXIT 00001
283 if (EstadoPin6 == LOW && EstadoPin5 == LOW && EstadoPin4 == LOW && EstadoPin3 == LOW && EstadoPin2 == HIGH ) {
284
285 Serial.print("EXIT");
286 while(EstadoPin6 == LOW && EstadoPin5 == LOW && EstadoPin4 == LOW && EstadoPin3 == LOW && EstadoPin2 == HIGH ){
287 EstadoPin2 = digitalRead(Pin2);
288 EstadoPin3 = digitalRead(Pin3);
289 EstadoPin4 = digitalRead(Pin4);
290 EstadoPin5 = digitalRead(Pin5);
291 EstadoPin6 = digitalRead(Pin6);
292 codigo = 16;
293 displayOled();
294 }
295 }
296}
297
298//Visualización el display
299 void displayOled(){
300 u8g2.firstPage();
301 do {
302 u8g2.setFont(u8g2_font_ncenB10_tr);
303 if(codigo == 1){
304 u8g2.drawStr(0,24,"Codigo: 1");
305 }
306 if(codigo == 2){
307 u8g2.drawStr(0,24,"Codigo: 2");
308 }
309 if(codigo == 3){
310 u8g2.drawStr(0,24,"Codigo: 3");
311 }
312 if(codigo == 4){
313 u8g2.drawStr(0,24,"Codigo: 4");
314 }
315 if(codigo == 5){
316 u8g2.drawStr(0,24,"Codigo: 5");
317 }
318 if(codigo == 6){
319 u8g2.drawStr(0,24,"Codigo: 6");
320 }
321 if(codigo == 7){
322 u8g2.drawStr(0,24,"Codigo: 7");
323 }
324 if(codigo == 8){
325 u8g2.drawStr(0,24,"Codigo: 8");
326 }
327 if(codigo == 9){
328 u8g2.drawStr(0,24,"Codigo: 9");
329 }
330 if(codigo == 0){
331 u8g2.drawStr(0,24,"Codigo: 0");
332 }
333 if(codigo == 11){
334 u8g2.drawStr(0,24,"Codigo: *");
335 }
336 if(codigo == 12){
337 u8g2.drawStr(0,24,"Codigo: #");
338 }
339 if(codigo == 13){
340 u8g2.drawStr(0,24,"Codigo: MENU");
341 }
342 if(codigo == 14){
343 u8g2.drawStr(0,24,"Codigo: UP");
344 }
345 if(codigo == 15){
346 u8g2.drawStr(0,24,"Codigo: DOWN");
347 }
348 if(codigo == 16){
349 u8g2.drawStr(0,24,"Codigo: EXIT");
350 }
351 if(codigo == 17){
352 u8g2.drawStr(0,24,"Preparado");
353
354 }
355 } while ( u8g2.nextPage() );
356 }




Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.

Easy remote control

Remotely control an LED with ease. Devices and components Arduino Nano 33 BLE with headers Box 525 Resistors precision 1% - 17 values Breadb...