Embedded device¶
Hardware overview¶
First look at the RFID sensor and the Wemoz
Wiring diagram¶
Disclaimer: I use my laptop to power my WeMos D1 Mini Pro
This is the first version of the wiring diagram.
First version of the wiring diagram
After useing Google to find the right sensor I made the second version of the wiring diagram
Second version of the wiring diagram
I added an LCD sensor with a backpack, I did solder the backpack on the LCD.
Third version of the wiring diagram
I added an LCD and changed around the wiring.
Fourth version of the wiring diagram
Added the LDR sensor.
Fifth version of the wiring diagram
Bill of Materials¶
This is a list of all the materials that I used to complete the blueprint.
Part number/SKU | Manifacturer | Name | Description | Quanitity | Cost | Link |
---|---|---|---|---|---|---|
WPI405 | Velleman | RFID Sensor | This module allows to both read and write RFID cards. | 1 | €12,90 | https://whadda.com/product/arduino-compatible-rfid-read-and-write-module-wpi405/ |
HE0369-925 | Wemos | WeMos D1 Mini (pro) | Wemos D1 mini V3 is a mini WiFi microcontroller board based on the ESP-8266 | 1 | €10,95 | https://www.hobbyelectronica.nl/product/wemos-d1-mini-pro/ |
000071 | Tinytronics | Breadboard 830 points | An electronics breadboard is great for making temporary circuits and prototyping. | 1 | €4,00 | tinytronics.nl/shop/nl/gereedschap-en-montage/prototyping-toebehoren/breadboards/breadboard-830-points |
000058 | Tinytronics | LCD Display 16*2 | Screen display | 1 | €4,00 | https://www.tinytronics.nl/shop/nl/displays/lcd/lcd-display-16*2-karakters-met-witte-tekst-en-blauwe-backlight |
161 | Adafruit | Photoresistor | CdS cells are little light sensors | 1 | $0.95 | https://www.adafruit.com/product/161#description |
EFR-W0P25-A:MF | EDGELEC | Resistor | Regulates volt | 1 | $0.50 | https://www.amazon.com/EDGELEC-Resistor-Tolerance-Resistance-Optional/dp/B07HDGX5LM/ref=sr_1_4?keywords=10k%2Bohm%2Bresistor&qid=1663666242&sr=8-4&th=1 |
000164 | Tinytronics | Jumper wires Male-Male | The DuPont wires are very handy for prototyping, for example, in combination with a breadboard. The different colors make it possible to distinguish the different signals from each other. | 20 | €0.75 | https://www.tinytronics.nl/shop/en/cables-and-connectors/cables-and-adapters/prototyping-wires/dupont-compatible-and-jumper/dupont-jumper-wire-male-male-20cm-10-wires |
000066 | Arduino | Arduino Uno R3 | This Uno R3 is based on the open source design of Arduino, making it both hardware and software compatible with the Arduino ecosystem | 1 | €12.50 | https://www.tinytronics.nl/shop/en/development-boards/microcontroller-boards/arduino-compatible/uno-r3-with-usb-cable |
003127 | Goobay | Goobay USB-C USB-C | This USB-C USB-C cable makes it possible to connect, synchronize and transfer data with USB-C devices at high speed. | 1 | €7.00 | https://www.tinytronics.nl/shop/en/cables-and-connectors/cables-and-adapters/usb/usb-c/goobay-67976-usb-c-usb-c-3.1-cable-1m-3a-black |
HE0153-001 | Hobby Electronica | I2C Backpack | With this interface you can control LCD display through the SDA/SCL interface. | 1 | €1,95 | https://www.hobbyelectronica.nl/product/i2c-lcd-interface-voor-16x2-en-20x4-displays/?gclid=EAIaIQobChMI26Wtoouj-gIVK49oCR12hgcJEAQYASABEgKZsPD_BwE |
R4,C1 | R4,C2 |
Arduino code¶
First version of the code
// Libraries
//#include <ESP8266WiFi.h>
//#include <ESP8266HTTPClient.h>
//#include <WiFiClient.h>
#include <MFRC522.h>
#include <ArduinoJson.h>
// define
#define RST_PIN D1 // RST-PIN for RC522 - RFID - SPI - Modul GPIO15
#define SS_PIN D8 // SDA-PIN for RC522 - RFID - SPI - Modul GPIO2
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications
// WiFi.begin("iotroam", "td7xzadjkk"); //SSID and password
Serial.print('starting setup');
// Keep in while-loop while the device is not connected to your accesspoint.
// while (WiFi.status() != WL_CONNECTED) {
// delay(1000); // Waiting on connection...
// }
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
}
// Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
String get_byte_array (byte *buffer, byte bufferSize) {
String UID = "";
for (byte i = 0; i < bufferSize; i++) {
buffer[i] < 0x10 ? " 0" : " ";
char myHex[10] = "";
ltoa(buffer[i],myHex,16); //convert to c string base 16
UID += String(myHex);
UID+=" ";
}
UID.toUpperCase();
return UID;
}
void loop() {
//wifi
// WiFiClient client;
// HTTPClient httpClient;
//
// String serverPath = "http://43e4e4e4279616.lhr.life/insert.php?cardUID=" + get_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
// httpClient.begin(client, serverPath);
// int httpCode = httpClient.GET();
//
// Serial.print('starting wifi');
//
// if(httpCode == HTTP_CODE_OK) { // HTTP_CODE_OK == 200
// String payload = httpClient.getString();
// Serial.println(payload);
// } else {
// Serial.println("Unable to connect :(");
// }
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
delay(50);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:"));
Serial.println(get_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size));
Serial.println();
delay(1000);
}
For the other two sensors, this is the code I used.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, world!");
Serial.begin(115200);
Serial.println("test");
}
void loop()
{
// Do nothing here...
}
This is the code for de LDR that I am using.
#define LDRpin A0 // pin where we connected the LDR and the resistor
int LDRValue = 0; // result of reading the analog pin
void setup() {
Serial.begin(9600); // sets serial port for communication
}
void loop() {
LDRValue = analogRead(LDRpin); // read the value from the LDR
Serial.println(LDRValue); // print the value to the serial port
delay(1500); // wait a little, this was originally 100, but I put it to 1500 so my serial monitor would not be overloaded with small data.
}
Current Arduino code¶
//Wifi manager
//#include <WiFiManager.h>
// Wifi
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//RFID scanner
#include <MFRC522.h>
#include <ArduinoJson.h>
//LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// define
#define RST_PIN D0 // RST-PIN for RC522 - RFID - SPI - Modul GPIO15
#define SS_PIN D8 // SDA-PIN for RC522 - RFID - SPI - Modul GPIO2
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(115200); // Initialize serial communications
//WiFi.begin("iotroam", "cwfwl1qb6t"); //SSID and password
WiFi.begin("meterkastwlan", "288Ea72870"); //SSID and password
Serial.print("starting setup");
// Keep in while-loop while the device is not connected to your accesspoint.
while (WiFi.status() != WL_CONNECTED) {
Serial.println("Waiting for connection status=" + String(WiFi.status()));
delay(1000); // Waiting on connection...
}
Serial.println("Connected! status=" + String(WiFi.status()));
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Hello, world!");
}
// Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
String get_byte_array (byte *buffer, byte bufferSize) {
String UID = "";
for (byte i = 0; i < bufferSize; i++) {
buffer[i] < 0x10 ? " 0" : " ";
char myHex[10] = "";
ltoa(buffer[i],myHex,16); //convert to c string base 16
UID += String(myHex);
UID+=" ";
}
UID.toUpperCase();
return UID;
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
delay(50);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
// Show some details of the PICC (that is: the tag/card)
Serial.print("Card UID:");
Serial.println(get_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size));
Serial.println();
delay(1000);
//wifi
WiFiClient client;
HTTPClient httpClient;
/*String serverPath = "http://ip/insert.php?cardUID=" + get_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
httpClient.begin(client, serverPath);
int httpCode = httpClient.GET();
Serial.print(serverPath);
//Serial.print("starting wifi");
if(httpCode == HTTP_CODE_OK) { // HTTP_CODE_OK == 200
String payload = httpClient.getString();
Serial.println(payload);
} else {
Serial.println("Unable to connect :(");
}*/
String url = String("http://ip/insert.php?cardUID=") + get_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println(url);
if (httpClient.begin(client, url)) {
//start connection and send HTTP header
int httpCode = httpClient.GET();
if(httpCode == HTTP_CODE_OK) { // HTTP_CODE_OK == 200
String payload = httpClient.getString();
Serial.println(payload);
} else {
Serial.println("Unable to connect :(");
}
delay(500);
}
}
Errors¶
Java error¶
During the process of tying all my code together I got this error/issue :
I asked 2 teachers for help, but they could not figure out what was wrong. Google didn’t help. Restarting laptop didn’t work. Nothing worked. This prevents me from working on my code any further.
Things I tried to fix it: - Restarting laptop - Restaring arduino - One by one turning off code to see if the error was still there
After those things did not work for me a classmate connected my WeMos to their laptop and tested a simple script.
void setup() {
Serial.begin(9600);
Serial.print("starting setup");
}
void loop() {
Serial.print("this is loop");
delay(1000);
}
That worked on their laptop and we did not get the error with java. Then I re-connected the WeMos to my laptop and ran the same script. After that I did not get the error anymore. We also ran all my code on their laptop through my WeMos and that did also not give an error.
Wifi¶
I also had a problem with connecting my wifi to the school’s hot spot. I highly recommend using your own wifi at home or using your phone as a hot spot. It is not that secure, but for a small project like this it is fine for me.
Links¶
- https://www.instructables.com/WiFi-RFID-Reader/
- https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
- https://microdigisoft.com/how-to-use-i2c-lcd-with-esp8266-wemos-d1-mini/
- https://www.tweaking4all.com/hardware/arduino/arduino-light-sensitive-resistor/