Taula de continguts:

Un robot que indica si un venedor d’electrònica us enganya o no: 6 passos
Un robot que indica si un venedor d’electrònica us enganya o no: 6 passos

Vídeo: Un robot que indica si un venedor d’electrònica us enganya o no: 6 passos

Vídeo: Un robot que indica si un venedor d’electrònica us enganya o no: 6 passos
Vídeo: Дэниэл Суарес: Смертный приговор не должен выноситься роботами 2024, Juliol
Anonim
Un robot que indica si un venedor d’electrònica us enganya o no
Un robot que indica si un venedor d’electrònica us enganya o no

L’any passat, jo i el meu pare vam anar a una botiga d’electrònica i robòtica acabada d’obrir, molt a prop d’on vivim. Quan hi vaig entrar, estava ple d’electrònica, serovs, sensors, Raspberry pis i Arduinos. L’endemà, vam anar a la mateixa botiga i vam comprar molts senors i 3 Arduinos per valor d’uns 150 dòlars. Tan bon punt vaig tornar a casa, cap altre producte funcionava excepte l’Arduino Mega. Ens van estafar per uns 130 dòlars, la qual cosa és molt.

Per tant, vaig decidir crear un robot que pugui provar uns 12 sensors i 2 motors (que encara funcionen al servo) i determinar si el producte és defectuós.

Anem-hi directament!

Subministraments

1. Arduino UNO

2. Pantalla tàctil TFT de 2,4"

3. parell de cables de pont

4. sensors i motors perquè els pugueu provar (aquí he utilitzat: sensor de moviment, sensor de gas MQ6, sensor de so, potenciòmetre i sensor de nivell d’aigua)

Pas 1: Com funciona …

Image
Image

He programat un Arduino per crear una IU interactiva amb una pantalla TFT. Com sabem, la pantalla TFT només té un pin lliure, és a dir, el pin A5. (si utilitzeu l’ONU). Per tant, qualsevol sensor que utilitzi pins analògics per llegir dades és compatible amb aquesta configuració …

A la interfície d’usuari, podeu canviar el color de fons de l’escriptori i obrir l’aplicació desenvolupada per Arduino per provar els sensors.

En obrir l'aplicació, podeu veure 2 opcions, INPUT i OUTPUT. per tant, si feu clic a Entrada, es mostren 4 sensors (és compatible amb 12, però encara no he de programar-lo ja que tinc exàmens que s'apropen … sense temps:(. Qualsevol persona és lliure d'editar el codi …)

I també pot comprovar si el servomotor funciona si el connecteu a la ranura.

mira-ho:

Pas 2: penjar el codi

El codi és un programa de 600 línies que he codificat meticulosament en unes 50 hores. Té alguns errors, així que si us plau, modifiqueu-lo i envieu-lo al meu correu electrònic ([email protected]).

Pengeu el codi i connecteu l’escut TFT a l’Arduino. Et recomano jugar amb la interfície d’usuari per aconseguir-ne un millor repàs.

El codi:

#incloure

#include #include #include #define LCD_CS A3 #define LCD_CD A2 #define LCD_WR A1 #define LCD_RD A0 #define LCD_RESET A4 #define BLACK 0x0000 #define BLUE 0x001F #define NAVY 0x000F #define RED 0xF800 #define GREEN 0x070x07 #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define LIGHTGREY 0xC618 #define PURPLE 0x780F #define OLIVE 0x7BE0 #define Selection #define YP A1 #define XM A2 #define YM 7 #DFINE XP 6 #define 160 #define TS_MAXX 160 #define TS_MAXY 970 Pantalla tàctil ts = Pantalla tàctil (XP, YP, XM, YM, 300); Adafruit_TFTLCD tft (LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); #define BOXSIZE 40 #define PENRADIUS 3 #define MINPRESSURE 10 #define MAXPRESSURE 1000 so int; estat char = 6; int touch = 0; int color = NEGRE; int redir = 0; int ota; configuració nul·la () {Serial.begin (9600); tft.reset (); tft.setFont (& FreeMonoBoldOblique12pt7b); tft.begin (0x9325); tft.setRotation (45); tft.setTextSize (0,5); tft.fillScreen (BLANC); tft.setCursor (60, 160); tft.setTextColor (NEGRE); tft.print ("Llisca per iniciar la sessió"); } void loop () {sensor de flotació Voltatge; sensor de flotació Valor; TSPoint p = ts.getPoint (); pinMode (XM, OUTPUT); pinMode (YP, OUTPUT); if (pz> MINPRESSURE && pz 240 && px 130 && py 240 && px 20 && py 240 && px 20 && py 160 && px 12 && py 240 && px 20 && py 240 && px 20 && py 40 && px 15 && py 150 && px 40 && py 150 && px 80 && py 150 && px 120 && py 150 && px 170 && py 90 && px 40 && py 90 && px 80 && py 90 && px 120 && py 150 && px 170 && py 150 && px 170 && py 150 && px 170 && py 150 && px 170 && py 150 && px 170 && py 100 && px 20 && py 200 && px 100 && py 100 && px 20 && py 100 && px 20 && py 100 && px 20 && py <100) {tacte = 26; }} if (toqueu == 1 && state == 6) {tft.setRotation (0); tft.fillScreen (color); so = 0; tft.fillRect (200, 180, 80, 140, BLANC); tft.drawRect (201, 181, 81, 141, NEGRE); tft.fillRect (80, 30, 100, 100, CIAN); tft.drawRect (81, 31, 101, 101, NEGRE); tft.fillRect (10, 30, 50, 100, NAVY); tft.drawRect (11, 31, 51, 101, NEGRE); tft.fillRect (10, 180, 30, 120, PURPLE); tft.drawRect (11, 181, 31, 121, NEGRE); tft.fillRect (45, 180, 30, 120, BLAU); tft.drawRect (46, 181, 31, 121, NEGRE); tft.fillRect (80, 180, 30, 120, CIAN); tft.drawRect (81, 181, 31, 121, NEGRE); tft.fillRect (115, 180, 30, 120, VERD); tft.drawRect (116, 181, 31, 121, NEGRE); tft.fillRect (150, 180, 30, 120, GROC); tft.drawRect (151, 181, 31, 121, NEGRE); tft.fillTriangle (210, 30, 210, 50, 220, 40, BLANC); tft.fillRect (200, 35, 12, 12, BLANC); tft.drawTriangle (210, 30, 210, 50, 220, 40, NEGRE); tft.drawRect (200, 35, 12, 12, NEGRE); tft.drawCircle (210, 40, 14, BLANC); //tft.fillTriange(a1, b1, a2, b2, c1, c2, RED); tft.setRotation (45); tft.setCursor (200, 20); tft.print ("Configuració"); tft.fillRoundRect (45, 75, 75, 75, 4, BLANC); tft.drawRoundRect (45, 75, 75, 75, 4, NEGRE); tft.fillRect (75, 75, 15, 30, NEGRE); tft.fillRect (75, 120, 15, 30, NEGRE); tft.fillRect (90, 105, 30, 15, NEGRE); tft.fillRect (45, 105, 30, 15, NEGRE); estat = 7; tacte = 0; ota = 0; } if (toqueu == 2) {tft.fillScreen (BLANC); tft.setRotation (0); tft.fillTriangle (210, 30, 210, 50, 220, 40, BLANC); tft.fillRect (200, 35, 12, 12, BLANC); tft.drawTriangle (210, 30, 210, 50, 220, 40, NEGRE); tft.drawRect (200, 35, 12, 12, NEGRE); tft.drawCircle (210, 40, 14, NEGRE); tft.setRotation (45); tft.fillTriangle (270, 40, 270, 20, 260, 30, NEGRE); tft.drawLine (300, 30, 270, 30, NEGRE); tft.setCursor (20, 200); tft.print ("personalització"); tft.setCursor (20, 170); tft.print ("tancar sessió"); tft.setCursor (20, 140); tft.print ("perifèrics"); tft.setCursor (20, 110); tft.print ("Quant a"); tacte = 1; estat = 2; } if (toqueu == 10 && state == 2) {tft.fillScreen (BLANC); tft.setCursor (10, 160); tft.setTextColor (NEGRE); tft.print ("Creat i desenvolupat"); tft.setCursor (100, 190); tft.print ("per:"); tft.setCursor (60, 220); tft.print ("Un adolescent de l'Índia"); tft.setRotation (0); tft.fillTriangle (210, 30, 210, 50, 220, 40, BLANC); tft.fillRect (200, 35, 12, 12, BLANC); tft.drawTriangle (210, 30, 210, 50, 220, 40, NEGRE); tft.drawRect (200, 35, 12, 12, NEGRE); tft.drawCircle (210, 40, 14, NEGRE); tft.setRotation (45); tft.fillTriangle (270, 40, 270, 20, 260, 30, NEGRE); tft.drawLine (300, 30, 270, 30, NEGRE); estat = 6; } if (toqueu == 11 && state == 2) {tft.fillScreen (BLANC); tft.setCursor (60, 40); tft.print ("Tria un"); tft.setCursor (40, 60); tft.print ("color de fons"); tft.fillRect (60, 180, 45, 45, VERMELL); tft.fillRect (120, 180, 45, 45, GROC); tft.fillRect (180, 180, 45, 45, BLAU); tft.fillRect (240, 180, 45, 45, VERD); tft.fillRect (60, 130, 45, 45, MAGENTA); tft.fillRect (120, 130, 45, 45, NAVY); tft.fillRect (180, 130, 45, 45, CLAR); tft.fillRect (240, 130, 45, 45, CYAN); tft.fillRect (60, 80, 45, 45, BLANC); tft.drawRect (60, 80, 45, 45, NEGRE); tft.fillRect (120, 80, 45, 45, NEGRE); tft.fillRect (180, 80, 45, 45, OLIVE); tft.fillRect (240, 80, 45, 45, PURPLE); tft.setRotation (0); tft.fillTriangle (210, 30, 210, 50, 220, 40, BLANC); tft.fillRect (200, 35, 12, 12, BLANC); tft.drawTriangle (210, 30, 210, 50, 220, 40, NEGRE); tft.drawRect (200, 35, 12, 12, NEGRE); tft.drawCircle (210, 40, 14, NEGRE); tft.setRotation (45); tft.fillTriangle (270, 40, 270, 20, 260, 30, NEGRE); tft.drawLine (300, 30, 270, 30, NEGRE); estat = 6; if (redir == 1) {color = BLANC; } if (redir == 2) {color = NEGRE; } if (redir == 3) {color = OLIVE; } if (redir == 4) {color = PURP; } if (redir == 5) {color = MAGENTA; } if (redir == 6) {color = MARI; } if (redir == 7) {color = CLAR; } if (redir == 8) {color = CIAN; } if (redir == 9) {color = VERMELL; } if (redirigir == 10) {color = GROC; } if (redirigir == 11) {color = BLAU; } if (redir == 12) {color = VERD; }} if (toca == 26) {ota = 1; tft.fillScreen (BLANC); tft.setRotation (0); tft.fillTriangle (210, 30, 210, 50, 220, 40, BLANC); tft.fillRect (200, 35, 12, 12, BLANC); tft.drawTriangle (210, 30, 210, 50, 220, 40, NEGRE); tft.drawRect (200, 35, 12, 12, NEGRE); tft.drawCircle (210, 40, 14, NEGRE); tft.setRotation (45); tft.fillTriangle (270, 40, 270, 20, 260, 30, NEGRE); tft.drawLine (300, 30, 270, 30, NEGRE); tft.setRotation (1); tft.setCursor (30, 80); tft.print ("Entrada"); tft.setCursor (30, 150); tft.print ("Sortida"); tft.drawRect (25, 130, 90, 30, NEGRE); tft.drawRect (25, 60, 90, 30, NEGRE); if (p.x> 190 && p.x 30 && p.y <90) {tft.setCursor (150, 220); tft.print ("Nivell d'aigua"); tft.setCursor (150, 170); tft.print ("Nivell de gas"); tft.setCursor (150, 120); tft.print ("Distància"); tft.setCursor (150, 70); tft.print ("So"); tacte = 1; estat = 2; }}} while (so == 1) {tft.fillScreen (BLANC); sensorValue = analogRead (A5); sensorVoltage = sensorValue; tft.setCursor (60, 160); tft.print (sensorVoltage); Serial.println ("Nivell de so ="); Serial.println (sensorVoltage); retard (1000); if (so == 0) {interrupció; }}}}

Pas 3: Biblioteques obligatòries:

  • Adafruit_GFX.h
  • Adafruit_TFTLCD.h
  • Pantalla tàctil.h

Enllaços de Github per al mateix:

github.com/adafruit/Adafruit-GFX-Library

github.com/adafruit/TFTLCD-Library

github.com/adafruit/Adafruit_TouchScreen

Pas 4: les connexions

Bofetar-ho tot junt
Bofetar-ho tot junt

Necessiteu 6 cables de pont. 3 mascles i 3 femelles. soldeu-los directament a la placa Arduino així:

Pas 5: colpeja-ho tot

Introduïu els cables a l’arduino (consulteu la imatge), utilitzeu una pistola de cola si cal …

A continuació, poseu l’escut TFT i, a continuació, proveu els vostres sensors.

Gràcies per desplaçar-vos fins a baix. Assegureu-vos de votar-me si creieu que aquest projecte és únic i útil

Tens ganes de fer estafadors electrònics i tingues cura?

Pas 6: Millores addicionals:

  • Més compatibilitat del sensor
  • S'havia d'acabar el codi del motor servo
  • Una altra aplicació que es pot interactuar amb mòduls Bluetooth perquè puguem controlar un robot alimentat per Bluetooth amb ella.
  • Reparació d'errors

Recomanat: